Skip to content

Commit 8d65b8b

Browse files
loudonlunestephenfin
authored andcommitted
tests: Add test for dependency feature
Signed-off-by: Adam Hassick <[email protected]>
1 parent 2d2daff commit 8d65b8b

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

Diff for: tests/test_series.py

+66-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
from git_pw import series
77

88

9+
@mock.patch('git_pw.api.get')
910
@mock.patch('git_pw.api.detail')
1011
@mock.patch('git_pw.api.download')
1112
@mock.patch('git_pw.utils.git_am')
1213
class ApplyTestCase(unittest.TestCase):
13-
def test_apply_without_args(self, mock_git_am, mock_download, mock_detail):
14+
def test_apply_without_args(
15+
self, mock_git_am, mock_download, mock_detail, mock_api_get
16+
):
1417
"""Validate calling with no arguments."""
1518

1619
rsp = {'mbox': 'http://example.com/api/patches/123/mbox/'}
@@ -25,7 +28,9 @@ def test_apply_without_args(self, mock_git_am, mock_download, mock_detail):
2528
mock_download.assert_called_once_with(rsp['mbox'])
2629
mock_git_am.assert_called_once_with(mock_download.return_value, ())
2730

28-
def test_apply_with_args(self, mock_git_am, mock_download, mock_detail):
31+
def test_apply_with_args(
32+
self, mock_git_am, mock_download, mock_detail, mock_api_get
33+
):
2934
"""Validate passthrough of arbitrary arguments to git-am."""
3035

3136
rsp = {'mbox': 'http://example.com/api/patches/123/mbox/'}
@@ -42,6 +47,63 @@ def test_apply_with_args(self, mock_git_am, mock_download, mock_detail):
4247
mock_download.return_value, ('-3',)
4348
)
4449

50+
def test_apply_with_deps_unsupported(
51+
self, mock_git_am, mock_download, mock_detail, mock_api_get
52+
):
53+
"""
54+
Validate that a series is applied when dependencies are
55+
requested and dependencies do not appear in the API.
56+
"""
57+
58+
rsp = {'mbox': 'http://example.com/api/series/123/mbox/'}
59+
mock_detail.return_value = rsp
60+
mock_download.return_value = 'test.patch'
61+
62+
runner = CLIRunner()
63+
result = runner.invoke(series.apply_cmd, ['123', '--deps'])
64+
65+
assert result.exit_code == 0, result
66+
mock_detail.assert_called_once_with('series', 123)
67+
mock_download.assert_called_once_with(rsp['mbox'])
68+
mock_git_am.assert_called_once_with(mock_download.return_value, ())
69+
70+
def test_apply_with_deps(
71+
self, mock_git_am, mock_download, mock_detail, mock_api_get
72+
):
73+
"""Validate that dependencies are applied when flag is given."""
74+
dep_ids = [
75+
'120',
76+
'121',
77+
'122',
78+
]
79+
dependencies = list(
80+
map(lambda x: f"http://example.com/api/series/{x}/", dep_ids)
81+
)
82+
dep_details = list(map(lambda x: {"mbox": f"{x}mbox/"}, dependencies))
83+
mboxes = list(map(lambda x: x["mbox"], dep_details))
84+
mboxes.append('http://example.com/api/series/123/mbox/')
85+
files = list(map(lambda x: f"series_{x}.mbox", [*dep_ids, '123']))
86+
87+
rsp_base = {
88+
'mbox': 'http://example.com/api/series/123/mbox/',
89+
'dependencies': dependencies,
90+
}
91+
92+
mock_detail.return_value = rsp_base
93+
mock_api_get.side_effect = dep_details
94+
mock_download.side_effect = files
95+
96+
runner = CLIRunner()
97+
result = runner.invoke(series.apply_cmd, ['123', '--deps'])
98+
99+
assert result.exit_code == 0, result
100+
mock_detail.assert_called_once_with('series', 123)
101+
mock_api_get.assert_has_calls(
102+
map(lambda x: mock.call(x), dependencies)
103+
)
104+
mock_download.assert_has_calls(map(lambda x: mock.call(x), mboxes))
105+
mock_git_am.assert_has_calls(map(lambda x: mock.call(x, ()), files))
106+
45107

46108
@mock.patch('git_pw.api.detail')
47109
@mock.patch('git_pw.api.download')
@@ -125,6 +187,8 @@ def _get_series(**kwargs):
125187
'received_all': True,
126188
'cover_letter': None,
127189
'patches': [],
190+
'dependencies': [],
191+
'dependents': [],
128192
}
129193

130194
rsp.update(**kwargs)

0 commit comments

Comments
 (0)