Skip to content

Commit 15eb3eb

Browse files
sigieseczalun
authored andcommitted
Bug 1570648 - Split test_get_revisions into individual test cases
Reviewers: zalun Reviewed By: zalun Subscribers: zalun Bug #: 1570648 Differential Revision: https://phabricator.services.mozilla.com/D40408
1 parent 75461ab commit 15eb3eb

2 files changed

Lines changed: 57 additions & 21 deletions

File tree

dev-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ scandir==1.9.0 \
4444
--hash=sha256:04b8adb105f2ed313a7c2ef0f1cf7aff4871aa7a1883fa4d8c44b5551ab052d6 \
4545
--hash=sha256:a5e232a0bf188362fa00123cc0bb842d363a292de7126126df5527b6a369586a \
4646
--hash=sha256:44975e209c4827fc18a3486f257154d34ec6eaec0f90fef0cca1caa482db7064
47+
frozendict==1.2 \
48+
--hash=sha256:774179f22db2ef8a106e9c38d4d1f8503864603db08de2e33be5b778230f6e45

tests/test_conduit.py

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import mock
99
import os
1010
import pytest
11+
from frozendict import frozendict
1112

1213
mozphab = imp.load_source(
1314
"mozphab", os.path.join(os.path.dirname(__file__), os.path.pardir, "moz-phab")
@@ -115,72 +116,105 @@ def test_check(m_open, m_os, m_ping, m_call):
115116
assert not check()
116117

117118

118-
@mock.patch("mozphab.ConduitAPI.call")
119-
def test_get_revisions(m_call):
120-
repo = mozphab.Repository("", "", "dummy")
121-
mozphab.conduit.set_repo(repo)
122-
get_revs = mozphab.conduit.get_revisions
119+
@pytest.fixture
120+
def get_revs():
121+
mozphab.conduit.set_repo(mozphab.Repository("", "", "dummy"))
122+
return mozphab.conduit.get_revisions
123+
123124

124-
# sanity checks
125+
@pytest.fixture
126+
def m_call(request):
127+
request.addfinalizer(mozphab.cache.reset)
128+
with mock.patch("mozphab.ConduitAPI.call") as xmock:
129+
yield xmock
130+
131+
132+
def test_get_revisions_both_ids_and_phids_fails(get_revs, m_call):
125133
with pytest.raises(ValueError):
126134
get_revs(ids=[1], phids=["PHID-1"])
135+
136+
137+
def test_get_revisions_none_ids_fails(get_revs, m_call):
127138
with pytest.raises(ValueError):
128139
get_revs(ids=None)
140+
141+
142+
def test_get_revisions_none_phids_fails(get_revs, m_call):
129143
with pytest.raises(ValueError):
130144
get_revs(phids=None)
131145

132-
m_call.return_value = {"data": [dict(id=1, phid="PHID-1")]}
133146

134-
# differential.revision.search by revision-id
147+
basic_phab_result = frozendict({"data": [dict(id=1, phid="PHID-1")]})
148+
149+
150+
def test_get_revisions_search_by_revid(get_revs, m_call):
151+
"""differential.revision.search by revision-id"""
152+
m_call.return_value = basic_phab_result
153+
135154
assert len(get_revs(ids=[1])) == 1
136155
m_call.assert_called_with(
137156
"differential.revision.search",
138157
dict(constraints=dict(ids=[1]), attachments=dict(reviewers=True)),
139158
)
140159

141-
# differential.revision.search by phid
142-
m_call.reset_mock()
143-
mozphab.cache.reset()
160+
161+
def test_get_revisions_search_by_phid(get_revs, m_call):
162+
"""differential.revision.search by phid"""
163+
m_call.return_value = basic_phab_result
164+
144165
assert len(get_revs(phids=["PHID-1"])) == 1
145166
m_call.assert_called_with(
146167
"differential.revision.search",
147168
dict(constraints=dict(phids=["PHID-1"]), attachments=dict(reviewers=True)),
148169
)
149170

150-
# differential.revision.search by revision-id with duplicates
151-
m_call.reset_mock()
152-
mozphab.cache.reset()
171+
172+
def test_get_revisions_search_by_revid_with_dups(get_revs, m_call):
173+
"""differential.revision.search by revision-id with duplicates"""
174+
m_call.return_value = basic_phab_result
175+
153176
assert len(get_revs(ids=[1, 1])) == 2
154177
m_call.assert_called_with(
155178
"differential.revision.search",
156179
dict(constraints=dict(ids=[1]), attachments=dict(reviewers=True)),
157180
)
158181

159-
# differential.revision.search by phid with duplicates
160-
m_call.reset_mock()
161-
mozphab.cache.reset()
182+
183+
def test_get_revisions_search_by_phid_with_dups(get_revs, m_call):
184+
"""differential.revision.search by phid with duplicates"""
185+
m_call.return_value = basic_phab_result
186+
162187
assert len(get_revs(phids=["PHID-1", "PHID-1"])) == 2
163188
m_call.assert_called_with(
164189
"differential.revision.search",
165190
dict(constraints=dict(phids=["PHID-1"]), attachments=dict(reviewers=True)),
166191
)
167192

168-
# ordering of results must match input
169-
m_call.reset_mock()
170-
mozphab.cache.reset()
171-
m_call.return_value = {
193+
194+
multiple_phab_result = frozendict(
195+
{
172196
"data": [
173197
dict(id=1, phid="PHID-1"),
174198
dict(id=2, phid="PHID-2"),
175199
dict(id=3, phid="PHID-3"),
176200
]
177201
}
202+
)
203+
204+
205+
def test_get_revisions_search_by_revids_ordering(get_revs, m_call):
206+
"""ordering of results must match input when querying by revids"""
207+
m_call.return_value = multiple_phab_result
178208
assert get_revs(ids=[2, 1, 3]) == [
179209
dict(id=2, phid="PHID-2"),
180210
dict(id=1, phid="PHID-1"),
181211
dict(id=3, phid="PHID-3"),
182212
]
183213

214+
215+
def test_get_revisions_search_by_phids_ordering(get_revs, m_call):
216+
"""ordering of results must match input when querying by phids"""
217+
m_call.return_value = multiple_phab_result
184218
assert get_revs(phids=["PHID-2", "PHID-1", "PHID-3"]) == [
185219
dict(id=2, phid="PHID-2"),
186220
dict(id=1, phid="PHID-1"),

0 commit comments

Comments
 (0)