Exemplo n.º 1
0
def test_get_json_data_generic_paths():
    with open(os.path.join('cove_ocds', 'fixtures', 'tenders_releases_2_releases_with_deprecated_fields.json')) as fp:
        json_data_w_deprecations = json.load(fp)

    generic_paths = cove_common.get_json_data_generic_paths(json_data_w_deprecations)
    assert len(generic_paths.keys()) == 36
    assert generic_paths[('releases', 'buyer', 'name')] == {
        ('releases', 1, 'buyer', 'name'): 'Parks Canada',
        ('releases', 0, 'buyer', 'name'): 'Agriculture & Agrifood Canada'
    }
Exemplo n.º 2
0
def test_corner_cases_for_deprecated_data_fields(json_data):
    data = json.loads(json_data)
    schema = SchemaOCDS(release_data=data)
    json_data_paths = cove_common.get_json_data_generic_paths(data)
    deprecated_fields = cove_common.get_json_data_deprecated_fields(json_data_paths, schema)

    assert deprecated_fields['additionalIdentifiers']['explanation'][0] == '1.1'
    assert 'parties section at the top level of a release' in deprecated_fields['additionalIdentifiers']['explanation'][1]
    assert deprecated_fields['additionalIdentifiers']['paths'] == ('releases/buyer',)
    assert len(deprecated_fields.keys()) == 1
    assert len(deprecated_fields['additionalIdentifiers']['paths']) == 1
Exemplo n.º 3
0
def test_corner_cases_for_deprecated_data_fields(json_data):
    data = json.loads(json_data)
    schema = SchemaOCDS(release_data=data)
    json_data_paths = cove_common.get_json_data_generic_paths(data)
    deprecated_fields = cove_common.get_json_data_deprecated_fields(
        json_data_paths, schema)

    assert deprecated_fields["additionalIdentifiers"]["explanation"][
        0] == "1.1"
    assert ("parties section at the top level of a release"
            in deprecated_fields["additionalIdentifiers"]["explanation"][1])
    assert deprecated_fields["additionalIdentifiers"]["paths"] == (
        "releases/buyer", )
    assert len(deprecated_fields.keys()) == 1
    assert len(deprecated_fields["additionalIdentifiers"]["paths"]) == 1
Exemplo n.º 4
0
def test_get_json_data_generic_paths():
    with open(
            os.path.join(
                "tests",
                "fixtures",
                "tenders_releases_2_releases_with_deprecated_fields.json",
            )) as fp:
        json_data_w_deprecations = json.load(fp)

    generic_paths = cove_common.get_json_data_generic_paths(
        json_data_w_deprecations, generic_paths={})
    assert len(generic_paths.keys()) == 36
    assert generic_paths[("releases", "buyer", "name")] == {
        ("releases", 1, "buyer", "name"): "Parks Canada",
        ("releases", 0, "buyer", "name"): "Agriculture & Agrifood Canada",
    }
Exemplo n.º 5
0
def test_get_json_data_deprecated_fields():
    with open(
            os.path.join(
                "tests",
                "fixtures",
                "tenders_releases_2_releases_with_deprecated_fields.json",
            )) as fp:
        json_data_w_deprecations = json.load(fp)

    schema_obj = SchemaOCDS()
    schema_obj.schema_host = os.path.join(
        "tests", "fixtures/")  # "/" is for urljoin in lib-cove
    schema_obj.pkg_schema_name = (
        "release_package_schema_ref_release_schema_deprecated_fields.json")
    schema_obj.pkg_schema_url = os.path.join(schema_obj.schema_host,
                                             schema_obj.pkg_schema_name)
    json_data_paths = cove_common.get_json_data_generic_paths(
        json_data_w_deprecations, generic_paths={})
    deprecated_data_fields = cove_common.get_json_data_deprecated_fields(
        json_data_paths, schema_obj)
    expected_result = OrderedDict([
        (
            "initiationType",
            {
                "paths": ("releases/0", "releases/1"),
                "explanation": (
                    "1.1",
                    "Not a useful field as always has to be tender",
                ),
            },
        ),
        (
            "quantity",
            {
                "paths": ("releases/0/tender/items/0", ),
                "explanation": ("1.1", "Nobody cares about quantities"),
            },
        ),
    ])
    for field_name in expected_result.keys():
        assert field_name in deprecated_data_fields
        assert (expected_result[field_name]["paths"] ==
                deprecated_data_fields[field_name]["paths"])
        assert (expected_result[field_name]["explanation"] ==
                deprecated_data_fields[field_name]["explanation"])
Exemplo n.º 6
0
def test_get_json_data_deprecated_fields():
    with open(os.path.join('cove_ocds', 'fixtures', 'tenders_releases_2_releases_with_deprecated_fields.json')) as fp:
        json_data_w_deprecations = json.load(fp)

    schema_obj = SchemaOCDS()
    schema_obj.schema_host = os.path.join('cove_ocds', 'fixtures/')
    schema_obj.release_pkg_schema_name = 'release_package_schema_ref_release_schema_deprecated_fields.json'
    schema_obj.release_pkg_schema_url = os.path.join(schema_obj.schema_host, schema_obj.release_pkg_schema_name)
    json_data_paths = cove_common.get_json_data_generic_paths(json_data_w_deprecations)
    deprecated_data_fields = cove_common.get_json_data_deprecated_fields(json_data_paths, schema_obj)
    expected_result = OrderedDict([
        ('initiationType', {"paths": ('releases/0', 'releases/1'),
                            "explanation": ('1.1', 'Not a useful field as always has to be tender')}),
        ('quantity', {"paths": ('releases/0/tender/items/0',),
                      "explanation": ('1.1', 'Nobody cares about quantities')})
    ])
    for field_name in expected_result.keys():
        assert field_name in deprecated_data_fields
        assert expected_result[field_name]["paths"] == deprecated_data_fields[field_name]["paths"]
        assert expected_result[field_name]["explanation"] == deprecated_data_fields[field_name]["explanation"]
Exemplo n.º 7
0
def test_get_json_data_missing_ids():
    file_name = os.path.join(
        'cove_ocds', 'fixtures', 'tenders_releases_2_releases_1_1_tenderers_with_missing_ids.json'
    )
    with open(os.path.join(file_name)) as fp:
        user_data = json.load(fp)

    schema_obj = SchemaOCDS(release_data=user_data)
    results = [
        'releases/0/tender/tenderers/1/id',
        'releases/0/tender/tenderers/2/id',
        'releases/0/tender/tenderers/5/id',
        'releases/1/tender/tenderers/1/id',
        'releases/1/tender/tenderers/2/id',
        'releases/1/tender/tenderers/4/id'
    ]
    user_data_paths = cove_common.get_json_data_generic_paths(user_data)
    missin_ids_paths = cove_common.get_json_data_missing_ids(user_data_paths, schema_obj)

    assert missin_ids_paths == results
Exemplo n.º 8
0
def test_get_json_data_missing_ids():
    file_name = os.path.join(
        "cove_ocds",
        "fixtures",
        "tenders_releases_2_releases_1_1_tenderers_with_missing_ids.json",
    )
    with open(os.path.join(file_name)) as fp:
        user_data = json.load(fp)

    schema_obj = SchemaOCDS(release_data=user_data)
    results = [
        "releases/0/tender/tenderers/1/id",
        "releases/0/tender/tenderers/2/id",
        "releases/0/tender/tenderers/5/id",
        "releases/1/tender/tenderers/1/id",
        "releases/1/tender/tenderers/2/id",
        "releases/1/tender/tenderers/4/id",
    ]
    user_data_paths = cove_common.get_json_data_generic_paths(user_data)
    missin_ids_paths = cove_common.get_json_data_missing_ids(
        user_data_paths, schema_obj)

    assert missin_ids_paths == results