Esempio n. 1
0
def test_validate_required():
    example = {"id": EXAMPLE_OCD_PERSON_ID, "name": "Anne A"}

    # with required fields
    assert validate_obj(example, PERSON_FIELDS) == []

    errs = validate_obj({}, PERSON_FIELDS)
    assert len(errs) == 2
    assert "id missing" in errs
Esempio n. 2
0
def test_validate_required():
    example = {
        'id': EXAMPLE_OCD_PERSON_ID,
        'name': 'Anne A',
    }

    # with required fields
    assert validate_obj(example, PERSON_FIELDS) == []

    errs = validate_obj({}, PERSON_FIELDS)
    assert len(errs) == 2
    assert 'id missing' in errs
Esempio n. 3
0
def test_validate_nested_role_list():
    example = {
        'id':
        EXAMPLE_OCD_PERSON_ID,
        'name':
        'Anne A',
        'roles': [
            {
                'type': 'upper',
                'district': '4',
                'end_date': '2010',
                'jurisdiction': 'ocd-jurisdiction/country:us/state:nc'
            },
            {
                'type': 'gov',
                'start_date': '2010',
                'jurisdiction': 'ocd-jurisdiction/country:us/state:nc'
            },
            # bad roles
            {
                'type': 'upper',
                'jurisdiction': 'ocd-jurisdiction/country:us/state:nc'
            },
            {
                'type': 'gov',
                'district': '4',
                'jurisdiction': 'ocd-jurisdiction/country:us/state:nc'
            },
        ]
    }

    errs = validate_obj(example, PERSON_FIELDS)
    assert len(errs) == 2
    assert 'roles.2' in errs[0]
    assert 'roles.3' in errs[1]
Esempio n. 4
0
def test_validate_nested_role_list():
    example = {
        "id":
        EXAMPLE_OCD_PERSON_ID,
        "name":
        "Anne A",
        "roles": [
            {
                "type": "upper",
                "district": "4",
                "end_date": "2010",
                "jurisdiction": "ocd-jurisdiction/country:us/state:nc",
            },
            {
                "type": "gov",
                "start_date": "2010",
                "jurisdiction": "ocd-jurisdiction/country:us/state:nc",
            },
            # bad roles
            {
                "type": "upper",
                "jurisdiction": "ocd-jurisdiction/country:us/state:nc"
            },
            {
                "type": "gov",
                "district": "4",
                "jurisdiction": "ocd-jurisdiction/country:us/state:nc",
            },
        ],
    }

    errs = validate_obj(example, PERSON_FIELDS)
    assert len(errs) == 2
    assert "roles.2" in errs[0]
    assert "roles.3" in errs[1]
Esempio n. 5
0
def test_validate_nested_required():
    example = {
        "id": EXAMPLE_OCD_PERSON_ID,
        "name": "Anne A",
        "links": [{
            "url": "https://example.com"
        }, {
            "note": "note only"
        }],
    }

    assert validate_obj(example, PERSON_FIELDS) == ["links.1.url missing"]
Esempio n. 6
0
def test_validate_nested_list():
    example = {
        "id": EXAMPLE_OCD_PERSON_ID,
        "name": "Anne A",
        "links": [{
            "url": "example.com"
        }]
    }

    errs = validate_obj(example, PERSON_FIELDS)
    assert len(errs) == 1
    assert "links.0.url" in errs[0]
Esempio n. 7
0
def test_validate_nested_list():
    example = {
        'id': EXAMPLE_OCD_PERSON_ID,
        'name': 'Anne A',
        'links': [
            {'url': 'example.com'},
        ]
    }

    errs = validate_obj(example, PERSON_FIELDS)
    assert len(errs) == 1
    assert 'links.0.url' in errs[0]
Esempio n. 8
0
def test_validate_nested_object():
    example = {
        'id': EXAMPLE_OCD_PERSON_ID,
        'name': 'Anne A',
        'ids': {
            'twitter': '@bad-name',
            'youtube': 'is-ok',
        }
    }

    errs = validate_obj(example, PERSON_FIELDS)
    assert len(errs) == 1
    assert 'ids.twitter' in errs[0]
Esempio n. 9
0
def test_validate_nested_object():
    example = {
        "id": EXAMPLE_OCD_PERSON_ID,
        "name": "Anne A",
        "ids": {
            "twitter": "@bad-name",
            "youtube": "is-ok"
        },
    }

    errs = validate_obj(example, PERSON_FIELDS)
    assert len(errs) == 1
    assert "ids.twitter" in errs[0]
Esempio n. 10
0
def test_validate_nested_required():
    example = {
        'id': EXAMPLE_OCD_PERSON_ID,
        'name': 'Anne A',
        'links': [
            {'url': 'https://example.com'},
            {'note': 'note only'},
        ]
    }

    assert validate_obj(example, PERSON_FIELDS) == [
        'links.1.url missing'
    ]
Esempio n. 11
0
def test_validate_extra_keys_not_present():
    example = {
        'id': EXAMPLE_OCD_PERSON_ID,
        'name': 'Anne A',
        'junk': 100,
        'links': [
            {'url': 'https://example.com', 'bad': 100},
        ]
    }

    errs = validate_obj(example, PERSON_FIELDS)
    assert len(errs) == 2
    assert 'extra key: junk' in errs
    assert 'extra key: links.0.bad' in errs
Esempio n. 12
0
def test_validate_extra_keys_not_present():
    example = {
        "id": EXAMPLE_OCD_PERSON_ID,
        "name": "Anne A",
        "junk": 100,
        "links": [{
            "url": "https://example.com",
            "bad": 100
        }],
    }

    errs = validate_obj(example, PERSON_FIELDS)
    assert len(errs) == 2
    assert "extra key: junk" in errs
    assert "extra key: links.0.bad" in errs