Skip to content

Commit de80e7c

Browse files
committed
Add tests
1 parent 31b5f27 commit de80e7c

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import os
2+
from unittest import mock
3+
4+
import responses # type: ignore
5+
6+
from launchable.utils.http_client import get_base_url
7+
from tests.cli_test_case import CliTestCase
8+
9+
10+
class FlakeDetectionTest(CliTestCase):
11+
@responses.activate
12+
@mock.patch.dict(os.environ, {"LAUNCHABLE_TOKEN": CliTestCase.launchable_token})
13+
def test_flake_detection_success(self):
14+
mock_json_response = {
15+
"testPaths": [
16+
[{"type": "file", "name": "test_flaky_1.py"}],
17+
[{"type": "file", "name": "test_flaky_2.py"}],
18+
]
19+
}
20+
responses.add(
21+
responses.GET,
22+
f"{get_base_url()}/intake/organizations/{self.organization}/workspaces/{self.workspace}/retry/flake-detection",
23+
json=mock_json_response,
24+
status=200,
25+
)
26+
result = self.cli(
27+
"retry",
28+
"flake-detection",
29+
"--session",
30+
self.session,
31+
"--confidence",
32+
"high",
33+
"file",
34+
mix_stderr=False,
35+
)
36+
self.assert_success(result)
37+
self.assertIn("test_flaky_1.py", result.stdout)
38+
self.assertIn("test_flaky_2.py", result.stdout)
39+
40+
@responses.activate
41+
@mock.patch.dict(os.environ, {"LAUNCHABLE_TOKEN": CliTestCase.launchable_token})
42+
def test_flake_detection_no_flakes(self):
43+
mock_json_response = {"testPaths": []}
44+
responses.add(
45+
responses.GET,
46+
f"{get_base_url()}/intake/organizations/{self.organization}/workspaces/{self.workspace}/retry/flake-detection",
47+
json=mock_json_response,
48+
status=200,
49+
)
50+
result = self.cli(
51+
"retry",
52+
"flake-detection",
53+
"--session",
54+
self.session,
55+
"--confidence",
56+
"low",
57+
"file",
58+
mix_stderr=False,
59+
)
60+
self.assert_success(result)
61+
self.assertEqual(result.stdout, "")
62+
63+
@responses.activate
64+
@mock.patch.dict(os.environ, {"LAUNCHABLE_TOKEN": CliTestCase.launchable_token})
65+
def test_flake_detection_api_error(self):
66+
responses.add(
67+
responses.GET,
68+
f"{get_base_url()}/intake/organizations/{self.organization}/workspaces/{self.workspace}/retry/flake-detection",
69+
status=500,
70+
)
71+
result = self.cli(
72+
"retry",
73+
"flake-detection",
74+
"--session",
75+
self.session,
76+
"--confidence",
77+
"medium",
78+
"file",
79+
mix_stderr=True,
80+
)
81+
self.assert_exit_code(result, 0)
82+
self.assertIn("Error", result.output)
83+
self.assertEqual(result.stdout, "")

0 commit comments

Comments
 (0)