I have problems understanding how unit tests should be designed for django.
In my opinion, testing the whole look in one go seems impossible. We need to distinguish between preliminary and post-request states. But I have no idea how to do this. Is there a real life example?
When looking at the documentation, the examples are too simplistic and focused only on the model.
@login_required def call_view(request, contact_id): profile = request.user.get_profile() if request.POST: form = CallsForm(profile.company, request.POST) if form.is_valid() return HttpResponseRedirect('/contact/' + contact_id + '/calls/') else: form = CallsForm(profile.company, instance=call) variables = RequestContext(request, {'form':form} return render_to_response('conversation.html', variables)
update:
trying to do a successful test job, but still failing:
def test_contact_view_success(self): # same again, but with valid data, then self.client.login(username='username1', password='password1') response = self.client.post('/contact/add/', {u'last_name': [u'Johnson'], }) self.assertRedirects(response, '/')
error message:
AssertionError: Response didn't redirect as expected: Response code was 200 (expected 302)
I think this is because form.is_valid () fails and does not redirect, fix it?
django unit-testing
Houman Aug 09 2018-12-12T00: 00Z
source share