Skip to content

Commit

Permalink
HEG import: fix es language code
Browse files Browse the repository at this point in the history
Fixes an error when processing records with language code `es`. As the two digit code for spanish is `sp` in config.py.

Co-Authored-by: Sébastien Délèze <sebastien.deleze@rero.ch>
  • Loading branch information
Sébastien Délèze committed Feb 8, 2021
1 parent 8e61b8f commit 3a14ca3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
9 changes: 7 additions & 2 deletions sonar/heg/serializers/schemas/heg.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ def pre_process_record(self, item, **kwargs):
"""Pre-process record, before dumping."""
# Store language
if item.get('language'):
item['language'] = get_bibliographic_code_from_language(
item['language'])
language = item['language']

# As spanish code is `sp` in config.py
if language == 'es':
language = 'sp'

item['language'] = get_bibliographic_code_from_language(language)
else:
item['language'] = 'eng'

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/heg/cli/test_heg_cli_harvest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def mock_queue_files(*args):
assert 'Files queued successfully' in result.output


def test_import_records(app, script_info, monkeypatch):
def test_import_records(app, script_info, monkeypatch, bucket_location):
"""Test import records."""
# Data file not exist
app.config.update(SONAR_APP_HEG_DATA_DIRECTORY='/non-existing/dir')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ def test_heg_schema(app):
}]
}

# With spanish language
data = {'_id': '111', 'language': 'es'}
assert HEGSchema().dump(data) == {
'documentType': 'coar:c_6501',
'identifiedBy': [{
'type': 'bf:Doi',
'value': '111'
}],
'language': [{
'type': 'bf:Language',
'value': 'spa'
}]
}

# Without language
data = {'_id': '111'}
assert HEGSchema().dump(data) == {
Expand Down

0 comments on commit 3a14ca3

Please # to comment.