2019-07-27 01:10:13 +02:00
|
|
|
|
import csv_metadata_quality.check as check
|
|
|
|
|
|
2019-07-28 16:47:28 +02:00
|
|
|
|
|
2019-07-27 01:10:13 +02:00
|
|
|
|
def test_check_invalid_issn(capsys):
|
|
|
|
|
'''Test checking invalid ISSN.'''
|
|
|
|
|
|
|
|
|
|
value = '2321-2302'
|
|
|
|
|
|
|
|
|
|
check.issn(value)
|
2019-07-28 16:47:28 +02:00
|
|
|
|
|
2019-07-27 01:10:13 +02:00
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
assert captured.out == f'Invalid ISSN: {value}\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_valid_issn():
|
|
|
|
|
'''Test checking valid ISSN.'''
|
|
|
|
|
|
|
|
|
|
value = '0024-9319'
|
|
|
|
|
|
|
|
|
|
result = check.issn(value)
|
|
|
|
|
|
|
|
|
|
assert result == value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_invalid_isbn(capsys):
|
|
|
|
|
'''Test checking invalid ISBN.'''
|
|
|
|
|
|
|
|
|
|
value = '99921-58-10-6'
|
|
|
|
|
|
|
|
|
|
check.isbn(value)
|
|
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
assert captured.out == f'Invalid ISBN: {value}\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_valid_isbn():
|
|
|
|
|
'''Test checking valid ISBN.'''
|
|
|
|
|
|
|
|
|
|
value = '99921-58-10-7'
|
|
|
|
|
|
|
|
|
|
result = check.isbn(value)
|
|
|
|
|
|
|
|
|
|
assert result == value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_invalid_separators(capsys):
|
|
|
|
|
'''Test checking invalid multi-value separators.'''
|
|
|
|
|
|
|
|
|
|
value = 'Alan|Orth'
|
|
|
|
|
|
|
|
|
|
check.separators(value)
|
|
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
assert captured.out == f'Invalid multi-value separator: {value}\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_valid_separators():
|
|
|
|
|
'''Test checking valid multi-value separators.'''
|
|
|
|
|
|
|
|
|
|
value = 'Alan||Orth'
|
|
|
|
|
|
|
|
|
|
result = check.separators(value)
|
|
|
|
|
|
|
|
|
|
assert result == value
|
2019-07-28 15:11:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_missing_date(capsys):
|
|
|
|
|
'''Test checking missing date.'''
|
|
|
|
|
|
|
|
|
|
value = None
|
|
|
|
|
|
|
|
|
|
check.date(value)
|
|
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
assert captured.out == f'Missing date.\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_multiple_dates(capsys):
|
|
|
|
|
'''Test checking multiple dates.'''
|
|
|
|
|
|
|
|
|
|
value = '1990||1991'
|
|
|
|
|
|
|
|
|
|
check.date(value)
|
|
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
assert captured.out == f'Multiple dates not allowed: {value}\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_invalid_date(capsys):
|
|
|
|
|
'''Test checking invalid ISO8601 date.'''
|
|
|
|
|
|
|
|
|
|
value = '1990-0'
|
|
|
|
|
|
|
|
|
|
check.date(value)
|
|
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
assert captured.out == f'Invalid date: {value}\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_valid_date():
|
|
|
|
|
'''Test checking valid ISO8601 date.'''
|
|
|
|
|
|
|
|
|
|
value = '1990'
|
|
|
|
|
|
|
|
|
|
result = check.date(value)
|
|
|
|
|
|
|
|
|
|
assert result == value
|
2019-07-29 16:08:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_suspicious_characters(capsys):
|
|
|
|
|
'''Test checking for suspicious characters.'''
|
|
|
|
|
|
|
|
|
|
value = 'foreˆt'
|
|
|
|
|
|
2019-08-09 00:26:13 +02:00
|
|
|
|
field_name = 'dc.contributor.author'
|
|
|
|
|
|
|
|
|
|
check.suspicious_characters(value, field_name)
|
2019-07-29 16:08:49 +02:00
|
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
2019-08-09 00:26:13 +02:00
|
|
|
|
assert captured.out == f'Suspicious character ({field_name}): ˆt\n'
|
2019-07-29 17:59:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_valid_iso639_2_language():
|
|
|
|
|
'''Test valid ISO 639-2 language.'''
|
|
|
|
|
|
|
|
|
|
value = 'ja'
|
|
|
|
|
|
|
|
|
|
result = check.language(value)
|
|
|
|
|
|
|
|
|
|
assert result == value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_valid_iso639_3_language():
|
|
|
|
|
'''Test invalid ISO 639-3 language.'''
|
|
|
|
|
|
|
|
|
|
value = 'eng'
|
|
|
|
|
|
|
|
|
|
result = check.language(value)
|
|
|
|
|
|
|
|
|
|
assert result == value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_invalid_iso639_2_language(capsys):
|
|
|
|
|
'''Test invalid ISO 639-2 language.'''
|
|
|
|
|
|
|
|
|
|
value = 'jp'
|
|
|
|
|
|
|
|
|
|
check.language(value)
|
|
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
assert captured.out == f'Invalid ISO 639-2 language: {value}\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_invalid_iso639_3_language(capsys):
|
|
|
|
|
'''Test invalid ISO 639-3 language.'''
|
|
|
|
|
|
|
|
|
|
value = 'chi'
|
|
|
|
|
|
|
|
|
|
check.language(value)
|
|
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
assert captured.out == f'Invalid ISO 639-3 language: {value}\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_invalid_language(capsys):
|
|
|
|
|
'''Test invalid language.'''
|
|
|
|
|
|
|
|
|
|
value = 'Span'
|
|
|
|
|
|
|
|
|
|
check.language(value)
|
|
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
assert captured.out == f'Invalid language: {value}\n'
|
2019-07-29 23:30:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_invalid_agrovoc(capsys):
|
|
|
|
|
'''Test invalid AGROVOC subject.'''
|
|
|
|
|
|
|
|
|
|
value = 'FOREST'
|
2019-08-01 22:59:11 +02:00
|
|
|
|
field_name = 'dc.subject'
|
2019-07-29 23:30:31 +02:00
|
|
|
|
|
2019-08-01 22:59:11 +02:00
|
|
|
|
check.agrovoc(value, field_name)
|
2019-07-29 23:30:31 +02:00
|
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
2019-08-01 22:59:11 +02:00
|
|
|
|
assert captured.out == f'Invalid AGROVOC ({field_name}): {value}\n'
|
2019-07-29 23:30:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_valid_agrovoc():
|
|
|
|
|
'''Test valid AGROVOC subject.'''
|
|
|
|
|
|
|
|
|
|
value = 'FORESTS'
|
2019-08-01 22:59:11 +02:00
|
|
|
|
field_name = 'dc.subject'
|
2019-07-29 23:30:31 +02:00
|
|
|
|
|
2019-08-01 22:59:11 +02:00
|
|
|
|
result = check.agrovoc(value, field_name)
|
2019-07-29 23:30:31 +02:00
|
|
|
|
|
|
|
|
|
assert result == value
|
2019-08-10 22:44:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_uncommon_filename_extension(capsys):
|
|
|
|
|
'''Test uncommon filename extension.'''
|
|
|
|
|
|
|
|
|
|
value = 'file.pdf.lck'
|
|
|
|
|
|
2019-08-10 22:45:41 +02:00
|
|
|
|
check.filename_extension(value)
|
2019-08-10 22:44:13 +02:00
|
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
assert captured.out == f'Filename with uncommon extension: {value}\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_common_filename_extension():
|
|
|
|
|
'''Test common filename extension.'''
|
|
|
|
|
|
|
|
|
|
value = 'file.pdf'
|
|
|
|
|
|
|
|
|
|
result = check.filename_extension(value)
|
|
|
|
|
|
|
|
|
|
assert result == value
|