def test_bill_delete_active_dqis(self): org = Organization.objects.create(name="Democratic", jurisdiction=self.jur) ls = LegislativeSession.objects.get(identifier="2017") voteevent = VoteEvent.objects.create( identifier="vote1", motion_text="VoteEvent with missing-bills & missingvoters", start_date="2017-06-26", result='pass', legislative_session=ls, organization=org) # Some Data Quality Issues DataQualityIssue.objects.create(jurisdiction=org.jurisdiction, content_object=voteevent, issue='voteevent-missing-bill', status='ignored') DataQualityIssue.objects.create(jurisdiction=org.jurisdiction, content_object=voteevent, issue='voteevent-missing-voters', status='active') vote_events_report(self.jur) ignored_issues = DataQualityIssue.objects.filter( status='ignored', issue='voteevent-missing-bill') active_issues = DataQualityIssue.objects.filter(status='active') self.assertEqual(len(ignored_issues), 1) self.assertEqual(len(active_issues), 1)
def test_voteevent_zzz_valueerror_on_not_updated_new_issue(self): IssueType('missing-votexyz', 'Missing VoteXYZ', 'voteevent', 'warning') DataQualityIssue._meta.get_field('issue').choices.append( ('missing-votexyz', 'Missing VoteXYZ')) try: vote_events_report(self.jur) except ValueError as e: exception_raised = True self.assertEqual(str(e), 'VoteEvents Importer needs update for new issue.') self.assertEqual(exception_raised, True)
def test_voteevent_unmatched_voter(self): org = Organization.objects.create(name="Democratic", jurisdiction=self.jur) bill = Bill.objects.get(identifier="Bill for VoteEvent") ls = LegislativeSession.objects.get(identifier="2017") voteevent = VoteEvent.objects.create(identifier="vote1", motion_text="VoteEvent with unmatched-voter", start_date="2017-06-26", result='pass', legislative_session=ls, organization=org, bill=bill) voteevent.votes.create(option="yes", voter_name="unmatched-voter") voteevent.counts.create(option="yes", value=1) vote_events_report(self.jur) issues = DataQualityIssue.objects.filter(unmatched_name='unmatched-voter', issue='voteevent-unmatched-voter').count() self.assertEqual(issues, 1)
def test_voteevent_missing_bill(self): org = Organization.objects.create(name="Democratic", jurisdiction=self.jur) p = Person.objects.get(name="Voter") ls = LegislativeSession.objects.get(identifier="2017") voteevent = VoteEvent.objects.create(identifier="vote1", motion_text="VoteEvent with missing-bill", start_date="2017-06-26", result='pass', legislative_session=ls, organization=org) voteevent.votes.create(option="yes", voter=p) voteevent.counts.create(option="yes", value=1) vote_events_report(self.jur) h = DataQualityIssue.objects.filter(object_id=voteevent.id, issue='voteevent-missing-bill').count() rest = DataQualityIssue.objects .exclude(object_id=voteevent.id, issue='voteevent-missing-bill') self.assertEqual(h, 1) self.assertQuerysetEqual(rest, [])
def test_voteevent_missing_voters(self): org = Organization.objects.create(name="Democratic", jurisdiction=self.jur) bill = Bill.objects.get(identifier="Bill for VoteEvent") ls = LegislativeSession.objects.get(identifier="2017") voteevent = VoteEvent.objects.create( identifier="vote1", motion_text="VoteEvent with missing-voters", start_date="2017-06-26", result='pass', legislative_session=ls, organization=org, bill=bill) # To check that on running twice no duplicate DataQualityIssue are being created. vote_events_report(self.jur) vote_events_report(self.jur) h = DataQualityIssue.objects.filter(object_id=voteevent.id, issue='voteevent-missing-voters').count() rest = DataQualityIssue.objects.exclude(object_id=voteevent.id, issue='voteevent-missing-voters') self.assertEqual(h, 1) self.assertQuerysetEqual(rest, [])
def test_voteevent_bad_counts(self): org = Organization.objects.create(name="Democratic", jurisdiction=self.jur) p = Person.objects.get(name="Voter") bill = Bill.objects.get(identifier="Bill for VoteEvent") ls = LegislativeSession.objects.get(identifier="2017") voteevent = VoteEvent.objects.create( identifier="vote1", motion_text="VoteEvent with bad-counts", start_date="2017-06-26", result='pass', legislative_session=ls, organization=org, bill=bill) voteevent.votes.create(option="yes", voter=p) voteevent.counts.create(option="yes", value=1) voteevent.counts.create(option="no", value=1) voteevent.counts.create(option="other", value=1) vote_events_report(self.jur) issues = DataQualityIssue.objects.filter(object_id=voteevent.id, issue='voteevent-bad-counts').count() rest = DataQualityIssue.objects.exclude(object_id=voteevent.id, issue='voteevent-bad-counts') self.assertEqual(issues, 1) self.assertQuerysetEqual(rest, [])