Skip to content

Commit af5dbc1

Browse files
committed
Fix tests
We needed to add some expected output for a phabricator command. Along the way, make the error reporting more informative.
1 parent 34cc5a8 commit af5dbc1

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

apis/phabricator.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ def chain_revisions(parent_rev, child_rev):
8484
cmd += " | %s call-conduit --conduit-uri=%s differential.revision.search --""" % (_arc(), self.url)
8585

8686
ret = self.run(cmd, shell=True)
87-
result = json.loads(ret.stdout.decode())
87+
try:
88+
result = json.loads(ret.stdout.decode())
89+
except Exception:
90+
raise Exception("Could not decode response as JSON: %s" % ret.stdout.decode())
8891

8992
if result['error']:
9093
raise Exception("Got an error from phabricator when trying to search for %s" % (child_rev))
@@ -101,7 +104,10 @@ def chain_revisions(parent_rev, child_rev):
101104
cmd = "echo " + quote_echo_string("""{"transactions": [{"type":"parents.add", "value":["%s"]}], "objectIdentifier": "%s"}""" % (child_phid, parent_rev))
102105
cmd += " | %s call-conduit --conduit-uri=%s differential.revision.edit --""" % (_arc(), self.url)
103106
ret = self.run(cmd, shell=True)
104-
result = json.loads(ret.stdout.decode())
107+
try:
108+
result = json.loads(ret.stdout.decode())
109+
except Exception:
110+
raise Exception("Could not decode response as JSON: %s" % ret.stdout.decode())
105111
if result['error']:
106112
raise Exception("Got an error from phabricator when trying chain revisions, parent: %s, child %s %s" % (parent_rev, child_rev, child_phid))
107113

@@ -116,7 +122,10 @@ def associate_bug_id(phab_revision):
116122
cmd = "echo " + quote_echo_string("""{"transactions": [{"type":"bugzilla.bug-id", "value":"%s"}], "objectIdentifier": "%s"}""" % (bug_id, phab_revision))
117123
cmd += " | %s call-conduit --conduit-uri=%s differential.revision.edit --""" % (_arc(), self.url)
118124
ret = self.run(cmd, shell=True)
119-
result = json.loads(ret.stdout.decode())
125+
try:
126+
result = json.loads(ret.stdout.decode())
127+
except Exception:
128+
raise Exception("Could not decode response as JSON: %s" % ret.stdout.decode())
120129
if result['error']:
121130
raise Exception("Got an error from phabricator when trying to set the bugzilla id for %s" % (phab_revision))
122131

@@ -142,7 +151,10 @@ def set_reviewer(self, phab_revision, phab_username):
142151
cmd += " | %s call-conduit --conduit-uri=%s user.search --""" % (_arc(), self.url)
143152

144153
ret = self.run(cmd, shell=True)
145-
result = json.loads(ret.stdout.decode())
154+
try:
155+
result = json.loads(ret.stdout.decode())
156+
except Exception:
157+
raise Exception("Could not decode response as JSON: %s" % ret.stdout.decode())
146158

147159
if result['error']:
148160
raise Exception("Got an error from phabricator when trying to search for %s" % (phab_username))
@@ -158,7 +170,10 @@ def set_reviewer(self, phab_revision, phab_username):
158170
cmd = "echo " + quote_echo_string("""{"transactions": [{"type":"reviewers.set", "value":["%s"]}], "objectIdentifier": "%s"}""" % (phid, phab_revision))
159171
cmd += " | %s call-conduit --conduit-uri=%s differential.revision.edit --""" % (_arc(), self.url)
160172
ret = self.run(cmd, shell=True)
161-
result = json.loads(ret.stdout.decode())
173+
try:
174+
result = json.loads(ret.stdout.decode())
175+
except Exception:
176+
raise Exception("Could not decode response as JSON: %s" % ret.stdout.decode())
162177
if result['error']:
163178
raise Exception("Got an error from phabricator when trying to set reviewers to %s (%s) for %s: %s" % (phab_username, phid, phab_revision, result))
164179

@@ -168,7 +183,10 @@ def abandon(self, phab_revision):
168183
cmd = "echo " + quote_echo_string("""{"transactions": [{"type":"abandon", "value":true}],"objectIdentifier": "%s"}""" % phab_revision)
169184
cmd += " | %s call-conduit --conduit-uri=%s differential.revision.edit --""" % (_arc(), self.url)
170185
ret = self.run(cmd, shell=True)
171-
result = json.loads(ret.stdout.decode())
186+
try:
187+
result = json.loads(ret.stdout.decode())
188+
except Exception:
189+
raise Exception("Could not decode response as JSON: %s" % ret.stdout.decode())
172190
if result['error']:
173191
if "You can not abandon this revision because it has already been closed." in result['errorMessage']:
174192
self.logger.log("Strangely, the phabricator revision %s was already closed when we tried to abandon it. Oh well." % phab_revision, level=LogLevel.Warning)

tests/functionality_utilities.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ def default_phab_submit():
7878
("hg diff --stat", lambda: " accessible/interfaces/ia2/moz.build | 6 +++---\n 1 files changed, 3 insertions(+), 3 deletions(-)\n"),
7979
("arc diff --verbatim", command_callbacks.get('phab_submit', default_phab_submit)),
8080
("arcanist diff --verbatim", command_callbacks.get('phab_submit', default_phab_submit)),
81-
(echo_str("echo {\"constraints\""), lambda: CONDUIT_USERNAME_SEARCH_OUTPUT),
81+
(echo_str("echo {\"constraints\""), lambda: CONDUIT_USERNAME_SEARCH_OUTPUT), # This is also used for differential.revision.search, that's alright
8282
(echo_str("echo {\"transactions\": [{\"type\":\"reviewers.set\""), lambda: CONDUIT_EDIT_OUTPUT),
8383
(echo_str("echo {\"transactions\": [{\"type\":\"abandon\""), command_callbacks.get('abandon', AssertFalse)),
8484
(echo_str("echo {\"transactions\": [{\"type\":\"bugzilla.bug-id\""), lambda: CONDUIT_EDIT_OUTPUT),
85+
(echo_str("echo {\"transactions\": [{\"type\":\"parents.add\""), lambda: CONDUIT_EDIT_OUTPUT),
8586
("git log -1 --oneline", lambda: "0481f1c (HEAD -> issue-115-add-revision-to-log, origin/issue-115-add-revision-to-log) Issue #115 - Add revision of updatebot to log output"),
8687
("git clone https://example.invalid .", lambda: ""),
8788
("git merge-base", lambda: "_current"),
@@ -162,6 +163,8 @@ def TRY_OUTPUT(revision, include_auto_line=True):
162163
-> https://phabricator-dev.allizom.org/D%s
163164
"""
164165

166+
# This is also used for differential.revision.search, that's alright, because it returns a PHID
167+
# even if it's not the right type of PHID.
165168
CONDUIT_USERNAME_SEARCH_OUTPUT = """
166169
{"error":null,"errorMessage":null,"response":{"data":[{"id":154,"type":"USER","phid":"PHID-USER-dd6rge2k2csia46r2wcw","fields":{"username":"tjr","realName":"Tom Ritter","roles":["verified","approved","activated"],"dateCreated":1519415695,"dateModified":1519416233,"policy":{"view":"public","edit":"no-one"}},"attachments":[]}],"maps":[],"query":{"queryKey":null},"cursor":{"limit":100,"after":null,"before":null,"order":null}}}
167170
"""

0 commit comments

Comments
 (0)