def test_get_events_reads_expected_file(self, mock_open): store = AuditLogCursorStore(PROFILE_NAME) store.get_events(CURSOR_NAME) user_path = path.join(path.expanduser("~"), ".code42cli") expected_filename = CURSOR_NAME + "_events" expected_path = path.join(user_path, AUDIT_LOG_CHECKPOINT_FOLDER_NAME, PROFILE_NAME, expected_filename) mock_open.assert_called_once_with(expected_path)
def test_get_events_when_checkpoint_not_valid_json_returns_empty_list( self, mocker): mocker.patch("builtins.open", mocker.mock_open(read_data="invalid_json")) store = AuditLogCursorStore(PROFILE_NAME) event_list = store.get_events(CURSOR_NAME) assert event_list == []
def test_get_events_when_profile_does_not_exist_returns_empty_list( self, mocker): store = AuditLogCursorStore(PROFILE_NAME) event_list = store.get_events(CURSOR_NAME) mock_open = mocker.patch(f"{_NAMESPACE}.open") mock_open.side_effect = FileNotFoundError assert event_list == []
def test_get_events_returns_expected_list(self, mock_open_events): store = AuditLogCursorStore(PROFILE_NAME) event_list = store.get_events(CURSOR_NAME) assert event_list == [AUDIT_LOG_EVENT_HASH_1, AUDIT_LOG_EVENT_HASH_2]