mercredi 31 décembre 2014

Django testing ajax endpoint in view

I'm using django-ajax in a django application, and want to do more thorough unit testing of the view that uses it.


My template for a particular view contains the following:



{% block head_js %}
<script type="text/javascript">
$(function() {
$('#progressbar').progressbar({
value: false
});

var checkStatus = function() {
$.ajax({
type: "POST",
url: '/ajax/MyApp/check_provisioning.json',
dataType: 'json',
success: function(data) {
if (data.data.complete != true) {
setTimeout(checkStatus, 3000);
} else {
// We've finished provisioning, time to move along.
window.location.replace('/MyApp/next');
}
}
});
};

checkStatus();
});
</script>
{% endblock %}


In MyApp/endpoints.py I have the function (simplified):



def check_provisioning(request):

# Do some stuff

return {'complete': some_boolean}


Now... As far as I can tell, the view functions just fine, in actual usage. But when making unit tests, django's test client retrieves the rendered response, but doesn't run anything embedded therein.


Does anyone know a way I can unit test that the view and/or the endpoint function are actually doing what they're supposed to? I would rather not fall back on using the django test framework to set up for a selenium test for the one view in the whole project that uses django-ajax this way.


Aucun commentaire:

Enregistrer un commentaire