Thursday, October 23, 2014

Re: unit test: AssertionError: 302 != 200

Hi Kim,

I was going through Django 1.7 and noticed that you have to force the redirect on this line

response = c.get('/admin/' follow=True)

Regards
Kenneth Kinyanjui



On Saturday, 21 June 2014 05:47:24 UTC+3, Kim wrote:
Hi everyone, 
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.

Many thanks,
Kim

--
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/43ec1d38-f258-42bd-ac8a-2e55fa74cbb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment