Skip to content

Commit 550df7a

Browse files
committed
fix: working integration test for tutorial creation
1 parent dfb3743 commit 550df7a

File tree

3 files changed

+22
-46
lines changed

3 files changed

+22
-46
lines changed

mapswipe_workers/tests/integration/tear_down.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from mapswipe_workers import auth
99

1010

11-
def delete_test_data(project_id: str) -> None:
11+
def delete_test_data(project_id: str, tutorial_id: str = None) -> None:
1212
"""
1313
Delete test project indluding groups, tasks and results
1414
from Firebase and Postgres
@@ -38,6 +38,12 @@ def delete_test_data(project_id: str) -> None:
3838
ref = fb_db.reference(f"v2/users/{project_id}")
3939
ref.delete()
4040

41+
if tutorial_id is not None:
42+
ref = fb_db.reference(f"v2/projects/{tutorial_id}")
43+
ref.delete()
44+
ref = fb_db.reference(f"v2/tutorialDrafts/{tutorial_id}")
45+
ref.delete()
46+
4147
# Clear out the user-group used in test.
4248
# XXX: Use a firebase simulator for running test.
4349
# For CI/CD, use a real firebase with scope using commit hash,

mapswipe_workers/tests/integration/test_create_tutorial.py

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,65 +10,35 @@
1010
class TestCreateTileClassificationProject(unittest.TestCase):
1111
def setUp(self):
1212
self.tutorial_id = set_up.create_test_tutorial_draft(
13-
"tile_classification",
14-
"tile_classification",
13+
"street",
14+
"street",
1515
"test_tile_classification_tutorial",
1616
)
1717

1818
self.project_id = set_up.create_test_project_draft(
19-
"tile_classification",
20-
"tile_classification",
19+
"street",
20+
"street",
2121
"test_tile_classification_tutorial",
2222
tutorial_id=self.tutorial_id,
2323
)
2424
create_directories()
2525

2626
def tearDown(self):
27-
tear_down.delete_test_data(self.project_id)
27+
tear_down.delete_test_data(self.project_id, self.tutorial_id)
2828

2929
def test_create_tile_classification_project(self):
3030
runner = CliRunner()
31+
runner.invoke(mapswipe_workers.run_create_tutorials, catch_exceptions=False)
3132
runner.invoke(mapswipe_workers.run_create_projects, catch_exceptions=False)
3233

33-
pg_db = auth.postgresDB()
34-
query = "SELECT project_id FROM projects WHERE project_id = %s"
35-
result = pg_db.retr_query(query, [self.project_id])[0][0]
36-
self.assertEqual(result, self.project_id)
37-
38-
query = """
39-
SELECT project_id
40-
FROM projects
41-
WHERE project_id = %s
42-
and project_type_specifics::jsonb ? 'customOptions'
43-
"""
44-
result = pg_db.retr_query(query, [self.project_id])[0][0]
45-
self.assertEqual(result, self.project_id)
46-
47-
query = "SELECT count(*) FROM groups WHERE project_id = %s"
48-
result = pg_db.retr_query(query, [self.project_id])[0][0]
49-
self.assertEqual(result, 20)
50-
51-
query = "SELECT count(*) FROM tasks WHERE project_id = %s"
52-
result = pg_db.retr_query(query, [self.project_id])[0][0]
53-
self.assertEqual(result, 5040)
54-
5534
fb_db = auth.firebaseDB()
5635
ref = fb_db.reference(f"/v2/projects/{self.project_id}")
57-
result = ref.get(shallow=True)
58-
self.assertIsNotNone(result)
36+
result = ref.get()
37+
self.assertEqual(result["tutorialId"], self.tutorial_id)
5938

60-
ref = fb_db.reference(f"/v2/groups/{self.project_id}")
39+
ref = fb_db.reference(f"/v2/projects/{self.tutorial_id}")
6140
result = ref.get(shallow=True)
62-
self.assertEqual(len(result), 20)
63-
64-
# Tile classification projects do not have tasks in Firebase
65-
ref = fb_db.reference(f"/v2/tasks/{self.project_id}")
66-
result = ref.get(shallow=True)
67-
self.assertIsNone(result)
68-
69-
ref = fb_db.reference(f"/v2/projects/{self.project_id}/tutorialId")
70-
result = ref.get(shallow=True)
71-
self.assertEqual(self.tutorial_id, result)
41+
self.assertIsNotNone(result)
7242

7343

7444
if __name__ == "__main__":

mapswipe_workers/tests/unittests/test_tutorial.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import os
22
import unittest
33

4-
from mapswipe_workers.project_types import ClassificationTutorial
4+
from mapswipe_workers.project_types import StreetTutorial
55
from tests.fixtures import FIXTURE_DIR, get_fixture
66

77

88
class TestTutorial(unittest.TestCase):
99
def test_init_tile_classification_project(self):
1010
tutorial_draft = get_fixture(
11-
os.path.join(FIXTURE_DIR, "tutorialDrafts", "tile_classification.json")
11+
os.path.join(FIXTURE_DIR, "tutorialDrafts", "street.json")
1212
)
13-
self.assertIsNotNone(ClassificationTutorial(tutorial_draft=tutorial_draft))
13+
self.assertIsNotNone(StreetTutorial(tutorial_draft=tutorial_draft))
1414

1515
def test_create_tile_classification_tasks(self):
1616
tutorial_draft = get_fixture(
17-
os.path.join(FIXTURE_DIR, "tutorialDrafts", "tile_classification.json")
17+
os.path.join(FIXTURE_DIR, "tutorialDrafts", "street.json")
1818
)
19-
tutorial = ClassificationTutorial(tutorial_draft=tutorial_draft)
19+
tutorial = StreetTutorial(tutorial_draft=tutorial_draft)
2020
tutorial.create_tutorial_groups()
2121
tutorial.create_tutorial_tasks()
2222
self.assertTrue(tutorial.groups)

0 commit comments

Comments
 (0)