def test_policy_from_row_duplicate(): assert Policy.objects.count() == 0 row = policy_row_factory(policyNumber='123', policyTitle='title 1') import_reqs.PolicyProcessor().from_row(row) assert Policy.objects.count() == 1 assert Policy.objects.get(policy_number=123).title == 'title 1' row['policyTitle'] = 'title 2' import_reqs.PolicyProcessor().from_row(row) assert Policy.objects.count() == 1 assert Policy.objects.get(policy_number=123).title == 'title 2'
def test_varying_policy_headers(opfid_field, uri_field): """ Test that we can handle a variety of names for fields (in this case, the OMB Policy ID field). """ row = policy_row_factory(policyNumber='123') del row['uriPolicyId'] del row['ombPolicyId'] row[opfid_field] = "some identifier" row[uri_field] = "http://example.com/a" policy_proc = import_reqs.PolicyProcessor() policy = policy_proc.from_row(row) assert policy.policy_number == 123 assert policy.omb_policy_id == "some identifier" assert policy.uri == "http://example.com/a"
def test_policy_from_row(): row = policy_row_factory(policyNumber='123', policyTitle='title 1', uriPolicyId='http://example.com/a', ombPolicyId='policy', policyType='Memo', policyIssuanceYear='12/20/2001', policySunset='NA', issuingBody='IBIB') policy_proc = import_reqs.PolicyProcessor() policy = policy_proc.from_row(row) assert policy.policy_number == 123 assert policy.title == 'title 1' assert policy.uri == 'http://example.com/a' assert policy.omb_policy_id == 'policy' assert PolicyTypes[policy.policy_type].name == PolicyTypes.memorandum.name assert policy.issuance == date(2001, 12, 20) assert policy.sunset is None assert {123: policy} == policy_proc.policies assert policy.issuing_body == 'IBIB'
def test_no_matching_policy_type(): """If the policy type isn't found, raise an exception""" row = policy_row_factory(policyType='IAmAnOutlier') policy_proc = import_reqs.PolicyProcessor() with pytest.raises(ValueError): policy_proc.from_row(row)