@@ -92,36 +92,42 @@ def test_export_project_route(client, tmp_path):
9292
9393def test_import_project_route (client , tmp_path ):
9494 route = "/opengeodeweb_back/import_project"
95- snapshot = {
96- "styles" : {"1" : {"visibility" : True , "opacity" : 1.0 , "color" : [0.2 , 0.6 , 0.9 ]}}
97- }
98-
99- client .application .config ["DATA_FOLDER_PATH" ] = os .path .join (
100- str (tmp_path ), "project_data"
95+ snapshot = {"styles" : {"1" : {"visibility" : True , "opacity" : 1.0 , "color" : [0.2 , 0.6 , 0.9 ]}}}
96+
97+ original_data_folder = client .application .config ["DATA_FOLDER_PATH" ]
98+ client .application .config ["DATA_FOLDER_PATH" ] = os .path .join (str (tmp_path ), "project_data" )
99+ db_path = os .path .join (client .application .config ["DATA_FOLDER_PATH" ], "project.db" )
100+
101+ import sqlite3 , zipfile , json
102+ temp_db = tmp_path / "temp_project.db"
103+ conn = sqlite3 .connect (str (temp_db ))
104+ conn .execute (
105+ "CREATE TABLE datas (id TEXT PRIMARY KEY, geode_object TEXT, viewer_object TEXT, native_file_name TEXT, "
106+ "viewable_file_name TEXT, light_viewable TEXT, input_file TEXT, additional_files TEXT)"
101107 )
102- data_folder = client .application .config ["DATA_FOLDER_PATH" ]
103- pre_existing_db_path = os .path .join (data_folder , "project.db" )
104-
105- tmp_zip = tmp_path / "import_project_test.zip"
106- new_database_bytes = b"new_db_content"
107- with zipfile .ZipFile (tmp_zip , "w" , compression = zipfile .ZIP_DEFLATED ) as zip_file :
108- zip_file .writestr ("snapshot.json" , json .dumps (snapshot ))
109- zip_file .writestr ("project.db" , new_database_bytes )
110-
111- with open (tmp_zip , "rb" ) as file :
112- response = client .post (
113- route ,
114- data = {"file" : (file , "import_project_test.zip" )},
115- content_type = "multipart/form-data" ,
108+ conn .commit (); conn .close ()
109+
110+ z = tmp_path / "import_project_test.zip"
111+ with zipfile .ZipFile (z , "w" , compression = zipfile .ZIP_DEFLATED ) as zipf :
112+ zipf .writestr ("snapshot.json" , json .dumps (snapshot ))
113+ zipf .write (str (temp_db ), "project.db" )
114+
115+ with open (z , "rb" ) as f :
116+ resp = client .post (
117+ route , data = {"file" : (f , "import_project_test.zip" )}, content_type = "multipart/form-data"
116118 )
117119
118- assert response .status_code == 200
119- assert response .json .get ("snapshot" ) == snapshot
120+ assert resp .status_code == 200
121+ assert resp .json .get ("snapshot" ) == snapshot
122+ assert os .path .exists (db_path )
120123
121- assert os .path .exists (pre_existing_db_path )
122- with open (pre_existing_db_path , "rb" ) as file :
123- assert file .read () == new_database_bytes
124+ from opengeodeweb_microservice .database import connection
125+ client .application .config ["DATA_FOLDER_PATH" ] = original_data_folder
126+ test_db_path = os .environ .get ("TEST_DB_PATH" )
127+ if test_db_path :
128+ connection .init_database (test_db_path , create_tables = True )
124129
130+ client .application .config ["DATA_FOLDER_PATH" ] = original_data_folder
125131
126132def test_save_viewable_workflow_from_file (client ):
127133 route = "/opengeodeweb_back/save_viewable_file"
0 commit comments