Saturday, June 21, 2014

Re: unit test: AssertionError: 302 != 200

Thanks, Marco!
It solved the question.

Kim


On 2014年6月21日 at 17:05:45, marcowahlsoft@gmail.com (marcowahlsoft@gmail.com) wrote:

Kim <kimitaka01@gmail.com> writes:

> I'm new to Django and am running a test.
>
> For my admintest in tests.py, I have the following:
> --------------
> class AdminTest(LiveServerTestCase):
> def test_login(self):
> c = Client()
>
> response = c.get('/admin/')
> self.assertEquals(response.status_code,200)
> self.assertTrue('Log in' in response.content)
> c.login(username = 'username',password='password')
> response = c.get('/admin/')
> self.assertEquals(response.status_code,200)
> self.assertTrue('Log out' in response.content)
>
> -------------
> And I get this error.
>
> -------------
> $ python manage.py test
> Creating test database for alias 'default'...
> .F
> ======================================================================
> FAIL: test_login (blogengine.tests.AdminTest)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
> File "/Users/Desktop/Python/1.7/src/blogengine/tests.py", line 35, in
> test_login
> self.assertEquals(response.status_code,200)
> AssertionError: 302 != 200
>
> ----------------------------------------------------------------------
> Ran 2 tests in 0.510s
>
> FAILED (failures=1)
> Destroying test database for alias 'default'...
> -------------
>
> Since I checked the admin is actually working(status 200) in my
> localhost, I thought I should give 200 status instead of 302.
>
> Please give me some advice to fix this.

Hi,

possibly just your expectation about the response status code is too
much focused on 200.

See e.g. https://en.wikipedia.org/wiki/HTTP_302


HTH, Marco
--
Marco Wahl -- Freelancer


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/84vbrud7up.fsf%40tm6592.fritz.box.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment