Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Konboi committed Aug 24, 2021
1 parent 2009ff1 commit 3ed2c55
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from unittest.mock import MagicMock

from nose_launchable.case_event import CaseEvent
from nose_launchable.client import LaunchableClientFactory, LaunchableClient
from nose_launchable.client import LaunchableClientFactory, LaunchableClient, TestSessionContext
from nose_launchable.version import __version__


Expand Down Expand Up @@ -55,13 +55,15 @@ def test_start(self):
'Authorization': 'Bearer token'
}

mock_requests.post.assert_called_once_with(expected_url, headers=expected_headers)
mock_requests.post.assert_called_once_with(
expected_url, headers=expected_headers)
mock_response.raise_for_status.assert_called_once_with()
mock_response.json.assert_called_once_with()

self.assertEqual("test_build_number", client.build_number)
self.assertEqual("test_build_number",
client.build_number)
self.assertEqual(
"builds/test_build_number/test_sessions/1", client.test_session_id)
"builds/test_build_number/test_sessions/1", client.test_session_context.get_build_path())

def test_subset_success_with_target(self):
mock_output = MagicMock(name="output")
Expand All @@ -77,12 +79,13 @@ def test_subset_success_with_target(self):

client = LaunchableClient(
"base_url", "org_name", "wp_name", "token", mock_requests, mock_subprocess)
client.test_session_id = "builds/test_subset_success_with_target/1"
client.test_session_context = TestSessionContext(
build_number="test_subset_success_with_target", test_session_id=1)

got = client.subset(["tests/test1.py", "tests/test2.py"], None, "10")

expected_command = ['launchable', 'subset', '--session',
'builds/test_subset_success_with_target/1', '--target', '10%', 'file']
'builds/test_subset_success_with_target/test_sessions/1', '--target', '10%', 'file']
expected_input = 'tests/test1.py\ntests/test2.py'

mock_subprocess.run.assert_called_once_with(
Expand All @@ -103,7 +106,8 @@ def test_subset_success_with_options(self):

client = LaunchableClient(
"base_url", "org_name", "wp_name", "token", mock_requests, mock_subprocess)
client.test_session_id = "builds/test_subset_success_with_options/test_sessions/1"
client.test_session_context = TestSessionContext(
build_number="test_subset_success_with_options", test_session_id=1)

got = client.subset(
["tests/test1.py", "tests/test2.py"], '--target 10%', None)
Expand All @@ -128,8 +132,10 @@ def test_subset_failure(self):

mock_requests = MagicMock(name="requests")

client = LaunchableClient("base_url", "org_name", "wp_name", "token", mock_requests, mock_subprocess)
client.test_session_id = 1
client = LaunchableClient(
"base_url", "org_name", "wp_name", "token", mock_requests, mock_subprocess)
client.test_session_context = TestSessionContext(
build_number="test", test_session_id=1)

with self.assertRaises(RuntimeError):
client.subset(["tests/test1.py", "tests/test2.py"], None, "10")
Expand All @@ -155,7 +161,8 @@ def test_upload_events(self):
]

client.build_number = 1
client.test_session_id = 2
client.test_session_context = TestSessionContext(
build_number=1, test_session_id=2)

client.upload_events(events)

Expand Down Expand Up @@ -200,9 +207,10 @@ def test_finish(self):
mock_requests = MagicMock(name="requests")
mock_requests.patch.return_value = mock_response

client = LaunchableClient("base_url", "org_name", "wp_name", "token", mock_requests, MagicMock(name="subprecess"))
client.build_number = "test_build_number"
client.test_session_id = "1"
client = LaunchableClient("base_url", "org_name", "wp_name",
"token", mock_requests, MagicMock(name="subprecess"))
client.test_session_context = TestSessionContext(
build_number="test_build_number", test_session_id=1)

client.finish()

Expand Down

0 comments on commit 3ed2c55

Please sign in to comment.