Ejemplo n.º 1
0
 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 == []
Ejemplo n.º 2
0
 def test_clean_calls_remove_on_each_checkpoint(self, mock_open,
                                                mock_remove, mock_listdir,
                                                mock_isfile):
     mock_listdir.return_value = ["fileone", "filetwo", "filethree"]
     store = AuditLogCursorStore(PROFILE_NAME)
     store.clean()
     assert mock_remove.call_count == 3
Ejemplo n.º 3
0
 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 == []
Ejemplo n.º 4
0
 def test_replace_writes_expected_content(self, mock_open):
     store = AuditLogCursorStore(PROFILE_NAME)
     store.replace("checkpointname", 123)
     user_path = path.join(path.expanduser("~"), ".code42cli")
     path.join(user_path, AUDIT_LOG_CHECKPOINT_FOLDER_NAME, PROFILE_NAME,
               "checkpointname")
     mock_open.return_value.write.assert_called_once_with("123")
Ejemplo n.º 5
0
 def test_get_reads_expected_file(self, mock_open):
     store = AuditLogCursorStore(PROFILE_NAME)
     store.get(CURSOR_NAME)
     user_path = path.join(path.expanduser("~"), ".code42cli")
     expected_path = path.join(user_path, AUDIT_LOG_CHECKPOINT_FOLDER_NAME,
                               PROFILE_NAME, CURSOR_NAME)
     mock_open.assert_called_once_with(expected_path)
Ejemplo n.º 6
0
 def test_delete_calls_remove_on_expected_file(self, mock_open,
                                               mock_remove):
     store = AuditLogCursorStore(PROFILE_NAME)
     store.delete("deleteme")
     user_path = path.join(path.expanduser("~"), ".code42cli")
     expected_path = path.join(user_path, AUDIT_LOG_CHECKPOINT_FOLDER_NAME,
                               PROFILE_NAME, "deleteme")
     mock_remove.assert_called_once_with(expected_path)
Ejemplo n.º 7
0
 def test_get_all_cursors_returns_all_checkpoints(self, mock_listdir,
                                                  mock_isfile):
     mock_listdir.return_value = ["fileone", "filetwo", "filethree"]
     store = AuditLogCursorStore(PROFILE_NAME)
     cursors = store.get_all_cursors()
     assert len(cursors) == 3
     assert cursors[0].name == "fileone"
     assert cursors[1].name == "filetwo"
     assert cursors[2].name == "filethree"
Ejemplo n.º 8
0
 def test_replace_events_writes_to_expected_file(self, mock_open):
     store = AuditLogCursorStore(PROFILE_NAME)
     store.replace_events("checkpointname", ["hash1", "hash2"])
     user_path = path.join(path.expanduser("~"), ".code42cli")
     expected_path = path.join(
         user_path,
         AUDIT_LOG_CHECKPOINT_FOLDER_NAME,
         PROFILE_NAME,
         "checkpointname_events",
     )
     mock_open.assert_called_once_with(expected_path, "w")
Ejemplo n.º 9
0
 def test_replace_events_writes_expected_content(self, mock_open_events):
     store = AuditLogCursorStore(PROFILE_NAME)
     store.replace_events("checkpointname", ["hash1", "hash2"])
     user_path = path.join(path.expanduser("~"), ".code42cli")
     path.join(
         user_path,
         AUDIT_LOG_CHECKPOINT_FOLDER_NAME,
         PROFILE_NAME,
         "checkpointname_events",
     )
     mock_open_events.return_value.write.assert_called_once_with(
         '["hash1", "hash2"]')
Ejemplo n.º 10
0
 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]
Ejemplo n.º 11
0
 def test_delete_when_checkpoint_does_not_exist_raises_cli_error(
         self, mock_open, mock_remove):
     store = AuditLogCursorStore(PROFILE_NAME)
     mock_remove.side_effect = FileNotFoundError
     with pytest.raises(Code42CLIError):
         store.delete("deleteme")
Ejemplo n.º 12
0
 def test_get_when_profile_does_not_exist_returns_none(self, mocker):
     store = AuditLogCursorStore(PROFILE_NAME)
     checkpoint = store.get(CURSOR_NAME)
     mock_open = mocker.patch(f"{_NAMESPACE}.open")
     mock_open.side_effect = FileNotFoundError
     assert checkpoint is None
Ejemplo n.º 13
0
 def test_get_returns_expected_timestamp(self, mock_open):
     store = AuditLogCursorStore(PROFILE_NAME)
     checkpoint = store.get(CURSOR_NAME)
     assert checkpoint == 123456789
Ejemplo n.º 14
0
def _get_audit_log_cursor_store(profile_name):
    return AuditLogCursorStore(profile_name)