Skip to content

Commit

Permalink
Fix project delete issue
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed Aug 1, 2024
1 parent 9fcd215 commit 6c3a24d
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions mapswipe_workers/mapswipe_workers/project_types/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,22 @@ 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
WHERE ms.mapping_session_id = msr.mapping_session_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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
123 ug100123
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ug1001 CustomUserGroup Description false 2020-02-03 15:39:39.332 NULL NULL NULL
6 changes: 5 additions & 1 deletion mapswipe_workers/tests/integration/set_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mapswipe_workers/tests/integration/test_delete_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 6c3a24d

Please sign in to comment.