def test_delete_ballot(self): proj = Project(name='test',order=0, doc_type='STD', \ description='test_delete_ballot', task_group='TGx', \ par_date=datetime.datetime.now()) proj.save() bal = Ballot(number=123,project=proj, draft='1.0', \ opened=datetime.datetime.now(), pool=100, \ ballot_type=Ballot.WGInitial.code) bal.closed = bal.opened + datetime.timedelta(days=15) bal.save() self.failUnlessEqual(bal.pk, 123) self.failUnlessEqual(Ballot.objects.count(), 1) url = reverse('ballot.views.main_page', args=[]) response = self._check_page(url) self.failUnlessEqual(Ballot.objects.count(), 1) self.wait_for_backlog_completion(DenormalizedBallot, 10) run_test_task_queue(self.client) self.failUnlessEqual(Ballot.objects.count(), 1) dn = DenormalizedBallot.objects.get(pk=bal.pk) self.failIfEqual(dn, None) self.failUnlessEqual(Ballot.objects.count(), 1) Ballot.objects.filter(pk=bal.number).delete() run_test_task_queue(self.client) self.failUnlessRaises(DenormalizedBallot.DoesNotExist, DenormalizedBallot.objects.get, pk=123) bal = Ballot(number=124,project=proj, draft='2.0', opened=datetime.datetime.now(), \ pool=100, ballot_type=Ballot.WGInitial.code) bal.closed = bal.opened + datetime.timedelta(days=15) bal.save() run_test_task_queue(self.client) url = reverse('ballot.views.edit_ballot', args=[bal.number]) response = self._check_page(url) data = response.context['form'].initial for key in data.keys(): if data[key] is None: data[key] = '' data['curpk'] = bal.pk data['delete'] = 'Delete' form = BallotForm(data, instance=bal) valid = form.is_valid() self.failUnless(valid) response = self.client.post(url, data) self.failIf(response.status_code != 302 and response.status_code != 303) url = reverse('del_ballot', args=[bal.number]) response.get('Location').index(url) response = self._check_page(url) match = re.search(r'input\s+type="submit"\s+name="confirm"', str(response), re.IGNORECASE) self.assertTrue(match) data = {"confirm": "Yes, I'm sure"} response = self.client.post(url, data) self.failIf(response.status_code != 302 and response.status_code != 303) self.failUnlessRaises(Ballot.DoesNotExist, Ballot.objects.get, pk=124) run_test_task_queue(self.client) self.failUnlessRaises(DenormalizedBallot.DoesNotExist, DenormalizedBallot.objects.get, pk=124)
def test_delete_ballot(self): proj = Project(name='test',order=0, doc_type='STD', \ description='test_delete_ballot', task_group='TGx', \ par_date=datetime.datetime.now()) proj.save() bal = Ballot(number=123,project=proj, draft='1.0', \ opened=datetime.datetime.now(), pool=100, \ ballot_type=Ballot.WGInitial.code) bal.closed = bal.opened + datetime.timedelta(days=15) bal.save() self.failUnlessEqual(bal.pk,123) self.failUnlessEqual(Ballot.objects.count(),1) url = reverse('ballot.views.main_page',args=[]) response = self._check_page(url) self.failUnlessEqual(Ballot.objects.count(),1) self.wait_for_backlog_completion(DenormalizedBallot, 10) run_test_task_queue(self.client) self.failUnlessEqual(Ballot.objects.count(),1) dn = DenormalizedBallot.objects.get(pk=bal.pk) self.failIfEqual(dn,None) self.failUnlessEqual(Ballot.objects.count(),1) Ballot.objects.filter(pk=bal.number).delete() run_test_task_queue(self.client) self.failUnlessRaises(DenormalizedBallot.DoesNotExist, DenormalizedBallot.objects.get, pk=123) bal = Ballot(number=124,project=proj, draft='2.0', opened=datetime.datetime.now(), \ pool=100, ballot_type=Ballot.WGInitial.code) bal.closed = bal.opened + datetime.timedelta(days=15) bal.save() run_test_task_queue(self.client) url = reverse('ballot.views.edit_ballot',args=[bal.number]) response = self._check_page(url) data = response.context['form'].initial for key in data.keys(): if data[key] is None: data[key] = '' data['curpk'] = bal.pk data['delete']='Delete' form = BallotForm(data, instance=bal) valid = form.is_valid() self.failUnless(valid) response = self.client.post(url,data) self.failIf(response.status_code!=302 and response.status_code!=303) url = reverse('del_ballot',args=[bal.number]) response.get('Location').index(url) response = self._check_page(url) match = re.search(r'input\s+type="submit"\s+name="confirm"', str(response), re.IGNORECASE) self.assertTrue(match) data = {"confirm":"Yes, I'm sure"} response = self.client.post(url,data) self.failIf(response.status_code!=302 and response.status_code!=303) self.failUnlessRaises(Ballot.DoesNotExist, Ballot.objects.get, pk=124) run_test_task_queue(self.client) self.failUnlessRaises(DenormalizedBallot.DoesNotExist, DenormalizedBallot.objects.get, pk=124)
def test_edit_ballot(self): proj = Project(name='test',order=0, doc_type='STD', description='test edit ballot', task_group='TGx', par_date=datetime.datetime.now()) proj.save() bal = Ballot(number=123,project=proj, ballot_type=Ballot.WGInitial.code, draft='1.0', opened=datetime.datetime.now(), pool=100) bal.closed = bal.opened + datetime.timedelta(days=15) bal.save() url = reverse('ballot.views.edit_ballot',args=[bal.number]) response = self._check_page(url) data = response.context['form'].initial for key in data.keys(): if data[key] is None: data[key] = '' data['curpk'] = bal.pk data['draft'] = '2.0' data['submit']='Save' form = BallotForm(data, instance=bal) valid = form.is_valid() self.failUnless(valid) response = self.client.post(url,data) self.failIf(response.status_code!=302 and response.status_code!=303) self.failUnlessEqual(Ballot.objects.count(),1) bal = Ballot.objects.get(pk=123) self.failUnlessEqual(float(bal.draft),2.0) # test renumbering the ballot, which should cause the old ballot object to be deleted data['number'] = 125 form = BallotForm(data, instance=bal) valid = form.is_valid() self.failUnless(valid) response = self.client.post(url,data) self.failIf(response.status_code!=302 and response.status_code!=303) self.failUnlessEqual(Ballot.objects.count(),1) bal = Ballot.objects.get(pk=125) self.failUnlessRaises(Ballot.DoesNotExist,Ballot.objects.get,pk=123)
def test_renumber_ballot(self): proj = Project(name='test', order=0, doc_type='STD', description='test_renumber_ballot', task_group='TGx', par_date=datetime.datetime.now()) proj.save() self.failUnlessEqual(Project.objects.count(), 1) self.failUnlessEqual(Ballot.objects.count(), 0) bal = Ballot(number=123, project=proj, draft='1.0', opened=datetime.datetime.now(), pool=100) bal.closed = bal.opened + datetime.timedelta(days=15) bal.save() self.failUnlessEqual(Ballot.objects.count(), 1) url = reverse('ballot.views.main_page', args=[]) self._check_page(url) #response = self.client.get(url) self.wait_for_backlog_completion(DenormalizedBallot, 10) dn = DenormalizedBallot.objects.get(pk=bal.pk) bal2 = Ballot.objects.get(number=bal.number) bal2.number = 321 bal2.save() Ballot.objects.get(number=123).delete() self.wait_for_backlog_completion(DenormalizedBallot, 10) self.failUnlessRaises(DenormalizedBallot.DoesNotExist, DenormalizedBallot.objects.get, number=123) dn = DenormalizedBallot.objects.get(number=bal2.number)
def test_edit_ballot(self): proj = Project(name='test', order=0, doc_type='STD', description='test edit ballot', task_group='TGx', par_date=datetime.datetime.now()) proj.save() bal = Ballot(number=123, project=proj, ballot_type=Ballot.WGInitial.code, draft='1.0', opened=datetime.datetime.now(), pool=100) bal.closed = bal.opened + datetime.timedelta(days=15) bal.save() url = reverse('ballot.views.edit_ballot', args=[bal.number]) response = self._check_page(url) data = response.context['form'].initial for key in data.keys(): if data[key] is None: data[key] = '' data['curpk'] = bal.pk data['draft'] = '2.0' data['submit'] = 'Save' form = BallotForm(data, instance=bal) valid = form.is_valid() self.failUnless(valid) response = self.client.post(url, data) self.failIf(response.status_code != 302 and response.status_code != 303) self.failUnlessEqual(Ballot.objects.count(), 1) bal = Ballot.objects.get(pk=123) self.failUnlessEqual(float(bal.draft), 2.0) # test renumbering the ballot, which should cause the old ballot object to be deleted data['number'] = 125 form = BallotForm(data, instance=bal) valid = form.is_valid() self.failUnless(valid) response = self.client.post(url, data) self.failIf(response.status_code != 302 and response.status_code != 303) self.failUnlessEqual(Ballot.objects.count(), 1) bal = Ballot.objects.get(pk=125) self.failUnlessRaises(Ballot.DoesNotExist, Ballot.objects.get, pk=123)
def test_renumber_ballot(self): proj = Project(name='test',order=0, doc_type='STD', description='test_renumber_ballot', task_group='TGx', par_date=datetime.datetime.now()) proj.save() self.failUnlessEqual(Project.objects.count(),1) self.failUnlessEqual(Ballot.objects.count(),0) bal = Ballot(number=123,project=proj, draft='1.0', opened=datetime.datetime.now(), pool=100) bal.closed = bal.opened + datetime.timedelta(days=15) bal.save() self.failUnlessEqual(Ballot.objects.count(),1) url = reverse('ballot.views.main_page',args=[]) self._check_page(url) #response = self.client.get(url) self.wait_for_backlog_completion(DenormalizedBallot, 10) dn = DenormalizedBallot.objects.get(pk=bal.pk) bal2 = Ballot.objects.get(number=bal.number) bal2.number = 321 bal2.save() Ballot.objects.get(number=123).delete() self.wait_for_backlog_completion(DenormalizedBallot, 10) self.failUnlessRaises(DenormalizedBallot.DoesNotExist, DenormalizedBallot.objects.get, number=123) dn = DenormalizedBallot.objects.get(number=bal2.number)