def test_bill_no_actions(self): org = Organization.objects.create(name="Org for Bill with no actions", jurisdiction=self.jur) p = Person.objects.create(name="Person for Bill with no actions") ls = LegislativeSession.objects.get(identifier="2017") bill = Bill.objects.create(legislative_session=ls, identifier="Bill with No Actions") bill.versions.create(note="Bill with version", date="2017-06-28") bill.sponsorships.create(classification="Bill with matched person sponsor", name="matched Person Sponsor", entity_type='person', person=p) bill.sponsorships.create(classification="Bill with matched organization sponsor", name="matched Organization Sponsor", organization=org, entity_type='organization') # To check that on running twice no duplicate DataQualityIssue are being created. bills_report(self.jur) bills_report(self.jur) h = DataQualityIssue.objects.filter(object_id=bill.id, issue='bill-no-actions').count() rest = DataQualityIssue.objects.exclude(object_id=bill.id, issue='bill-no-actions') self.assertEqual(h, 1) self.assertQuerysetEqual(rest, [])
def test_bill_delete_active_dqis(self): ls = LegislativeSession.objects.get(identifier="2017") bill = Bill.objects.create(legislative_session=ls, identifier="BS01") # Some Data Quality Issues DataQualityIssue.objects.create(jurisdiction=self.jur, content_object=bill, alert='error', issue='bill-no-actions', status='ignored') DataQualityIssue.objects.create(jurisdiction=self.jur, content_object=bill, alert='warning', issue='bill-no-sponsors', status='active') DataQualityIssue.objects.create(jurisdiction=self.jur, content_object=bill, alert='warning', issue='bill-no-versions', status='active') bills_report(self.jur) ignored_issues = DataQualityIssue.objects.filter( status='ignored', issue='bill-no-actions') active_issues = DataQualityIssue.objects.filter(status='active') self.assertEqual(len(ignored_issues), 1) self.assertEqual(len(active_issues), 2)
def test_bill_unmatched_person_sponsor(self): org = Organization.objects.create(name="Org: Unmatched person sponsor", jurisdiction=self.jur) ls = LegislativeSession.objects.get(identifier="2017") bill = Bill.objects.create(legislative_session=ls, identifier="Bill: Unmatched person sponsor") bill.actions.create(description="Bill with Action", organization=org, date="2017-06-28", order=2) bill.versions.create(note="Bill with version", date="2017-06-28") bill.sponsorships.create( classification="Bill with unmatched person sponsor", name="Unmatched Person Sponsor", entity_type='person') bill.sponsorships.create( classification="Bill with matched organization sponsor", name="matched Organization Sponsor", organization=org, entity_type='organization') bills_report(self.jur) h = DataQualityIssue.objects.filter( object_id=bill.id, issue='bill-unmatched-person-sponsor') rest = DataQualityIssue.objects.exclude( object_id=bill.id, issue='bill-unmatched-person-sponsor') self.assertEqual(len(h), 1) self.assertQuerysetEqual(rest, [])
def test_bill_no_versions(self): org = Organization.objects.create(name="Org for Bill with no versions", jurisdiction=self.jur) p = Person.objects.create(name="Person for Bill with no versions") ls = LegislativeSession.objects.get(identifier="2017") bill = Bill.objects.create(legislative_session=ls, identifier="Bill with No Versions") bill.actions.create(description="Bill with Action", organization=org, date="2017-06-28", order=2) bill.sponsorships.create( classification="Bill with matched person sponsor", name="matched Person Sponsor", entity_type='person', person=p) bill.sponsorships.create( classification="Bill with matched organization sponsor", name="matched Organization Sponsor", organization=org, entity_type='organization') bills_report(self.jur) h = DataQualityIssue.objects.filter(object_id=bill.id, issue='bill-no-versions').count() rest = DataQualityIssue.objects.exclude(issue='bill-no-versions') self.assertEqual(h, 1) self.assertQuerysetEqual(rest, [])
def test_bill_zzz_valueerror_on_not_updated_new_issue(self): IssueType('missing-billxyz', 'Missing BillXYZ', 'bill', 'error') DataQualityIssue._meta.get_field('issue').choices.append( ('missing-billxyz', 'Missing BillXYZ')) try: bills_report(self.jur) except ValueError as e: exception_raised = True self.assertEqual(str(e), 'Bill Importer needs update for new issue.') self.assertEqual(exception_raised, True)
def test_bill_no_sponsors(self): org = Organization.objects.create(name="Org for Bill with no sponsor", jurisdiction=self.jur) ls = LegislativeSession.objects.get(identifier="2017") bill = Bill.objects.create(legislative_session=ls, identifier="Bill with No Sponsors") bill.actions.create(description="Bill with Action", organization=org, date="2017-06-28", order=2) bill.versions.create(note="Bill with version", date="2017-06-28") bills_report(self.jur) h = DataQualityIssue.objects.filter(issue='bill-no-sponsors').count() rest = DataQualityIssue.objects.exclude(issue='bill-no-sponsors') self.assertEqual(h, 1) self.assertQuerysetEqual(rest, [])
def test_bill_unmatched_org_sponsor(self): org = Organization.objects.create(name="Org for Unmatched org sponsor", jurisdiction=self.jur) p = Person.objects.create(name="Person for Unmatched org sponsor") ls = LegislativeSession.objects.get(identifier="2017") bill = Bill.objects.create(legislative_session=ls, identifier="Bill: Unmatched org sponsor") bill.actions.create(description="Bill with Action", organization=org, date="2017-06-28", order=2) bill.versions.create(note="Bill with version", date="2017-06-28") bill.sponsorships.create(classification="Bill with matched person sponsor", name="matched Person Sponsor", entity_type='person', person=p) bill.sponsorships.create(classification="Bill with matched organization sponsor", name="unmatched Organization Sponsor", entity_type='organization') bills_report(self.jur) issues = DataQualityIssue.objects.filter(unmatched_name='unmatched Organization Sponsor', issue='bill-unmatched-org-sponsor') self.assertEqual(len(issues), 1)