I am still a newbie with Django but I am well on my way to completing
my first Django application, but not yet as I am having some trouble
testing and any help would be greatly recieved.

I am having trouble testing some POST data.  What I am trying to do in
my view is post some dynamic data and then save that to the database.
It all works fine in practice but then I test it I get an error
saying, "OperationalError: no such column: selectedcheck6".  I'm not
sure why this is or what it means.

I have added my test function below, I think what I have done is right
but obviously not as I'm getting that error.  My view is also below as
well to provide clarity.

test function
"""
class selectedTests(TestCase):
        fixtures = ['testdata/my_text_fixture.json']

        def setUp(self):
                self.client = Client()

        def test_add_check_to_testtrial1(self):
                #adding check_id=6 to this trial
                i=6
                post_data = {'selectedcheck%s' %i : 'selectedcheck%s' %i}
                response = self.client.post('/lib/project/7/', post_data)

                #checking that check has been added to the trial
                self.assertEqual(response.status_code, 200)
                self.assertEqual(response.template[0].name, 'selected.html')
                self.failUnless('You do not currently have any checks selected 
for
this study.' not in response.content)
"""

View
"""
def selected(request, project_id):
..........

        if request.method == 'POST':
                selected1 = Project.objects.get(id=project_id)

                ids = ''
                for i in range (1,100):
                        data = request.POST.get('selectedcheck%s' %i, '')
                        ids += '%s,' % (data)

                list2 = Checks.objects.extra(where=['id IN (%s)' % ids])
                for i in list2:
                        range2 = request.POST.get('range%s' %i.id, 'None')
                        comments = request.POST.get('comment%s' %i.id, 'None')
                        if range2 == 'None':
                                range2 = ''
                        if comments == 'None':
                                comments = ''
                        list3 = Checks.objects.get(id=i.id)
                        new = StudyChecksFinal(projectid=selected1, 
checkid=list3,
checkrange='%s' % range2, comments='%s' % comments)
                        new.save()

#matches projectid to project.id and filters checks for that project
        qset = (Q(projectid = project_id))
        results = StudyChecksFinal.objects.filter(qset)
        return render_to_response('selected.html', {
                'results': results,
                'currentproject': currentproject,
                'theuser' : theuser,
        })
"""

Many thanks in advance
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to