Skip to content

Commit 1d174d8

Browse files
Merge pull request #418 from mapswipe/tests
Adresses test fail due to late Firebase Function completion.
2 parents 93be73b + c6056e0 commit 1d174d8

File tree

11 files changed

+40
-70
lines changed

11 files changed

+40
-70
lines changed

mapswipe_workers/.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
repos:
33
- repo: https://github.com/psf/black
4-
rev: stable
4+
rev: 19.10b0
55
hooks:
66
- id: black
77
- repo: https://gitlab.com/pycqa/flake8

mapswipe_workers/mapswipe_workers/mapswipe_workers.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,7 @@ def run_create_tutorials() -> None:
289289

290290
@cli.command("archive")
291291
@click.option(
292-
"--project-id",
293-
"-i",
294-
help=("Archive project with giving project id"),
295-
type=str,
292+
"--project-id", "-i", help=("Archive project with giving project id"), type=str,
296293
)
297294
@click.option(
298295
"--project-ids",
@@ -320,10 +317,7 @@ def run_archive_project(project_id, project_ids):
320317

321318
@cli.command("delete")
322319
@click.option(
323-
"--project-id",
324-
"-i",
325-
help=("Delete project with giving project id"),
326-
type=str,
320+
"--project-id", "-i", help=("Delete project with giving project id"), type=str,
327321
)
328322
@click.option(
329323
"--project-ids",

mapswipe_workers/mapswipe_workers/project_types/base/project.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ def save_project(self):
127127
# Make sure projects get saved in Postgres and Firebase successful
128128
try:
129129
self.save_to_postgres(
130-
project,
131-
groups,
132-
groupsOfTasks,
130+
project, groups, groupsOfTasks,
133131
)
134132
logger.info(
135133
f"{self.projectId}" f" - the project has been saved" f" to postgres"
@@ -161,9 +159,7 @@ def save_project(self):
161159

162160
try:
163161
self.save_to_firebase(
164-
project,
165-
groups,
166-
groupsOfTasks,
162+
project, groups, groupsOfTasks,
167163
)
168164
logger.info(
169165
f"{self.projectId}" f" - the project has been saved" f" to firebase"
@@ -452,10 +448,7 @@ def create_groups_txt_file(self, groups):
452448
"project_type_specifics",
453449
)
454450
w = csv.DictWriter(
455-
groups_txt_file,
456-
fieldnames=fieldnames,
457-
delimiter="\t",
458-
quotechar="'",
451+
groups_txt_file, fieldnames=fieldnames, delimiter="\t", quotechar="'",
459452
)
460453

461454
for groupId, group in groups.items():
@@ -525,10 +518,7 @@ def create_tasks_txt_file(self, groupsOfTasks):
525518
"project_type_specifics",
526519
)
527520
w = csv.DictWriter(
528-
tasks_txt_file,
529-
fieldnames=fieldnames,
530-
delimiter="\t",
531-
quotechar="'",
521+
tasks_txt_file, fieldnames=fieldnames, delimiter="\t", quotechar="'",
532522
)
533523

534524
for groupId, tasks in groupsOfTasks.items():

mapswipe_workers/mapswipe_workers/utils/geojson_functions.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,7 @@ def create_geojson_file_from_dict(final_groups_dict, outfile):
153153

154154
dataSource = driver.CreateDataSource(outfile_temp)
155155
# create layer
156-
layer = dataSource.CreateLayer(
157-
outfile_temp,
158-
srs,
159-
geom_type=ogr.wkbPolygon,
160-
)
156+
layer = dataSource.CreateLayer(outfile_temp, srs, geom_type=ogr.wkbPolygon,)
161157

162158
# create fields
163159
field_id = ogr.FieldDefn("group_id", ogr.OFTInteger)
@@ -246,11 +242,7 @@ def create_geojson_file(geometries, outfile):
246242

247243
dataSource = driver.CreateDataSource(outfile_temp)
248244
# create layer
249-
layer = dataSource.CreateLayer(
250-
outfile_temp,
251-
srs,
252-
geom_type=ogr.wkbPolygon,
253-
)
245+
layer = dataSource.CreateLayer(outfile_temp, srs, geom_type=ogr.wkbPolygon,)
254246

255247
# create fields
256248
field_id = ogr.FieldDefn("id", ogr.OFTInteger)

mapswipe_workers/mapswipe_workers/utils/tile_functions.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ def tile_coords_zoom_and_tileserver_to_url(
9696
# https://www.maptiler.com/google-maps-coordinates-tile-bounds-projection/
9797
tile_y = int(math.pow(2, tile_z) - tile_y) - 1
9898
url = tile_server["url"].format(
99-
key=tile_server["apiKey"],
100-
x=tile_x,
101-
y=tile_y,
102-
z=tile_z,
99+
key=tile_server["apiKey"], x=tile_x, y=tile_y, z=tile_z,
103100
)
104101
elif "{-y}" in tile_server["url"]:
105102
# this uses not the standard TMS tile y coordinate,
@@ -108,18 +105,10 @@ def tile_coords_zoom_and_tileserver_to_url(
108105
# https://www.maptiler.com/google-maps-coordinates-tile-bounds-projection/
109106
tile_y = int(math.pow(2, tile_z) - tile_y) - 1
110107
url = tile_server["url"].replace("{-y}", "{y}")
111-
url = url.format(
112-
key=tile_server["apiKey"],
113-
x=tile_x,
114-
y=tile_y,
115-
z=tile_z,
116-
)
108+
url = url.format(key=tile_server["apiKey"], x=tile_x, y=tile_y, z=tile_z,)
117109
else:
118110
url = tile_server["url"].format(
119-
key=tile_server["apiKey"],
120-
x=tile_x,
121-
y=tile_y,
122-
z=tile_z,
111+
key=tile_server["apiKey"], x=tile_x, y=tile_y, z=tile_z,
123112
)
124113

125114
return url
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# python -m unittest test_create_project.py
1+
python -m unittest test_create_project.py
22
python -m unittest test_archive_project.py
33
python -m unittest test_delete_project.py
44
python -m unittest test_update_user_data.py
55
python -m unittest test_transfer_results.py
6-
python -m unittest test_gdal.py
6+
# python -m unittest test_gdal.py
7+
# python -m unittest test_team_management.py

mapswipe_workers/tests/integration/set_up.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import json
1111
import os
12+
import time
1213

1314
from mapswipe_workers import auth
1415

@@ -60,13 +61,15 @@ def create_test_project(
6061
set_firebase_test_data(project_type, "results", fixture_name, project_id)
6162
set_postgres_test_data(project_type, "results", fixture_name)
6263

64+
time.sleep(5) # Wait for Firebase Functions to complete
6365
return project_id
6466

6567

6668
def create_test_results(project_type: str, fixture_name: str) -> str:
6769
"""Create test results only in Firebase."""
6870
project_id = "test_{0}".format(project_type)
6971
set_firebase_test_data(project_type, "results", fixture_name, project_id)
72+
time.sleep(5) # Wait for Firebase Functions to complete
7073
return project_id
7174

7275

mapswipe_workers/tests/integration/test_delete_project.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import time
21
import unittest
32

43
import set_up
@@ -21,7 +20,6 @@ def tearDown(self):
2120
def test_deletion(self):
2221
"""Test if tasks, groups, project and results are deleted."""
2322
delete_project.delete_project([self.project_id])
24-
time.sleep(3)
2523

2624
fb_db = auth.firebaseDB()
2725
ref = fb_db.reference("v2/results/{0}".format(self.project_id))

mapswipe_workers/tests/integration/test_transfer_results.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ def test_changes_given_project_id(self):
2626

2727
pg_db = auth.postgresDB()
2828
sql_query = (
29-
"SELECT * FROM results WHERE project_id = '{0}' AND user_id = '{0}'".format(
30-
self.project_id
31-
)
29+
f"SELECT * "
30+
f"FROM results "
31+
f"WHERE project_id = '{self.project_id}' "
32+
f"AND user_id = '{self.project_id}'"
3233
)
3334
result = pg_db.retr_query(sql_query)
3435
self.assertIsNotNone(result)
@@ -43,9 +44,10 @@ def test_changes(self):
4344

4445
pg_db = auth.postgresDB()
4546
sql_query = (
46-
"SELECT * FROM results WHERE project_id = '{0}' and user_id = '{0}'".format(
47-
self.project_id
48-
)
47+
f"SELECT * "
48+
f"FROM results "
49+
f"WHERE project_id = '{self.project_id}' "
50+
f"AND user_id = '{self.project_id}'"
4951
)
5052
result = pg_db.retr_query(sql_query)
5153
self.assertIsNotNone(result)
@@ -56,9 +58,9 @@ def test_user_not_in_postgres(self):
5658

5759
# Make sure user and results are not yet in Postgres
5860
sql_query = (
59-
"DELETE FROM results WHERE user_id = '{0}' and project_id = '{0}'".format(
60-
self.project_id
61-
)
61+
f"DELETE FROM results "
62+
f"WHERE user_id = '{self.project_id}' "
63+
f"AND project_id = '{self.project_id}'"
6264
)
6365
pg_db.query(sql_query)
6466
sql_query = "DELETE FROM users WHERE user_id = '{0}'".format(self.project_id)
@@ -71,9 +73,10 @@ def test_user_not_in_postgres(self):
7173
self.assertIsNotNone(result)
7274

7375
sql_query = (
74-
"SELECT * FROM results WHERE project_id = '{0}' AND user_id = '{0}'".format(
75-
self.project_id
76-
)
76+
f"SELECT * "
77+
f"FROM results "
78+
f"WHERE project_id = '{self.project_id}' "
79+
f"AND user_id = '{self.project_id}'"
7780
)
7881
result = pg_db.retr_query(sql_query)
7982
self.assertIsNotNone(result)

mapswipe_workers/tests/integration/test_update_user_data.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import time
21
import unittest
32

43
import set_up
@@ -19,7 +18,6 @@ def tearDown(self):
1918
def test_no_users_in_postgres(self):
2019
"""Test update users when no users are in postgres yet."""
2120
update_data.update_user_data()
22-
time.sleep(2)
2321
pg_db = auth.postgresDB()
2422
sql_query = "SELECT * FROM users WHERE user_id = '{0}'".format(self.user_id)
2523
result = pg_db.retr_query(sql_query)
@@ -28,7 +26,6 @@ def test_no_users_in_postgres(self):
2826
def test_last_updated_users(self):
2927
"""Test update users when some users are in postgres."""
3028
update_data.update_user_data()
31-
time.sleep(2)
3229
user_id = set_up.create_test_user("tile_map_service_grid", "test_user_2")
3330
self.user_ids.append(user_id)
3431
update_data.update_user_data()
@@ -40,7 +37,6 @@ def test_last_updated_users(self):
4037

4138
def test_with_user_ids(self):
4239
update_data.update_user_data([self.user_id])
43-
time.sleep(2)
4440
pg_db = auth.postgresDB()
4541
sql_query = "SELECT * FROM users WHERE user_id = '{0}'".format(self.user_id)
4642
result = pg_db.retr_query(sql_query)

0 commit comments

Comments
 (0)