Skip to content

Commit

Permalink
Additional MITAardvark methods
Browse files Browse the repository at this point in the history
Why these changes are being introduced:
* Additonal methods are needed for the MITAardvark class

How this addresses that need:
* Update get_optional_fields method to include format and summary values and add corresponding unit test
* Add get_alternate_titles, get_contributors, get_notes, get_publication_information, and get_rights field methods along with calls in get_optional_fields and corresponding unit tests
* Update aardvark_record_all_fields fixture to include new fields

Side effects of this change:
* None

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/GDT-54
  • Loading branch information
ehanson8 committed Dec 19, 2023
1 parent 1aba987 commit dce0e82
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 9 deletions.
6 changes: 2 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ def runner():

@pytest.fixture
def aardvark_record_all_fields():
return next(
JsonTransformer.parse_source_file(
"tests/fixtures/aardvark/aardvark_record_all_fields.jsonl"
)
return JsonTransformer.parse_source_file(
"tests/fixtures/aardvark/aardvark_record_all_fields.jsonl"
)


Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/aardvark/aardvark_record_all_fields.jsonl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id": "123", "dcat_keyword_sm": ["Country"], "dcat_theme_sm": ["Political boundaries"], "dct_spatial_sm": ["Some city, Some country"], "dct_subject_sm": ["Geography", "Earth"], "gbl_resourceClass_sm": ["Dataset"], "gbl_resourceType_sm": ["Vector data"], "dct_title_s": "Test title 1"}
{"id": "123", "dcat_bbox": "ENVELOPE(-111.1, -104.0, 45.0, 40.9)", "dcat_keyword_sm": ["Country"], "dcat_theme_sm": ["Political boundaries"], "dct_accessRights_s": "Access note", "dct_alternative_sm": ["Alternate title"], "dct_creator_sm": ["Smith, Jane", "Smith, John"], "dct_description_sm": ["A description"], "dct_format_s": "Shapefile", "dct_language_sm": ["eng"], "dct_license_sm": "http://license.license", "dct_publisher_sm": ["ML InfoMap (Firm)"], "dct_rights_sm": ["Some person has the rights"], "dct_rightsHolder_sm": ["The person with the rights", "Another person with the rights"], "dct_spatial_sm": ["Some city, Some country"], "dct_subject_sm": ["Geography", "Earth"], "dct_title_s": "Test title 1", "gbl_displayNote_sm": ["Danger: This text will be displayed in a red box","Info: This text will be displayed in a blue box","Tip: This text will be displayed in a green box","Warning: This text will be displayed in a yellow box","This is text without a tag and it will be assigned default 'note' style"], "gbl_resourceClass_sm": ["Dataset"], "gbl_resourceType_sm": ["Vector data"], "locn_geometry": "POLYGON((-80 25, -65 18, -64 33, -80 25))", "schema_provider_s": "MIT"}
83 changes: 79 additions & 4 deletions tests/sources/json/test_aardvark.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_aardvark_get_required_fields_returns_expected_values(aardvark_records):
}


def test_jsontransformer_transform_returns_timdex_record(aardvark_records):
def test_aardvark_transform_returns_timdex_record(aardvark_records):
transformer = MITAardvark("cool-repo", aardvark_records)
assert next(transformer) == timdex.TimdexRecord(
source="A Cool Repository",
Expand All @@ -24,16 +24,91 @@ def test_jsontransformer_transform_returns_timdex_record(aardvark_records):
)


def test_aardvark_get_optional_fields_non_field_method_values_success(
aardvark_record_all_fields,
):
transformer = MITAardvark("cool-repo", aardvark_record_all_fields)
record = next(transformer)
assert record.format == "Shapefile"
assert record.languages == ["eng"]
assert record.summary == ["A description"]


def test_aardvark_get_main_titles_success(aardvark_record_all_fields):
assert MITAardvark.get_main_titles(aardvark_record_all_fields) == ["Test title 1"]
assert MITAardvark.get_main_titles(next(aardvark_record_all_fields)) == [
"Test title 1"
]


def test_aardvark_get_source_record_id_success(aardvark_record_all_fields):
assert MITAardvark.get_source_record_id(aardvark_record_all_fields) == "123"
assert MITAardvark.get_source_record_id(next(aardvark_record_all_fields)) == "123"


def test_aardvark_get_alternate_titles_success(aardvark_record_all_fields):
assert MITAardvark.get_alternate_titles(next(aardvark_record_all_fields)) == [
timdex.AlternateTitle(value="Alternate title")
]


def test_aardvark_get_contributors_success(aardvark_record_all_fields):
assert MITAardvark.get_contributors(next(aardvark_record_all_fields)) == [
timdex.Contributor(
value="Smith, Jane",
kind="Creator",
),
timdex.Contributor(
value="Smith, John",
kind="Creator",
),
]


def test_aardvark_get_notes_success(aardvark_record_all_fields):
assert MITAardvark.get_notes(next(aardvark_record_all_fields)) == [
timdex.Note(
value=["Danger: This text will be displayed in a red box"],
kind="Display note",
),
timdex.Note(
value=["Info: This text will be displayed in a blue box"],
kind="Display note",
),
timdex.Note(
value=["Tip: This text will be displayed in a green box"],
kind="Display note",
),
timdex.Note(
value=["Warning: This text will be displayed in a yellow box"],
kind="Display note",
),
timdex.Note(
value=[
"This is text without a tag and it will be assigned default 'note' style"
],
kind="Display note",
),
]


def test_aardvark_get_publication_information_success(aardvark_record_all_fields):
assert MITAardvark.get_publication_information(
next(aardvark_record_all_fields)
) == ["ML InfoMap (Firm)", "MIT"]


def test_aardvark_get_rights_success(aardvark_record_all_fields):
assert MITAardvark.get_rights(next(aardvark_record_all_fields)) == [
timdex.Rights(description="Access note", kind="Access"),
timdex.Rights(uri="http://license.license"),
timdex.Rights(description="Some person has the rights"),
timdex.Rights(
description="The person with the rights. Another person with the rights"
),
]


def test_aardvark_get_subjects_success(aardvark_record_all_fields):
assert MITAardvark.get_subjects(aardvark_record_all_fields) == [
assert MITAardvark.get_subjects(next(aardvark_record_all_fields)) == [
timdex.Subject(value=["Country"], kind="DCAT Keyword"),
timdex.Subject(value=["Political boundaries"], kind="DCAT Theme"),
timdex.Subject(value=["Geography"], kind="Dublin Core Subject"),
Expand Down

0 comments on commit dce0e82

Please sign in to comment.