Skip to content

Commit e87b02a

Browse files
authored
Merge pull request #37 from AfricasVoices/fetch-runs-tweaks
Fetch runs tweaks
2 parents d08d488 + 0cffb45 commit e87b02a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

fetch_runs/fetch_runs.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
if len(matching_flows) == 0:
8484
raise KeyError("Requested flow not found on RapidPro (Available flows: {})".format(
85-
",".join(list(map(lambda f: f.name, flows)))))
85+
", ".join(list(map(lambda f: f.name, flows)))))
8686
if len(matching_flows) > 1:
8787
raise KeyError("Non-unique flow name")
8888

@@ -117,17 +117,21 @@
117117
# Sometimes contact uuids which appear in `runs` do not appear in `contact_runs`.
118118
# I have only observed this happen for contacts which were created very recently.
119119
# This test skips the run in this case; it should be included next time this script is executed.
120-
print("Warning: Run found with uuid '{}', but this id is not present in contacts".format(run.contact.uuid))
120+
print(f"Warning: Run found with Rapid Pro Contact UUID '{run.contact.uuid}', "
121+
f"but this id is not present in the downloaded contacts")
121122
continue
122123

123124
contact_urns = contact_runs[run.contact.uuid].urns
124125

125126
if len(contact_urns) == 0:
126-
print("Warning: Ignoring contact with no urn. URNs: {}, UUID: {}".format(contact_urns, run.contact.uuid))
127+
print(f"Warning: Ignoring contact with no urn. URNs: {contact_urns} "
128+
f"(Rapid Pro Contact UUID: {run.contact.uuid})")
127129
continue
128130

129-
# assert len(contact_urns) == 1, "Contact has multiple URNs" TODO: Re-enable once AVF test runs are ignored.
130-
run_dict = {"avf_phone_id": phone_uuids.add_phone(contact_urns[0])}
131+
run_dict = {
132+
"avf_phone_id": phone_uuids.add_phone(contact_urns[0]),
133+
f"run_id - {run.flow.name}": run.id
134+
}
131135

132136
for category, response in run.values.items():
133137
run_dict[category.title() + " (Category) - " + run.flow.name] = response.category
@@ -140,6 +144,9 @@
140144

141145
if run.contact.uuid in test_contacts:
142146
run_dict["test_run"] = True
147+
else:
148+
assert len(contact_urns) == 1, \
149+
f"A non-test contact has multiple URNs (Rapid Pro Contact UUID: {run.contact.uuid})"
143150

144151
if mode == "all":
145152
run_dict["created_on"] = run.created_on.isoformat()

0 commit comments

Comments
 (0)