6
6
from git_pw import series
7
7
8
8
9
+ @mock .patch ('git_pw.api.get' )
9
10
@mock .patch ('git_pw.api.detail' )
10
11
@mock .patch ('git_pw.api.download' )
11
12
@mock .patch ('git_pw.utils.git_am' )
12
13
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
+ ):
14
17
"""Validate calling with no arguments."""
15
18
16
19
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):
25
28
mock_download .assert_called_once_with (rsp ['mbox' ])
26
29
mock_git_am .assert_called_once_with (mock_download .return_value , ())
27
30
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
+ ):
29
34
"""Validate passthrough of arbitrary arguments to git-am."""
30
35
31
36
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):
42
47
mock_download .return_value , ('-3' ,)
43
48
)
44
49
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
+
45
107
46
108
@mock .patch ('git_pw.api.detail' )
47
109
@mock .patch ('git_pw.api.download' )
@@ -125,6 +187,8 @@ def _get_series(**kwargs):
125
187
'received_all' : True ,
126
188
'cover_letter' : None ,
127
189
'patches' : [],
190
+ 'dependencies' : [],
191
+ 'dependents' : [],
128
192
}
129
193
130
194
rsp .update (** kwargs )
0 commit comments