From 50bc8c0babcc27afcb7b5a0926769d542b43b982 Mon Sep 17 00:00:00 2001 From: Uwe Hartwig Date: Fri, 30 Aug 2024 13:39:19 +0200 Subject: [PATCH] [test][fix] fix output format --- src/digiflow/record/record_service.py | 5 ++--- tests/test_record_service.py | 17 +++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/digiflow/record/record_service.py b/src/digiflow/record/record_service.py index a4b76d4..3e66c0f 100644 --- a/src/digiflow/record/record_service.py +++ b/src/digiflow/record/record_service.py @@ -25,8 +25,8 @@ STATETIME_FORMAT = '%Y-%m-%d_%H:%M:%S' -DATA_EXHAUSTED_PREFIX = 'no open records' -DATA_EXHAUSTED_MARK = DATA_EXHAUSTED_PREFIX + ' in {}' +DATA_EXHAUSTED_PREFIX = 'no records ' +DATA_EXHAUSTED_MARK = DATA_EXHAUSTED_PREFIX + '{} in {}' @dataclasses.dataclass @@ -237,7 +237,6 @@ def get_record(self, get_record_state, set_record_state): if status == 404: # probably nothing to do? if DATA_EXHAUSTED_PREFIX in str(result): - self.log(result) raise RecordsExhaustedException(result.decode(encoding='utf-8')) if status != 200: diff --git a/tests/test_record_service.py b/tests/test_record_service.py index eac68d7..f57e93d 100644 --- a/tests/test_record_service.py +++ b/tests/test_record_service.py @@ -128,17 +128,17 @@ def test_record_update_dealing_invalid_data(): assert 'ppn#3345' in record.info -@pytest.mark.parametrize("file_path,result", +@pytest.mark.parametrize("state,file_path,result", [ - ('/data/oai/test.csv', 'no open records in /data/oai/test.csv'), - ('', 'no open records in '), - (None, 'no open records in None') + ('n.a.', '/data/oai/test.csv', 'no records n.a. in /data/oai/test.csv'), + ('n.a.', '', 'no records n.a. in '), + (None, None, 'no records None in None') ]) -def test_mark_exhausted_matching(file_path, result): +def test_mark_exhausted_matching(state, file_path, result): """Check formatting behavior""" # assert - assert df_rs.DATA_EXHAUSTED_MARK.format(file_path) == result + assert df_rs.DATA_EXHAUSTED_MARK.format(state, file_path) == result @unittest.mock.patch('digiflow.requests.get') @@ -151,8 +151,9 @@ def test_exit_on_data_exhausted(mock_request): """ # arrange + record_state = 'ocr_busy' list_label = 'oai-record-test' - srv_rsp = f'{df_rs.DATA_EXHAUSTED_MARK.format(list_label)}'.encode() + srv_rsp = f'{df_rs.DATA_EXHAUSTED_MARK.format(record_state, list_label)}'.encode() client = df_r.Client(list_label, '1.2.3.4', '9999') mock_resp = unittest.mock.Mock() mock_resp.status_code = 404 @@ -165,7 +166,7 @@ def test_exit_on_data_exhausted(mock_request): client.get_record(get_record_state=df_r.UNSET_LABEL, set_record_state='busy') # assert - assert recs_ex.value.args[0] == f'no open records in {list_label}' + assert recs_ex.value.args[0] == f'no records {record_state} in {list_label}' @unittest.mock.patch('digiflow.requests.get')