Skip to content

Commit 9c4fa89

Browse files
committed
better test for results that have been submitted when tranfer results is running already
1 parent 4c337c8 commit 9c4fa89

File tree

3 files changed

+320
-7
lines changed

3 files changed

+320
-7
lines changed

mapswipe_workers/tests/integration/fixtures/tile_map_service_grid/results/build_area_additional_results.json renamed to mapswipe_workers/tests/integration/fixtures/tile_map_service_grid/results/build_area_additional_results_different_group.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,4 @@
258258
"startTime" : "2020-02-03T15:36:29.286Z",
259259
"timestamp" : "2020-02-03T15:39:39.332Z"
260260
}
261-
}
261+
}
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
{
2+
"endTime" : "2020-02-03T15:39:39.332Z",
3+
"results" : {
4+
"18-156540-142783" : 1,
5+
"18-156540-142784" : 1,
6+
"18-156540-142785" : 1,
7+
"18-156541-142783" : 1,
8+
"18-156541-142784" : 1,
9+
"18-156541-142785" : 1,
10+
"18-156542-142783" : 1,
11+
"18-156542-142784" : 0,
12+
"18-156542-142785" : 1,
13+
"18-156543-142783" : 1,
14+
"18-156543-142784" : 1,
15+
"18-156543-142785" : 1,
16+
"18-156544-142783" : 0,
17+
"18-156544-142784" : 1,
18+
"18-156544-142785" : 0,
19+
"18-156545-142783" : 1,
20+
"18-156545-142784" : 1,
21+
"18-156545-142785" : 0,
22+
"18-156546-142783" : 0,
23+
"18-156546-142784" : 0,
24+
"18-156546-142785" : 0,
25+
"18-156547-142783" : 0,
26+
"18-156547-142784" : 0,
27+
"18-156547-142785" : 0,
28+
"18-156548-142783" : 1,
29+
"18-156548-142784" : 1,
30+
"18-156548-142785" : 1,
31+
"18-156549-142783" : 1,
32+
"18-156549-142784" : 1,
33+
"18-156549-142785" : 0,
34+
"18-156550-142783" : 1,
35+
"18-156550-142784" : 1,
36+
"18-156550-142785" : 1,
37+
"18-156551-142783" : 1,
38+
"18-156551-142784" : 1,
39+
"18-156551-142785" : 0,
40+
"18-156552-142783" : 1,
41+
"18-156552-142784" : 0,
42+
"18-156552-142785" : 0,
43+
"18-156553-142783" : 1,
44+
"18-156553-142784" : 1,
45+
"18-156553-142785" : 0,
46+
"18-156554-142783" : 1,
47+
"18-156554-142784" : 1,
48+
"18-156554-142785" : 1,
49+
"18-156555-142783" : 1,
50+
"18-156555-142784" : 1,
51+
"18-156555-142785" : 1,
52+
"18-156556-142783" : 1,
53+
"18-156556-142784" : 0,
54+
"18-156556-142785" : 0,
55+
"18-156557-142783" : 1,
56+
"18-156557-142784" : 0,
57+
"18-156557-142785" : 0,
58+
"18-156558-142783" : 1,
59+
"18-156558-142784" : 1,
60+
"18-156558-142785" : 0,
61+
"18-156559-142783" : 1,
62+
"18-156559-142784" : 0,
63+
"18-156559-142785" : 0,
64+
"18-156560-142783" : 1,
65+
"18-156560-142784" : 0,
66+
"18-156560-142785" : 0,
67+
"18-156561-142783" : 0,
68+
"18-156561-142784" : 1,
69+
"18-156561-142785" : 1,
70+
"18-156562-142783" : 1,
71+
"18-156562-142784" : 1,
72+
"18-156562-142785" : 1,
73+
"18-156563-142783" : 0,
74+
"18-156563-142784" : 0,
75+
"18-156563-142785" : 0,
76+
"18-156564-142783" : 0,
77+
"18-156564-142784" : 0,
78+
"18-156564-142785" : 0,
79+
"18-156565-142783" : 0,
80+
"18-156565-142784" : 0,
81+
"18-156565-142785" : 0,
82+
"18-156566-142783" : 1,
83+
"18-156566-142784" : 1,
84+
"18-156566-142785" : 0,
85+
"18-156567-142783" : 1,
86+
"18-156567-142784" : 1,
87+
"18-156567-142785" : 1,
88+
"18-156568-142783" : 0,
89+
"18-156568-142784" : 0,
90+
"18-156568-142785" : 1,
91+
"18-156569-142783" : 1,
92+
"18-156569-142784" : 1,
93+
"18-156569-142785" : 0,
94+
"18-156570-142783" : 1,
95+
"18-156570-142784" : 1,
96+
"18-156570-142785" : 1,
97+
"18-156571-142783" : 1,
98+
"18-156571-142784" : 1,
99+
"18-156571-142785" : 0,
100+
"18-156572-142783" : 1,
101+
"18-156572-142784" : 1,
102+
"18-156572-142785" : 1,
103+
"18-156573-142783" : 0,
104+
"18-156573-142784" : 1,
105+
"18-156573-142785" : 0,
106+
"18-156574-142783" : 1,
107+
"18-156574-142784" : 1,
108+
"18-156574-142785" : 1,
109+
"18-156575-142783" : 0,
110+
"18-156575-142784" : 1,
111+
"18-156575-142785" : 1,
112+
"18-156576-142783" : 0,
113+
"18-156576-142784" : 1,
114+
"18-156576-142785" : 1,
115+
"18-156577-142783" : 0,
116+
"18-156577-142784" : 0,
117+
"18-156577-142785" : 0,
118+
"18-156578-142783" : 0,
119+
"18-156578-142784" : 0,
120+
"18-156578-142785" : 1,
121+
"18-156579-142783" : 0,
122+
"18-156579-142784" : 0,
123+
"18-156579-142785" : 0,
124+
"18-156580-142783" : 1,
125+
"18-156580-142784" : 0,
126+
"18-156580-142785" : 0,
127+
"18-156581-142783" : 0,
128+
"18-156581-142784" : 0,
129+
"18-156581-142785" : 0,
130+
"18-156582-142783" : 0,
131+
"18-156582-142784" : 0,
132+
"18-156582-142785" : 0,
133+
"18-156583-142783" : 0,
134+
"18-156583-142784" : 0,
135+
"18-156583-142785" : 0,
136+
"18-156584-142783" : 0,
137+
"18-156584-142784" : 0,
138+
"18-156584-142785" : 0,
139+
"18-156585-142783" : 0,
140+
"18-156585-142784" : 0,
141+
"18-156585-142785" : 0,
142+
"18-156586-142783" : 0,
143+
"18-156586-142784" : 0,
144+
"18-156586-142785" : 0,
145+
"18-156587-142783" : 0,
146+
"18-156587-142784" : 0,
147+
"18-156587-142785" : 0,
148+
"18-156588-142783" : 0,
149+
"18-156588-142784" : 0,
150+
"18-156588-142785" : 0,
151+
"18-156589-142783" : 0,
152+
"18-156589-142784" : 0,
153+
"18-156589-142785" : 0,
154+
"18-156590-142783" : 0,
155+
"18-156590-142784" : 0,
156+
"18-156590-142785" : 0,
157+
"18-156591-142783" : 0,
158+
"18-156591-142784" : 2,
159+
"18-156591-142785" : 0,
160+
"18-156592-142783" : 0,
161+
"18-156592-142784" : 2,
162+
"18-156592-142785" : 0,
163+
"18-156593-142783" : 2,
164+
"18-156593-142784" : 2,
165+
"18-156593-142785" : 0,
166+
"18-156594-142783" : 1,
167+
"18-156594-142784" : 2,
168+
"18-156594-142785" : 0,
169+
"18-156595-142783" : 0,
170+
"18-156595-142784" : 0,
171+
"18-156595-142785" : 0,
172+
"18-156596-142783" : 1,
173+
"18-156596-142784" : 1,
174+
"18-156596-142785" : 0,
175+
"18-156597-142783" : 1,
176+
"18-156597-142784" : 1,
177+
"18-156597-142785" : 0,
178+
"18-156598-142783" : 1,
179+
"18-156598-142784" : 0,
180+
"18-156598-142785" : 0,
181+
"18-156599-142783" : 1,
182+
"18-156599-142784" : 1,
183+
"18-156599-142785" : 1,
184+
"18-156600-142783" : 1,
185+
"18-156600-142784" : 1,
186+
"18-156600-142785" : 1,
187+
"18-156601-142783" : 1,
188+
"18-156601-142784" : 1,
189+
"18-156601-142785" : 1,
190+
"18-156602-142783" : 1,
191+
"18-156602-142784" : 1,
192+
"18-156602-142785" : 1,
193+
"18-156603-142783" : 1,
194+
"18-156603-142784" : 1,
195+
"18-156603-142785" : 1,
196+
"18-156604-142783" : 1,
197+
"18-156604-142784" : 1,
198+
"18-156604-142785" : 1,
199+
"18-156605-142783" : 1,
200+
"18-156605-142784" : 1,
201+
"18-156605-142785" : 0,
202+
"18-156606-142783" : 0,
203+
"18-156606-142784" : 1,
204+
"18-156606-142785" : 1,
205+
"18-156607-142783" : 1,
206+
"18-156607-142784" : 1,
207+
"18-156607-142785" : 1,
208+
"18-156608-142783" : 0,
209+
"18-156608-142784" : 1,
210+
"18-156608-142785" : 1,
211+
"18-156609-142783" : 1,
212+
"18-156609-142784" : 1,
213+
"18-156609-142785" : 1,
214+
"18-156610-142783" : 1,
215+
"18-156610-142784" : 1,
216+
"18-156610-142785" : 1,
217+
"18-156611-142783" : 1,
218+
"18-156611-142784" : 1,
219+
"18-156611-142785" : 1,
220+
"18-156612-142783" : 0,
221+
"18-156612-142784" : 0,
222+
"18-156612-142785" : 1,
223+
"18-156613-142783" : 1,
224+
"18-156613-142784" : 1,
225+
"18-156613-142785" : 1,
226+
"18-156614-142783" : 1,
227+
"18-156614-142784" : 1,
228+
"18-156614-142785" : 1,
229+
"18-156615-142783" : 0,
230+
"18-156615-142784" : 1,
231+
"18-156615-142785" : 1,
232+
"18-156616-142783" : 0,
233+
"18-156616-142784" : 0,
234+
"18-156616-142785" : 0,
235+
"18-156617-142783" : 1,
236+
"18-156617-142784" : 1,
237+
"18-156617-142785" : 1,
238+
"18-156618-142783" : 1,
239+
"18-156618-142784" : 1,
240+
"18-156618-142785" : 1,
241+
"18-156619-142783" : 0,
242+
"18-156619-142784" : 1,
243+
"18-156619-142785" : 1,
244+
"18-156620-142783" : 1,
245+
"18-156620-142784" : 1,
246+
"18-156620-142785" : 1,
247+
"18-156621-142783" : 1,
248+
"18-156621-142784" : 1,
249+
"18-156621-142785" : 3,
250+
"18-156622-142783" : 0,
251+
"18-156622-142784" : 1,
252+
"18-156622-142785" : 0,
253+
"18-156623-142783" : 0,
254+
"18-156623-142784" : 0,
255+
"18-156623-142785" : 0
256+
},
257+
"startTime" : "2020-02-03T15:36:29.286Z",
258+
"timestamp" : "2020-02-03T15:39:39.332Z"
259+
}

mapswipe_workers/tests/integration/test_transfer_results.py

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_user_not_in_postgres(self):
8686
result = pg_db.retr_query(sql_query)
8787
self.assertIsNotNone(result)
8888

89-
def test_additional_results_are_not_deleted(self):
89+
def test_additional_results_for_different_group_are_not_deleted(self):
9090
"""Test if new results are not deleted when workflow has already started.
9191
9292
Here we check what happens to results that are submitted,
@@ -100,10 +100,13 @@ def test_additional_results_are_not_deleted(self):
100100
results_ref = fb_db.reference(f"v2/results/{self.project_id}")
101101
results = results_ref.get()
102102

103-
# add additional results in Firebase for group with key 'g120'
104-
# These results should not get deleted by the function below
103+
# Add additional results in Firebase for group with key 'g115'.
104+
# This is the same group for which results already exist.
105+
# So here we simulate another user mapping a group
106+
# that has been mapped before already.
107+
# These results should not get deleted by the function below.
105108
test_dir = os.path.dirname(__file__)
106-
fixture_name = "build_area_additional_results.json"
109+
fixture_name = "build_area_additional_results_different_group.json"
107110
file_path = os.path.join(
108111
test_dir, "fixtures", "tile_map_service_grid", "results", fixture_name
109112
)
@@ -129,8 +132,59 @@ def test_additional_results_are_not_deleted(self):
129132
self.assertIsNotNone(result)
130133

131134
# check if new results for the group 'g120' are still in Firebase
132-
ref = fb_db.reference("v2/results/{0}".format(self.project_id))
133-
self.assertDictEqual(ref.get(shallow=True), {"g120": True})
135+
ref = fb_db.reference(
136+
f"v2/results/{self.project_id}/g120/test_build_area/results"
137+
)
138+
self.assertEqual(len(ref.get(shallow=True)), 252)
139+
140+
def test_additional_results_for_same_group_are_not_deleted(self):
141+
"""Test if new results are not deleted when workflow has already started.
142+
143+
Here we check what happens to results that are submitted,
144+
when the transfer of results workflow is already running.
145+
We expect that these new results should remain in Firebase
146+
until the next run of transfer results.
147+
"""
148+
149+
fb_db = auth.firebaseDB()
150+
151+
results_ref = fb_db.reference(f"v2/results/{self.project_id}")
152+
results = results_ref.get()
153+
154+
# Add additional results in Firebase for group with key 'g115'.
155+
# This is the same group for which results already exist.
156+
# So here we simulate another user mapping a group
157+
# that has been mapped before already.
158+
# These results should not get deleted by the function below.
159+
test_dir = os.path.dirname(__file__)
160+
fixture_name = "build_area_additional_results_same_group.json"
161+
file_path = os.path.join(
162+
test_dir, "fixtures", "tile_map_service_grid", "results", fixture_name
163+
)
164+
165+
with open(file_path) as test_file:
166+
new_results = json.load(test_file)
167+
168+
results_ref = fb_db.reference(f"v2/results/{self.project_id}/g115/new_user/")
169+
results_ref.set(new_results)
170+
171+
# run transfer results function
172+
transfer_results_for_project(self.project_id, results)
173+
174+
# Check if results have been transferred
175+
pg_db = auth.postgresDB()
176+
sql_query = (
177+
f"SELECT * "
178+
f"FROM results "
179+
f"WHERE project_id = '{self.project_id}' "
180+
f"AND user_id = '{self.project_id}'"
181+
)
182+
result = pg_db.retr_query(sql_query)
183+
self.assertIsNotNone(result)
184+
185+
# check if new results for the group 'g115' are still in Firebase
186+
ref = fb_db.reference(f"v2/results/{self.project_id}/g115/new_user/results")
187+
self.assertEqual(len(ref.get(shallow=True)), 252)
134188

135189

136190
if __name__ == "__main__":

0 commit comments

Comments
 (0)