def test_file_exporter_export(self, mock_task_get, mock_dumps, mock_open, mock_exists): mock_task = mock.Mock() mock_exists.return_value = True mock_task_get.return_value = mock_task mock_task.get_results.return_value = [{ "key": "fake_key", "data": { "raw": "bar_raw", "sla": "baz_sla", "load_duration": "foo_load_duration", "full_duration": "foo_full_duration", } }] mock_dumps.return_value = "fake_results" input_mock = mock.MagicMock(spec=file) mock_open.return_value = input_mock exporter = file_system.FileExporter("file-exporter:///fake_path.json") exporter.export("fake_uuid") mock_open().__enter__().write.assert_called_once_with("fake_results") mock_task_get.assert_called_once_with("fake_uuid") expected_dict = [{ "load_duration": "foo_load_duration", "full_duration": "foo_full_duration", "result": "bar_raw", "key": "fake_key", "sla": "baz_sla" }] mock_dumps.assert_called_once_with(expected_dict, sort_keys=True, indent=4)
def test_file_exporter_export_running_task(self, mock_task_get): mock_task = mock.Mock() mock_task_get.return_value = mock_task mock_task.get_results.return_value = [] exporter = file_system.FileExporter("file-exporter:///fake_path.json") self.assertRaises(exceptions.RallyException, exporter.export, "fake_uuid")
def test_file_exporter_export(self, mock_api, mock_dumps, mock_open, mock_exists): rapi = mock_api.return_value mock_exists.return_value = True rapi.task.get_detailed.return_value = { "results": [{ "key": "fake_key", "data": { "raw": "bar_raw", "sla": "baz_sla", "hooks": "baz_hooks", "load_duration": "foo_load_duration", "full_duration": "foo_full_duration", } }] } mock_dumps.return_value = "fake_results" input_mock = mock.MagicMock(spec=file) mock_open.return_value = input_mock exporter = file_system.FileExporter("file-exporter:///fake_path.json") exporter.export("fake_uuid") mock_open().__enter__().write.assert_called_once_with("fake_results") rapi.task.get_detailed.assert_called_once_with("fake_uuid") expected_dict = [{ "load_duration": "foo_load_duration", "full_duration": "foo_full_duration", "result": "bar_raw", "key": "fake_key", "hooks": "baz_hooks", "sla": "baz_sla" }] mock_dumps.assert_called_once_with(expected_dict, sort_keys=False, indent=4, separators=(",", ": "))
def test_file_exporter_validate(self, connection, raises): print(connection) if raises: self.assertRaises(raises, file_system.FileExporter, connection) else: file_system.FileExporter(connection)
def test_file_exporter_export_running_task(self, mock___task): mock___task.get_detailed.return_value = {"results": []} exporter = file_system.FileExporter("file-exporter:///fake_path.json") self.assertRaises(exceptions.RallyException, exporter.export, "fake_uuid")