Skip to content

Commit

Permalink
[test][fix] fix output format
Browse files Browse the repository at this point in the history
  • Loading branch information
M3ssman committed Aug 30, 2024
1 parent cce27e7 commit 50bc8c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/digiflow/record/record_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 9 additions & 8 deletions tests/test_record_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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')
Expand Down

0 comments on commit 50bc8c0

Please sign in to comment.