Skip to content

Commit 4da6ea9

Browse files
committed
Since we now expect a real .qgs file uploaded, upload something that resembles a .qgs file
1 parent 23e9a17 commit 4da6ea9

2 files changed

Lines changed: 25 additions & 18 deletions

File tree

docker-app/qfieldcloud/core/tests/test_qgis_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def test_upload_and_list_file_with_space_in_name(self):
287287
)
288288
self.assertFalse(Project.objects.get(pk=self.project1.pk).has_the_qgis_file)
289289

290-
file_path = testdata_path("file.txt")
290+
file_path = testdata_path("self_contained.qgs")
291291
# Push a file
292292
project_file = "aaa bbb/project qgis 1.2.qgs"
293293
response = self.client.post(
@@ -512,7 +512,7 @@ def test_one_qgis_project_per_project(self):
512512
)
513513
self.assertFalse(Project.objects.get(pk=self.project1.pk).has_the_qgis_file)
514514

515-
file_path = testdata_path("file.txt")
515+
file_path = testdata_path("self_contained.qgs")
516516
qgis_project_file = "foo/bar/file.qgs"
517517
# Push a QGIS project file
518518
response = self.client.post(
@@ -720,7 +720,7 @@ def test_multiple_file_uploads_one_process_job(self):
720720
)
721721
self.assertFalse(Project.objects.get(pk=self.project1.pk).has_the_qgis_file)
722722

723-
file_path = testdata_path("file.txt")
723+
file_path = testdata_path("self_contained.qgs")
724724
qgis_project_file = "foo/bar/file.qgs"
725725

726726
for i in range(10):

docker-app/qfieldcloud/filestorage/tests/test_files_api.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
logging.disable(logging.CRITICAL)
3535

3636

37+
def qgis_contents(seconds: int = 0) -> StringIO:
38+
return StringIO(
39+
f"""
40+
<qgis projectname="" saveDateTime="2026-05-26T00:00:{seconds:02d}" saveUser="suricactus" saveUserFull="Ivan Ivanov" version="3.44.7-Solothurn">
41+
</qgis>
42+
"""
43+
)
44+
45+
3746
class QfcTestCase(QfcFilesTestCaseMixin, APITransactionTestCase):
3847
def setUp(self):
3948
setup_subscription_plans()
@@ -295,20 +304,18 @@ def test_upload_file_by_unauthorized_user_fails(self):
295304
def test_upload_project_files_sets_the_qgis_file_name(self):
296305
self.assertIsNone(self.p1.the_qgis_file_name)
297306

298-
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", StringIO("Hello!"))
307+
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", qgis_contents())
299308
self.p1.refresh_from_db()
300309
self.assertEqual(self.p1.the_qgis_file_name, "project1.qgs")
301310

302311
def test_upload_multiple_project_files_fails(self):
303312
self.assertIsNone(self.p1.the_qgis_file_name)
304313

305-
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", StringIO("Hello!"))
314+
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", qgis_contents())
306315
self.p1.refresh_from_db()
307316
self.assertEqual(self.p1.the_qgis_file_name, "project1.qgs")
308317

309-
response = self._upload_file(
310-
self.u1, self.p1, "project2.qgs", StringIO("Hello!")
311-
)
318+
response = self._upload_file(self.u1, self.p1, "project2.qgs", qgis_contents())
312319
self.p1.refresh_from_db()
313320
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
314321
self.assertEqual(self.p1.project_files.count(), 1)
@@ -320,10 +327,10 @@ def test_upload_admin_restricted_files_by_owner_succeeds(self):
320327
self.p1.save(update_fields=["has_restricted_projectfiles"])
321328

322329
self.assertIsNone(self.p1.the_qgis_file_name)
323-
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", StringIO("Hello1!"))
330+
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", qgis_contents(1))
324331
self.p1.refresh_from_db()
325332
self.assertEqual(self.p1.the_qgis_file_name, "project1.qgs")
326-
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", StringIO("Hello2!"))
333+
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", qgis_contents(2))
327334
self.p1.refresh_from_db()
328335
self.assertEqual(self.p1.the_qgis_file_name, "project1.qgs")
329336

@@ -338,7 +345,7 @@ def test_upload_admin_restricted_files_by_admin_or_manager_succeeds(self):
338345
project=self.p1, collaborator=u2, role=ProjectCollaborator.Roles.ADMIN
339346
)
340347

341-
self.assertFileUploaded(u2, self.p1, "project1.qgs", StringIO("Hello1!"))
348+
self.assertFileUploaded(u2, self.p1, "project1.qgs", qgis_contents(1))
342349
self.p1.refresh_from_db()
343350
self.assertEqual(self.p1.the_qgis_file_name, "project1.qgs")
344351

@@ -348,7 +355,7 @@ def test_upload_admin_restricted_files_by_admin_or_manager_succeeds(self):
348355
project=self.p1, collaborator=u3, role=ProjectCollaborator.Roles.MANAGER
349356
)
350357

351-
self.assertFileUploaded(u3, self.p1, "project1.qgs", StringIO("Hello2!"))
358+
self.assertFileUploaded(u3, self.p1, "project1.qgs", qgis_contents(2))
352359
self.p1.refresh_from_db()
353360
self.assertEqual(self.p1.the_qgis_file_name, "project1.qgs")
354361

@@ -359,7 +366,7 @@ def test_upload_admin_restricted_files_set_to_false_by_editor_succeeds(self):
359366
project=self.p1, collaborator=u2, role=ProjectCollaborator.Roles.EDITOR
360367
)
361368

362-
self.assertFileUploaded(u2, self.p1, "project1.qgs", StringIO("Hello1!"))
369+
self.assertFileUploaded(u2, self.p1, "project1.qgs", qgis_contents())
363370
self.p1.refresh_from_db()
364371
self.assertEqual(self.p1.the_qgis_file_name, "project1.qgs")
365372

@@ -374,7 +381,7 @@ def test_upload_admin_restricted_files_by_non_admin_or_manager_fails(self):
374381
project=self.p1, collaborator=u2, role=ProjectCollaborator.Roles.EDITOR
375382
)
376383

377-
response = self._upload_file(u2, self.p1, "project1.qgs", StringIO("Hello1!"))
384+
response = self._upload_file(u2, self.p1, "project1.qgs", qgis_contents())
378385

379386
self.p1.refresh_from_db()
380387

@@ -386,7 +393,7 @@ def test_upload_file_by_non_collaborator_fails(self):
386393
# create a new independent user that is not a collaborator
387394
u2 = Person.objects.create_user(username="u2", password="abc123")
388395

389-
response = self._upload_file(u2, self.p1, "file.name", StringIO("Hello1!"))
396+
response = self._upload_file(u2, self.p1, "file.name", qgis_contents())
390397

391398
self.p1.refresh_from_db()
392399

@@ -649,7 +656,7 @@ def test_delete_non_existing_file_version_fails(self):
649656

650657
def test_delete_qgs_project_file_sets_the_qgis_file_name_to_none(self):
651658
self.assertIsNone(self.p1.the_qgis_file_name)
652-
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", StringIO("Hello1!"))
659+
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", qgis_contents())
653660

654661
self.p1.refresh_from_db()
655662

@@ -664,15 +671,15 @@ def test_delete_all_file_versions_fails(self):
664671
self.assertIsNone(self.p1.the_qgis_file_name)
665672

666673
# upload the a new `.qgs` file
667-
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", StringIO("Hello1!"))
674+
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", qgis_contents(1))
668675

669676
self.p1.refresh_from_db()
670677

671678
# project file set to the recently uploaded file
672679
self.assertEqual(self.p1.the_qgis_file_name, "project1.qgs")
673680

674681
# upload the another version of the `.qgs` file
675-
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", StringIO("Hello2!"))
682+
self.assertFileUploaded(self.u1, self.p1, "project1.qgs", qgis_contents(2))
676683

677684
self.p1.refresh_from_db()
678685

0 commit comments

Comments
 (0)