def test_stdout_ok(self, data_mock, urljoin_mock, requests_mock): # Configure mocks: data_mock.configure_mock(id=123, resolwe=MagicMock(url="a", auth="b")) urljoin_mock.return_value = "some_url" # If response.ok = True: response = MagicMock(ok=True, **{'iter_content.return_value': [b"abc", b"def"]}) requests_mock.configure_mock(**{'get.return_value': response}) out = Data.stdout(data_mock) self.assertEqual(out, "abcdef") urljoin_mock.assert_called_once_with("a", 'data/123/stdout.txt') requests_mock.get.assert_called_once_with("some_url", stream=True, auth="b") # If response.ok = False: response = MagicMock(ok=False) requests_mock.configure_mock(**{'get.return_value': response}) out = Data.stdout(data_mock) self.assertEqual(response.raise_for_status.call_count, 1)
def test_stdout_ok(self, data_mock, urljoin_mock, resolwe_mock): # Configure mocks: process_mock = MagicMock(type="data:index") data_mock.configure_mock(id=123, status="OK", resolwe=resolwe_mock, process=process_mock) urljoin_mock.return_value = "some_url" resolwe_mock.configure_mock(url="a", auth="b") # If response.ok = True: resolwe_mock.session.get.return_value = MagicMock( ok=True, **{"iter_content.return_value": [b"abc", b"def"]}) out = Data.stdout(data_mock) self.assertEqual(out, "abcdef") urljoin_mock.assert_called_once_with("a", "data/123/stdout.txt") resolwe_mock.session.get.assert_called_once_with("some_url", stream=True, auth="b") # If response.ok = False: response = MagicMock(ok=False) resolwe_mock.session.get.return_value = response out = Data.stdout(data_mock) self.assertEqual(response.raise_for_status.call_count, 1)
def test_stdout_ok(self, data_mock, urljoin_mock, requests_mock): # Configure mocks: data_mock.configure_mock(id=123, resolwe=MagicMock(url="a", auth="b")) urljoin_mock.return_value = "some_url" # If response.ok = True: response = MagicMock(ok=True, **{'iter_content.return_value': [b"abc", b"def"]}) requests_mock.configure_mock(**{'get.return_value': response}) out = Data.stdout(data_mock) self.assertEqual(out, "abcdef") urljoin_mock.assert_called_once_with("a", 'data/123/stdout.txt') requests_mock.get.assert_called_once_with("some_url", stream=True, auth="b") # If response.ok = False: response = MagicMock(ok=False) requests_mock.configure_mock(**{'get.return_value': response}) out = Data.stdout(data_mock) self.assertEqual(response.raise_for_status.call_count, 1)