On Thu, 2008-06-26 at 00:02 -0700, laspal wrote:
> hi,
> I am writting unit test for the views.
>
> class IndustryTest(unittest.TestCase):
>
> def setUp( self):
> self.client = Client()
> self.client.post('/ibm/login/', {' usrename' :'admin',
> 'password' : 'abcd'})
>
>
> def test_addIndustry( self):
> url = '/ibm/crm/industries/add/'
> response = self.client.post(url,{ 'name': 'some'})
> self.failUnlessEqual( response.status_code, 200)
> # check if Industry was created
>
> industry = Industry.objects.get( name = 'some')
> self.failUnlessEqual( industry.name, 'some')
>
> def tearDown( self):
> self.client.post('/ibm/logout/')
>
> After running the test I am getting error.
> self.failUnlessEqual( response.status_code, 200)
> AssertionError: 302 != 200
Status code 302 is an HTTP redirect, which is what you would expect to
see, since your view is always returning a HttpResponseRedirect. The
test framework doesn't follow redirects. Bear in mind that status codes
in the 300 - 399 range aren't bad. So everything is working correctly
and it's just your expectation that's a little off here (i.e. the test
is wrong, not the code).
Ironically, I have a feeling that in the past I came down slightly
against an option to automatically follow redirects in the test
framework and yet my own code has a little function I'm always using to
do exactly that. I think there's a lesson about learning from experience
in there somewhere. :-)
Regards,
Malcolm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---