|
@@ -7,6 +7,8 @@ from pycs.database.File import File
|
|
|
from pycs.database.Label import Label
|
|
|
from pycs.database.Model import Model
|
|
|
from pycs.database.Project import Project
|
|
|
+from pycs.database.Result import Result
|
|
|
+from pycs.interfaces.MediaFile import MediaFile
|
|
|
|
|
|
from tests.base import BaseTestCase
|
|
|
|
|
@@ -389,3 +391,104 @@ class ProjectListTests(_BaseProjectTests):
|
|
|
|
|
|
for file, entry in zip(files[start:start+length], content):
|
|
|
self.assertDictEqual(entry, file.serialize())
|
|
|
+
|
|
|
+
|
|
|
+ def test_list_project_results(self):
|
|
|
+ project = Project.new(
|
|
|
+ name="test_project",
|
|
|
+ description="Project for a test case",
|
|
|
+ model=self.model,
|
|
|
+ root_folder="project_folder",
|
|
|
+ external_data=False,
|
|
|
+ data_folder="project_folder/data",)
|
|
|
+
|
|
|
+ url = url_for("get_project_results", project_id=42)
|
|
|
+ self.get(url, status_code=404)
|
|
|
+
|
|
|
+ files = []
|
|
|
+ for i in range(1, 4):
|
|
|
+ file_uuid = str(uuid.uuid1())
|
|
|
+ file, is_new = project.add_file(
|
|
|
+ uuid=file_uuid,
|
|
|
+ file_type="image",
|
|
|
+ name=f"name{i}",
|
|
|
+ filename=f"image_{i:03d}",
|
|
|
+ extension=".jpg",
|
|
|
+ size=32*1024,
|
|
|
+ )
|
|
|
+ self.assertTrue(is_new)
|
|
|
+ files.append(file)
|
|
|
+
|
|
|
+ file.create_result(
|
|
|
+ origin="user",
|
|
|
+ result_type="bounding-box",
|
|
|
+ label=None,
|
|
|
+ data=dict(x=0, y=0, w=1, h=1)
|
|
|
+ )
|
|
|
+
|
|
|
+ self.assertEqual(3, File.query.count())
|
|
|
+ self.assertEqual(3, Result.query.count())
|
|
|
+
|
|
|
+
|
|
|
+ url = url_for("get_project_results", project_id=project.id)
|
|
|
+ response = self.get(url)
|
|
|
+
|
|
|
+ self.assertTrue(response.is_json)
|
|
|
+ content = response.json
|
|
|
+
|
|
|
+ self.assertTrue(project.files.count(), len(content))
|
|
|
+
|
|
|
+ media_files = {f.filename: MediaFile(f, None) for f in project.files.all()}
|
|
|
+
|
|
|
+ for entry in content:
|
|
|
+ media_file = media_files[entry["filename"]]
|
|
|
+
|
|
|
+ self.assertDictEqual(media_file.serialize(), entry)
|
|
|
+
|
|
|
+
|
|
|
+class ProjectEditTests(_BaseProjectTests):
|
|
|
+
|
|
|
+ def setupModels(self):
|
|
|
+ super().setupModels()
|
|
|
+ self.project = Project.new(
|
|
|
+ name="test_project",
|
|
|
+ description="Project for a test case",
|
|
|
+ model=self.model,
|
|
|
+ root_folder="project_folder",
|
|
|
+ external_data=False,
|
|
|
+ data_folder="project_folder/data",)
|
|
|
+
|
|
|
+
|
|
|
+ def test_name_edit(self):
|
|
|
+
|
|
|
+ name = "new_name"
|
|
|
+ url = url_for("edit_project_name", project_id=self.project.id)
|
|
|
+ self.post(url, json=dict(name=name))
|
|
|
+
|
|
|
+ self.assertEqual(name, self.project.name)
|
|
|
+
|
|
|
+
|
|
|
+ def test_name_edit_missing_argument(self):
|
|
|
+
|
|
|
+ url = url_for("edit_project_name", project_id=self.project.id)
|
|
|
+ self.post(url, json=dict(), status_code=400)
|
|
|
+
|
|
|
+ self.assertEqual("test_project", self.project.name)
|
|
|
+
|
|
|
+
|
|
|
+ def test_description_edit(self):
|
|
|
+
|
|
|
+ description = "New description for the project"
|
|
|
+ url = url_for("edit_project_description", project_id=self.project.id)
|
|
|
+ self.post(url, json=dict(description=description))
|
|
|
+
|
|
|
+ self.assertEqual(description, self.project.description)
|
|
|
+
|
|
|
+
|
|
|
+ def test_description_edit_missing_argument(self):
|
|
|
+
|
|
|
+ url = url_for("edit_project_description", project_id=self.project.id)
|
|
|
+ self.post(url, json=dict(), status_code=400)
|
|
|
+
|
|
|
+ self.assertEqual("Project for a test case", self.project.description)
|
|
|
+
|