'c' is written here by mistake, I was trying different things by and commented out the wrong statement while pasting. It was,
r = self.client.post('/createauction/', post_data) Also, could the problem be with my Python version 2.6.5 and Django 1.1.1 as stated in this thread: http://groups.google.com/group/django-users/browse_thread/thread/617457f5d62366ae/e5d1436ac93aeb61?lnk=gst&q=baffled# I have also tried after updating my django-trunk but the problem persisits. Should I downgrade to Python 2.6.4 to fix this? Irum On May 28, 12:13 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On May 28, 9:23 am, irum <irumrauf...@gmail.com> wrote: > > <snip> > > > > > > > import unittest > > from django.test.client import Client > > from django.test import Client, TestCase > > from django.contrib.auth import authenticate > > from django.contrib.auth.models import * > > from django.core import mail > > import datetime > > import time > > > class SimpleTest(TestCase): > > fixtures = ['f1.json'] > > > def setUp(self): # Every test needs a client > > self.client = Client() > > > def test_create(self): > > > response = self.client.get('/createauction/') > > # Check that it takes to login page if not logged n > > self.failUnlessEqual(response.status_code, 302) > > self.assertRedirects(response, '/login/?next=/createauction/') > > > # i have created a user here again as some threads suggested that I > > should make a user here. > > user = User.objects.create_user(username = 'myadmin2', email > > ='du...@dummy.com', password = 'testing2') > > uid = user.id > > user.is_staff = True > > user.save() > > > print "trying to login..." > > > login = self.client.login(username='myadmin2', > > password='testing2') > > self.failUnless(login, True) > > self.assertEqual( login, True) # this test does not fail, > > means user has logged in succefully and login is True > > > enddate = datetime.datetime(2010, 06, 04, 3, 45, 50) > > > post_data = { > > 'title' : 'Title1', > > 'desc' : 'description', > > 'start-date' : datetime.datetime.now() , > > 'end_date' : enddate, > > 'owner' : user.id, > > 'price' : 60, > > 'highbid' : 60, > > 'banned' : False, > > 'closed' : True, > > > } > > > r = c.post('/createauction/', post_data) > > self.failUnlessEqual(r.status_code, 200) # this test fails, as > > status_code returned is 302 > > > These tests are run successully, meaning the user is redirected to > > login page, implying that client never enters the else branch for > > authenticated user in the 'cauction' view. > > self.failUnlessEqual(r.status_code, 302) > > self.assertRedirects(response, '/login/?next=/createauction/') > > > I have put in more than a day in this problem, trying to figure out > > where I am going wrong. I have tried to explain clearly here. Any one > > has any idea? > > > Thanks, > > irum > > What is `c` in the second-last line of the test? Are you perhaps > instantiating a separate test client somewhere? Show the actual code > you're running. > > Also note you don't need to define self.client in setUp(), as TestCase > does that > already:http://docs.djangoproject.com/en/1.2/topics/testing/#default-test-client > -- > DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.