Exemple #1
0
def test_person_summary():
    settings = {'us': {'upper_seats': 100, 'lower_seats': 435},
                'http_whitelist': ['http://bad.example.com']}
    v = Validator('us', settings)

    people = [
        {'gender': 'F', 'image': 'https://example.com/image1',
         'party': [{'name': 'Democratic'}, {'name': 'Democratic', 'end_date': '1990'}],
         },
        {'gender': 'F', 'image': 'https://example.com/image2',
         'party': [{'name': 'Democratic'}, {'name': 'Working Families'}],
         'extras': {'religion': 'Zoroastrian'},
         'contact_details': [{'fax': '123-456-7890'}],
         'other_identifiers': [{'scheme': 'fake', 'identifier': 'abc'}],
         'ids': {'twitter': 'fake'},
         },
        {'gender': 'M', 'image': 'https://example.com/image3',
         'party': [{'name': 'Republican'}],
         'contact_details': [{'phone': '123-456-7890'}],
         'other_identifiers': [{'scheme': 'fake', 'identifier': '123'}],
         },
    ]

    for p in people:
        v.summarize_person(p)

    assert v.parties == {'Republican': 1, 'Democratic': 2,
                         'Working Families': 1}
    assert v.contact_counts == {'phone': 1, 'fax': 1}
    assert v.id_counts == {'fake': 2, 'twitter': 1}
    assert v.optional_fields == {'gender': 3, 'image': 3}
    assert v.extra_counts == {'religion': 1}
Exemple #2
0
def test_validator_check_https():
    settings = {
        'us': {
            'upper_seats': 100,
            'lower_seats': 435
        },
        'http_whitelist': ['http://bad.example.com']
    }
    v = Validator('us', settings)

    person = {
        'links': [
            {
                'url': 'https://example.com'
            },
            {
                'url': 'http://insecure.example.com'
            },
            {
                'url': 'https://bad.example.com'
            },
        ]
    }
    warnings = v.check_https(person)
    assert len(warnings) == 1
    assert 'links.1' in warnings[0]
Exemple #3
0
def test_validator_check_https():
    settings = {
        "us": {
            "upper_seats": 100,
            "lower_seats": 435
        },
        "http_whitelist": ["http://bad.example.com"],
    }
    v = Validator("us", settings)

    person = {
        "links": [
            {
                "url": "https://example.com"
            },
            {
                "url": "http://insecure.example.com"
            },
            {
                "url": "https://bad.example.com"
            },
        ]
    }
    warnings = v.check_https(person)
    assert len(warnings) == 1
    assert "links.1" in warnings[0]
Exemple #4
0
def test_person_duplicates():
    settings = {"http_whitelist": ["http://bad.example.com"], "parties": []}
    v = Validator("ak", settings)

    people = [
        # duplicates across people
        {
            "id": "ocd-person/1",
            "name": "One",
            "ids": {
                "twitter": "no-twitter",
                "youtube": "fake"
            }
        },
        {
            "id": "ocd-person/2",
            "name": "Two",
            "ids": {
                "twitter": "no-twitter",
                "youtube": "fake"
            }
        },
        # duplicate on same person
        {
            "id":
            "ocd-person/3",
            "name":
            "Three",
            "ids": {
                "twitter": "no-twitter"
            },
            "other_identifiers": [
                {
                    "scheme": "external_service_id",
                    "identifier": "XYZ"
                },
                {
                    "scheme": "external_service_id",
                    "identifier": "XYZ"
                },
            ],
        },
        {
            "id": "ocd-person/4",
            "name": "Four",
            "ids": {
                "twitter": "no-twitter"
            }
        },
    ]
    for p in people:
        v.summarize_person(p)
    errors = v.check_duplicates()
    assert len(errors) == 3
    assert 'duplicate youtube: "fake" One-1.yml, Two-2.yml' in errors
    assert 'duplicate external_service_id: "XYZ" Three-3.yml, Three-3.yml' in errors
    assert (
        'duplicate twitter: "no-twitter" One-1.yml, Two-2.yml, Three-3.yml and 1 more...'
        in errors)
Exemple #5
0
def test_filename_id_test():
    person = {
        "id": EXAMPLE_OCD_PERSON_ID,
        "name": "Jane Smith",
        "roles": [],
        "party": []
    }
    v = Validator("ak", {"parties": []})
    v.validate_person(person, "bad-filename")
    for err in v.errors["bad-filename"]:
        if f"not in filename" in err:
            break
    else:
        raise AssertionError("did not check for id in filename")
Exemple #6
0
def test_filename_id_test():
    person = {'id': EXAMPLE_OCD_PERSON_ID,
              'name': 'Jane Smith',
              'roles': [],
              'party': [],
              }
    settings = {'us': {'upper_seats': 100, 'lower_seats': 435}}
    v = Validator('us', settings)
    v.validate_person(person, 'bad-filename')
    for err in v.errors['bad-filename']:
        if f'not in filename' in err:
            break
    else:
        raise AssertionError("did not check for id in filename")
Exemple #7
0
def test_filename_id_test():
    person = {
        "id": EXAMPLE_OCD_PERSON_ID,
        "name": "Jane Smith",
        "roles": [],
        "party": []
    }
    settings = {"us": {"upper_seats": 100, "lower_seats": 435}}
    v = Validator("us", settings)
    v.validate_person(person, "bad-filename")
    for err in v.errors["bad-filename"]:
        if f"not in filename" in err:
            break
    else:
        raise AssertionError("did not check for id in filename")
Exemple #8
0
def test_validator_check_https():
    settings = {"http_whitelist": ["http://bad.example.com"], "parties": []}
    v = Validator("ak", settings)

    person = {
        "links": [
            {
                "url": "https://example.com"
            },
            {
                "url": "http://insecure.example.com"
            },
            {
                "url": "https://bad.example.com"
            },
        ]
    }
    warnings = v.check_https(person)
    assert len(warnings) == 1
    assert "links.1" in warnings[0]
Exemple #9
0
def test_person_duplicates():
    settings = {'us': {'upper_seats': 100, 'lower_seats': 435},
                'http_whitelist': ['http://bad.example.com']}
    v = Validator('us', settings)

    people = [
        # duplicates across people
        {
            'id': 'ocd-person/1', 'name': 'One',
            'ids': {'twitter': 'no-twitter', 'youtube': 'fake'},
         },
        {
            'id': 'ocd-person/2', 'name': 'Two',
            'ids': {'twitter': 'no-twitter', 'youtube': 'fake'},
         },
        # duplicate on same person
        {
            'id': 'ocd-person/3', 'name': 'Three',
            'ids': {'twitter': 'no-twitter'},
            'other_identifiers': [
                {'scheme': 'external_service_id', 'identifier': 'XYZ'},
                {'scheme': 'external_service_id', 'identifier': 'XYZ'},
            ]
         },
        {
            'id': 'ocd-person/4', 'name': 'Four',
            'ids': {'twitter': 'no-twitter'},
         },
    ]
    for p in people:
        v.summarize_person(p)
    errors = v.check_duplicates()
    assert len(errors) == 3
    assert 'duplicate youtube: "fake" One-1.yml, Two-2.yml' in errors
    assert 'duplicate external_service_id: "XYZ" Three-3.yml, Three-3.yml' in errors
    assert ('duplicate twitter: "no-twitter" One-1.yml, Two-2.yml, Three-3.yml and 1 more...'
            in errors)
Exemple #10
0
def test_validate_org_memberships():
    person = {
        'id': EXAMPLE_OCD_PERSON_ID,
        'name': 'Jane Smith',
        'roles': [],
        'party': [],
    }
    org = {
        'id': EXAMPLE_OCD_ORG_ID,
        'name': 'Finance Committee',
        'jurisdiction': 'ocd-jurisdiction/country:us',
        'parent': 'lower',
        'classification': 'committee',
        'memberships': []
    }
    settings = {'us': {'upper_seats': 100, 'lower_seats': 435}}

    # a good membership
    org['memberships'] = [{'id': EXAMPLE_OCD_PERSON_ID, 'name': 'Jane Smith'}]
    v = Validator('us', settings)
    v.validate_person(person,
                      'fake-person')  # validate person first to learn ID
    v.validate_org(org, 'fake-org')
    assert v.errors['fake-org'] == []
    assert v.warnings['fake-org'] == []

    # a bad ID
    org['memberships'] = [{
        'id': 'ocd-person/00000000-0000-0000-0000-000000000000',
        'name': 'Jane Smith'
    }]
    v = Validator('us', settings)
    v.validate_person(person, 'fake-person')
    v.validate_org(org, 'fake-org')
    assert len(v.errors['fake-org']) == 1

    # bad name, warning
    org['memberships'] = [{'id': EXAMPLE_OCD_PERSON_ID, 'name': 'Smith'}]
    v = Validator('us', settings)
    v.validate_person(person, 'fake-person')
    v.validate_org(org, 'fake-org')
    assert len(v.warnings['fake-org']) == 1
    assert v.warnings['fake-org']
Exemple #11
0
def test_validate_org_memberships():
    person = {
        "id": EXAMPLE_OCD_PERSON_ID,
        "name": "Jane Smith",
        "roles": [],
        "party": []
    }
    org = {
        "id": EXAMPLE_OCD_ORG_ID,
        "name": "Finance Committee",
        "jurisdiction": "ocd-jurisdiction/country:us",
        "parent": "lower",
        "classification": "committee",
        "memberships": [],
    }
    settings = {"us": {"upper_seats": 100, "lower_seats": 435}}
    org_filename = "fake-org-" + EXAMPLE_OCD_ORG_ID
    person_filename = "fake-person-" + EXAMPLE_OCD_PERSON_ID

    # a good membership
    org["memberships"] = [{"id": EXAMPLE_OCD_PERSON_ID, "name": "Jane Smith"}]
    v = Validator("us", settings)
    # validate person first to learn ID
    v.validate_person(person, person_filename)
    v.validate_org(org, org_filename)
    assert v.errors[org_filename] == []
    assert v.warnings[org_filename] == []

    # a bad ID
    org["memberships"] = [{
        "id": "ocd-person/00000000-0000-0000-0000-000000000000",
        "name": "Jane Smith"
    }]
    v = Validator("us", settings)
    v.validate_person(person, person_filename)
    v.validate_org(org, org_filename)
    print(v.errors)
    assert len(v.errors[org_filename]) == 1

    # bad name, warning
    org["memberships"] = [{"id": EXAMPLE_OCD_PERSON_ID, "name": "Smith"}]
    v = Validator("us", settings)
    v.validate_person(person, person_filename)
    v.validate_org(org, org_filename)
    assert len(v.warnings[org_filename]) == 1
    assert v.warnings[org_filename]
Exemple #12
0
def test_person_summary():
    settings = {
        "us": {
            "upper_seats": 100,
            "lower_seats": 435
        },
        "http_whitelist": ["http://bad.example.com"],
    }
    v = Validator("us", settings)

    people = [
        {
            "gender":
            "F",
            "image":
            "https://example.com/image1",
            "party": [{
                "name": "Democratic"
            }, {
                "name": "Democratic",
                "end_date": "1990"
            }],
        },
        {
            "gender": "F",
            "image": "https://example.com/image2",
            "party": [{
                "name": "Democratic"
            }, {
                "name": "Working Families"
            }],
            "extras": {
                "religion": "Zoroastrian"
            },
            "contact_details": [{
                "fax": "123-456-7890"
            }],
            "other_identifiers": [{
                "scheme": "fake",
                "identifier": "abc"
            }],
            "ids": {
                "twitter": "fake"
            },
        },
        {
            "gender": "M",
            "image": "https://example.com/image3",
            "party": [{
                "name": "Republican"
            }],
            "contact_details": [{
                "phone": "123-456-7890"
            }],
            "other_identifiers": [{
                "scheme": "fake",
                "identifier": "123"
            }],
        },
    ]

    for p in people:
        v.summarize_person(p)

    assert v.parties == {
        "Republican": 1,
        "Democratic": 2,
        "Working Families": 1
    }
    assert v.contact_counts == {"phone": 1, "fax": 1}
    assert v.id_counts == {"fake": 2, "twitter": 1}
    assert v.optional_fields == {"gender": 3, "image": 3}
    assert v.extra_counts == {"religion": 1}