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
My url is -> (r'^industries/add/$', add_industry),
and view function is:
def add_industry(request):
if request.user.is_superuser:
if request.method == 'POST':
industryform = IndustryForm(request.POST)
if industryform.is_valid():
industry = Industry()
industry.name = industryform.clean_data['name']
industry.save()
request.user.message_set.create(message = "New
Industry added successfully")
else:
industry_list = Industry.objects.all()
return render_to_response('industries.html', locals())
return HttpResponseRedirect('../')
else:
return HttpResponseRedirect('../')
else:
return HttpResponseRedirect('../')
I am able to create industry using python manager shell
but after running the test I am getting error.
Can some one tell me what I am doing wrong or some links for writing
test for views functions.
Thanks.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---