diff --git a/mapswipe_workers/mapswipe_workers/project_types/project.py b/mapswipe_workers/mapswipe_workers/project_types/project.py index 4f20ac5e0..efc43ce03 100644 --- a/mapswipe_workers/mapswipe_workers/project_types/project.py +++ b/mapswipe_workers/mapswipe_workers/project_types/project.py @@ -566,6 +566,7 @@ def delete_draft_from_firebase(self): @staticmethod def delete_mapping_session_results(project_id): p_con = auth.postgresDB() + # User data sql_query = """ DELETE FROM mapping_sessions_results msr USING mapping_sessions ms @@ -573,6 +574,14 @@ def delete_mapping_session_results(project_id): AND ms.project_id = %(project_id)s; """ p_con.query(sql_query, {"project_id": project_id}) + # User Group data + sql_query = """ + DELETE FROM mapping_sessions_user_groups msug + USING mapping_sessions ms + WHERE ms.mapping_session_id = msug.mapping_session_id + AND ms.project_id = %(project_id)s; + """ + p_con.query(sql_query, {"project_id": project_id}) @classmethod def delete_from_postgres(cls, project_id): diff --git a/mapswipe_workers/tests/integration/fixtures/tile_map_service_grid/mapping_sessions_user_groups/build_area.csv b/mapswipe_workers/tests/integration/fixtures/tile_map_service_grid/mapping_sessions_user_groups/build_area.csv new file mode 100644 index 000000000..6a9f64702 --- /dev/null +++ b/mapswipe_workers/tests/integration/fixtures/tile_map_service_grid/mapping_sessions_user_groups/build_area.csv @@ -0,0 +1 @@ +123 ug100123 diff --git a/mapswipe_workers/tests/integration/fixtures/tile_map_service_grid/user_groups/build_area.csv b/mapswipe_workers/tests/integration/fixtures/tile_map_service_grid/user_groups/build_area.csv new file mode 100644 index 000000000..3cd8963c9 --- /dev/null +++ b/mapswipe_workers/tests/integration/fixtures/tile_map_service_grid/user_groups/build_area.csv @@ -0,0 +1 @@ +ug1001 CustomUserGroup Description false 2020-02-03 15:39:39.332 NULL NULL NULL diff --git a/mapswipe_workers/tests/integration/fixtures/tile_map_service_grid/userGroups/user_group.json b/mapswipe_workers/tests/integration/fixtures/tile_map_service_grid/user_groups/user_group.json similarity index 100% rename from mapswipe_workers/tests/integration/fixtures/tile_map_service_grid/userGroups/user_group.json rename to mapswipe_workers/tests/integration/fixtures/tile_map_service_grid/user_groups/user_group.json diff --git a/mapswipe_workers/tests/integration/set_up.py b/mapswipe_workers/tests/integration/set_up.py index 72296e4c6..e6dc05fd8 100644 --- a/mapswipe_workers/tests/integration/set_up.py +++ b/mapswipe_workers/tests/integration/set_up.py @@ -55,6 +55,7 @@ def create_test_project( project_type: str, fixture_name: str, results: bool = False, + create_user_group_session_data: bool = False, mapping_sessions_results: str = "mapping_sessions_results", ) -> str: """Create a test data in Firebase and Posgres.""" @@ -82,10 +83,13 @@ def create_test_project( if results: set_firebase_test_data(project_type, "users", "user", project_id) set_postgres_test_data(project_type, "users", "user") - set_firebase_test_data(project_type, "userGroups", "user_group", "") + set_firebase_test_data(project_type, "user_groups", "user_group", "") set_firebase_test_data(project_type, "results", fixture_name, project_id) set_postgres_test_data(project_type, "mapping_sessions", fixture_name) set_postgres_test_data(project_type, mapping_sessions_results, fixture_name) + if create_user_group_session_data: + set_postgres_test_data(project_type, "user_groups", fixture_name) + set_postgres_test_data(project_type, "mapping_sessions_user_groups", fixture_name) time.sleep(5) # Wait for Firebase Functions to complete return project_id diff --git a/mapswipe_workers/tests/integration/test_delete_project.py b/mapswipe_workers/tests/integration/test_delete_project.py index 3739d29cd..89854cf8d 100644 --- a/mapswipe_workers/tests/integration/test_delete_project.py +++ b/mapswipe_workers/tests/integration/test_delete_project.py @@ -14,7 +14,7 @@ def setUp(self): project_type = "tile_map_service_grid" fixture_name = "build_area" self.project_id = set_up.create_test_project( - project_type, fixture_name, results=True + project_type, fixture_name, results=True, create_user_group_session_data=True, ) def tearDown(self): diff --git a/mapswipe_workers/tests/integration/test_transfer_results.py b/mapswipe_workers/tests/integration/test_transfer_results.py index 7d10666c2..649a02dd2 100644 --- a/mapswipe_workers/tests/integration/test_transfer_results.py +++ b/mapswipe_workers/tests/integration/test_transfer_results.py @@ -22,7 +22,7 @@ def setUp(self): ) # add some results in firebase set_up.set_firebase_test_data(project_type, "users", "user", self.project_id) - set_up.set_firebase_test_data(project_type, "userGroups", "user_group", "") + set_up.set_firebase_test_data(project_type, "user_groups", "user_group", "") set_up.set_firebase_test_data( project_type, "results", fixture_name, self.project_id ) diff --git a/mapswipe_workers/tests/integration/test_transfer_results_many_results.py b/mapswipe_workers/tests/integration/test_transfer_results_many_results.py index 5b90a75c0..a0d081a90 100644 --- a/mapswipe_workers/tests/integration/test_transfer_results_many_results.py +++ b/mapswipe_workers/tests/integration/test_transfer_results_many_results.py @@ -14,7 +14,7 @@ def setUp(self): ) # add some results in firebase set_up.set_firebase_test_data(project_type, "users", "user", self.project_id) - set_up.set_firebase_test_data(project_type, "userGroups", "user_group", "") + set_up.set_firebase_test_data(project_type, "user_groups", "user_group", "") set_up.set_firebase_test_data( project_type, "results", fixture_name, self.project_id )