1616
1717
1818def set_firebase_test_data (
19- project_type : str , data_type : str , fixture_name : str , identifier : str
19+ project_type : str ,
20+ data_type : str ,
21+ fixture_name : str ,
22+ identifier : str ,
23+ tutorial_id : str = None ,
2024):
2125 test_dir = os .path .dirname (__file__ )
2226 fixture_name = fixture_name + ".json"
2327 file_path = os .path .join (
2428 test_dir , "fixtures" , project_type , data_type , fixture_name
2529 )
26- upload_file_to_firebase (file_path , data_type , identifier )
30+ upload_file_to_firebase (file_path , data_type , identifier , tutorial_id = tutorial_id )
2731
2832
29- def upload_file_to_firebase (file_path : str , data_type : str , identifier : str ):
33+ def upload_file_to_firebase (
34+ file_path : str , data_type : str , identifier : str , tutorial_id : str = None
35+ ):
3036 with open (file_path ) as test_file :
3137 test_data = json .load (test_file )
3238
39+ if tutorial_id :
40+ test_data ["tutorialId" ] = tutorial_id
3341 fb_db = auth .firebaseDB ()
3442 ref = fb_db .reference (f"/v2/{ data_type } /{ identifier } " )
3543 ref .set (test_data )
@@ -85,15 +93,20 @@ def create_test_project(
8593 set_postgres_test_data (project_type , "users" , "user" )
8694 set_firebase_test_data (project_type , "user_groups" , "user_group" , "" )
8795 set_firebase_test_data (project_type , "results" , fixture_name , project_id )
88- set_postgres_test_data (project_type , "mapping_sessions" , fixture_name , columns = [
89- "project_id" ,
90- "group_id" ,
91- "user_id" ,
92- "mapping_session_id" ,
93- "start_time" ,
94- "end_time" ,
95- "items_count" ,
96- ])
96+ set_postgres_test_data (
97+ project_type ,
98+ "mapping_sessions" ,
99+ fixture_name ,
100+ columns = [
101+ "project_id" ,
102+ "group_id" ,
103+ "user_id" ,
104+ "mapping_session_id" ,
105+ "start_time" ,
106+ "end_time" ,
107+ "items_count" ,
108+ ],
109+ )
97110 set_postgres_test_data (project_type , mapping_sessions_results , fixture_name )
98111 if create_user_group_session_data :
99112 set_postgres_test_data (
@@ -108,7 +121,9 @@ def create_test_project(
108121 "created_at" ,
109122 ],
110123 )
111- set_postgres_test_data (project_type , "mapping_sessions_user_groups" , fixture_name )
124+ set_postgres_test_data (
125+ project_type , "mapping_sessions_user_groups" , fixture_name
126+ )
112127
113128 time .sleep (5 ) # Wait for Firebase Functions to complete
114129 return project_id
@@ -131,12 +146,24 @@ def create_test_user(project_type: str, user_id: str = None) -> str:
131146
132147
133148def create_test_project_draft (
134- project_type : str , fixture_name : str = "user" , identifier : str = ""
149+ project_type : str ,
150+ fixture_name : str = "user" ,
151+ identifier : str = "" ,
152+ tutorial_id : str = None ,
135153) -> str :
136154 """
137155 Create test project drafts in Firebase and return project ids.
138156 Project drafts in Firebase are created by project manager using the dashboard.
139157 """
158+ if tutorial_id :
159+ set_firebase_test_data (
160+ project_type ,
161+ "projectDrafts" ,
162+ fixture_name ,
163+ identifier ,
164+ tutorial_id = tutorial_id ,
165+ )
166+ return identifier
140167 if not identifier :
141168 identifier = f"test_{ fixture_name } "
142169 set_firebase_test_data (project_type , "projectDrafts" , fixture_name , identifier )
0 commit comments