Hi,
I'm running a test that fails when using Django's TestCase class, but
not when running TestCase from unittest. This is my test class:
class LoggedInUser(TestCase):
fixtures = ['myflow']
def setUp(self):
self.client = Client()
try:
User.objects.create_user('user', 'm...@nowhere.com', 'user')
except IntegrityError:
pass
self.client.login(username='user', password='user')
def test_experiment_view(self):
response = self.client.get('/myflow/experiment/1')
print response.context
self.failUnlessEqual(response.status_code, 200)
It fails with:
AssertionError: 302 != 200
when using Django's TestCase class, but everything is fine when using
unittest.
Also, when it fails everything in response seems fine except
for response.context (and response.content, of course).
response.context gets lots of variables, like MEDIA_URL, LANGUAGES and
others. I have no idea where that is coming from.
This is the relevant line from urls.py:
(r'^experiment/(?P<experiment_id>\d+)$',
'bioinformatics.myflow.views.view_experiment'),
Hi Karen,
You're right, I had some unnecessary lines that I used only for unittest. I commented them out now. Printing response['location'] gives me this:
http://testserver/myflow/experiment/1/
You're also right that there is no Redirect in my view, so I don't know where that is coming from. I guess I'll have to figure it out, because it seems to be the key to the problem.
It's time to use the scientific method. Make the smallest self-contained
example possible that exhibits the problem. A single test case in a file
that uses Django.TestCase. A single view that does nothing but returns a
constant string. A single URL pattern, etc. Remove everything that you
possibly can. If you find you cannot remove a particular chunk of
functionality (a URL pattern or a view or a template or whatever), then
you know where to look for the problem.
You have a lot of things in flight here all at once. Throw as many
overboard as you and eliminate the moving parts. What's left is the
problem you're trying to solve.
Regards,
Malcolm