33
44import set_up
55import tear_down
6+ from base import BaseTestCase
67
78from mapswipe_workers import auth
89from mapswipe_workers .config import FIREBASE_DB
910from mapswipe_workers .definitions import CustomError
1011from mapswipe_workers .firebase_to_postgres import delete_project
1112
1213
13- class TestDeleteProject (unittest . TestCase ):
14+ class TestDeleteProject (BaseTestCase ):
1415 def setUp (self ):
16+ super ().setUp ()
17+ project_type = "tile_map_service_grid"
18+ fixture_name = "build_area"
1519 self .project_id = set_up .create_test_project (
16- "tile_map_service_grid" , "build_area" , results = True
20+ project_type , fixture_name , results = True
1721 )
1822
1923 def tearDown (self ):
@@ -25,12 +29,7 @@ def tearDown(self):
2529 FIREBASE_DB == "ci-mapswipe" ,
2630 "Test is unreliable when running in Github Actions" ,
2731 )
28- def test_deletion (self ):
29- """Test if tasks, groups, project and results are deleted."""
30- delete_project .delete_project ([self .project_id ])
31-
32- time .sleep (1 ) # Wait for Firebase Functions to complete
33-
32+ def verify_firebase_empty (self ):
3433 fb_db = auth .firebaseDB ()
3534 ref = fb_db .reference (f"v2/results/{ self .project_id } " )
3635 self .assertIsNone (ref .get ())
@@ -43,29 +42,7 @@ def test_deletion(self):
4342 ref = fb_db .reference (f"v2/projects/{ self .project_id } " )
4443 self .assertIsNone (ref .get ())
4544
46- pg_db = auth .postgresDB ()
47- sql_query = f"SELECT * FROM tasks WHERE project_id = '{ self .project_id } '"
48- result = pg_db .retr_query (sql_query )
49-
50- self .assertEqual (result , [])
51- sql_query = f"SELECT * FROM groups WHERE project_id = '{ self .project_id } '"
52- result = pg_db .retr_query (sql_query )
53- self .assertEqual (result , [])
54- sql_query = f"SELECT * FROM projects WHERE project_id = '{ self .project_id } '"
55- result = pg_db .retr_query (sql_query )
56- self .assertEqual (result , [])
57- sql_query = "SELECT * FROM results WHERE project_id = '{}'" .format (
58- self .project_id
59- )
60- result = pg_db .retr_query (sql_query )
61- self .assertEqual (result , [])
62-
63- def test_project_id_not_exists (self ):
64- """Test for project id which does not exists."""
65- delete_project .delete_project (["tuna" ])
66-
67- time .sleep (5 ) # Wait for Firebase Functions to complete
68-
45+ def verify_firebase_not_empty (self ):
6946 fb_db = auth .firebaseDB ()
7047 ref = fb_db .reference ("v2/results" )
7148 self .assertIsNotNone (ref .get (shallow = True ))
@@ -78,51 +55,79 @@ def test_project_id_not_exists(self):
7855 ref = fb_db .reference ("v2/projects" )
7956 self .assertIsNotNone (ref .get (shallow = True ))
8057
58+ def verify_postgres_empty (self ):
8159 pg_db = auth .postgresDB ()
8260 sql_query = f"SELECT * FROM tasks WHERE project_id = '{ self .project_id } '"
8361 result = pg_db .retr_query (sql_query )
84- self .assertNotEqual (result , [])
62+ self .assertListEqual (result , [])
8563 sql_query = f"SELECT * FROM groups WHERE project_id = '{ self .project_id } '"
8664 result = pg_db .retr_query (sql_query )
87- self .assertNotEqual (result , [])
65+ self .assertListEqual (result , [])
8866 sql_query = f"SELECT * FROM projects WHERE project_id = '{ self .project_id } '"
8967 result = pg_db .retr_query (sql_query )
90- self .assertNotEqual (result , [])
91- sql_query = f"SELECT * FROM results WHERE project_id = '{ self .project_id } '"
68+ self .assertListEqual (result , [])
69+ sql_query = (
70+ f"SELECT * FROM mapping_sessions WHERE project_id = '{ self .project_id } '"
71+ )
9272 result = pg_db .retr_query (sql_query )
93- self .assertNotEqual (result , [])
94-
95- def test_project_id_equals_none (self ):
96- """Test for project id which does not exists."""
97- delete_project .delete_project ([None ])
98-
99- time .sleep (5 ) # Wait for Firebase Functions to complete
100-
101- fb_db = auth .firebaseDB ()
102- ref = fb_db .reference ("v2/results" )
103- self .assertIsNotNone (ref .get (shallow = True ))
104- ref = fb_db .reference ("v2/tasks" )
105- self .assertIsNotNone (ref .get (shallow = True ))
106- ref = fb_db .reference ("v2/groups" )
107- self .assertIsNotNone (ref .get (shallow = True ))
108- ref = fb_db .reference ("v2/groupsUsers" )
109- self .assertIsNotNone (ref .get (shallow = True ))
110- ref = fb_db .reference ("v2/projects" )
111- self .assertIsNotNone (ref .get (shallow = True ))
73+ self .assertListEqual (result , [])
74+ sql_query = f"""
75+ SELECT msr.*
76+ FROM mapping_sessions_results msr
77+ JOIN mapping_sessions ms USING (mapping_session_id)
78+ WHERE ms.project_id = '{ self .project_id } '
79+ """
80+ result = pg_db .retr_query (sql_query )
81+ self .assertListEqual (result , [])
11282
83+ def verify_postgres_not_empty (self ):
11384 pg_db = auth .postgresDB ()
11485 sql_query = f"SELECT * FROM tasks WHERE project_id = '{ self .project_id } '"
11586 result = pg_db .retr_query (sql_query )
116- self .assertNotEqual ( result , [] )
87+ self .assertGreater ( len ( result ), 0 )
11788 sql_query = f"SELECT * FROM groups WHERE project_id = '{ self .project_id } '"
11889 result = pg_db .retr_query (sql_query )
119- self .assertNotEqual ( result , [] )
90+ self .assertGreater ( len ( result ), 0 )
12091 sql_query = f"SELECT * FROM projects WHERE project_id = '{ self .project_id } '"
12192 result = pg_db .retr_query (sql_query )
122- self .assertNotEqual (result , [])
123- sql_query = f"SELECT * FROM results WHERE project_id = '{ self .project_id } '"
93+ self .assertGreater (len (result ), 0 )
94+ sql_query = (
95+ f"SELECT * FROM mapping_sessions WHERE project_id = '{ self .project_id } '"
96+ )
97+ result = pg_db .retr_query (sql_query )
98+ self .assertGreater (len (result ), 0 )
99+ sql_query = f"""
100+ SELECT msr.*
101+ FROM mapping_sessions_results msr
102+ JOIN mapping_sessions ms USING (mapping_session_id)
103+ WHERE ms.project_id = '{ self .project_id } '
104+ """
124105 result = pg_db .retr_query (sql_query )
125- self .assertNotEqual (result , [])
106+ self .assertGreater (len (result ), 0 )
107+
108+ def test_deletion (self ):
109+ """Test if tasks, groups, project and results are deleted."""
110+ delete_project .delete_project ([self .project_id ])
111+ time .sleep (1 ) # Wait for Firebase Functions to complete
112+
113+ self .verify_firebase_empty ()
114+ self .verify_postgres_empty ()
115+
116+ def test_project_id_not_exists (self ):
117+ """Test for project id which does not exists."""
118+ delete_project .delete_project (["tuna" ])
119+ time .sleep (5 ) # Wait for Firebase Functions to complete
120+
121+ self .verify_firebase_not_empty ()
122+ self .verify_postgres_not_empty ()
123+
124+ def test_project_id_equals_none (self ):
125+ """Test for project id which does not exists."""
126+ delete_project .delete_project ([None ])
127+ time .sleep (5 ) # Wait for Firebase Functions to complete
128+
129+ self .verify_firebase_not_empty ()
130+ self .verify_postgres_not_empty ()
126131
127132 def test_project_id_invalid (self ):
128133 """Test for project id which does not exists."""
0 commit comments