I am testing my view using the Client(), and I am having trouble retrieving a variable that is in a try and except block. It is not returning the posted item in the block, but instead always returning the excepted data.
Here is the snippet I am trying to test in my view.py: """ allchecks = Checks.objects.all() datagroups = [] for i in allchecks: i.datagroup if not i.datagroup in datagroups: datagroups += ['%s' % i.datagroup] try: data = request.POST['datagroup'] except: data="" if data: checkslist = Checks.objects.filter(datagroup=data) else: checkslist = [] """ In my rendered template I have a filter input box which contains everything stored in datagroups. What I doing here is posting the selected filter in datagroups to display the results from my Checks table. This all works fine in practice but when I am testing it using Django's Client(), it never returns data as the posted datagroup but rather returns the excepted data="". This is what I have in my test.py: """ class checksearchTests(TestCase): fixtures = ['testdata/my_text_fixture.json'] def setUp(self): self.client = Client() #login user to perform following tests self.client.login(username='auser', password='apassword') response = self.client.get('/lib/project/7/checksearch/') self.assertEqual(response.status_code, 200) self.assertEqual(response.template[0].name, 'allsearch.html') self.failUnless('testtrial1' in response.content) def test_post_datagroup_search_ALC(self): dg='ALC' post_data = {'data': dg} postresponse = self.client.post('/lib/project/7/checksearch/', post_data) response = self.client.get('/lib/project/7/checksearch/') self.assertEqual(response.status_code, 200) self.assertEqual(response.template[0].name, 'allsearch.html') self.failUnless('Results for datagroup: ALC' in response.content) """ Its failing on "self.failUnless('Results for datagroup: ALC' in response.content)" because the posted data has not been rendered, so instead its rendering dg="". Anyidea why this is? Is it the way I have written my function? Any help is received with thanks. Tony. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---