|
@@ -1,11 +1,14 @@
|
|
from flask import url_for
|
|
from flask import url_for
|
|
|
|
|
|
|
|
+from pycs.database.Collection import Collection
|
|
|
|
+from pycs.database.File import File
|
|
|
|
+from pycs.database.Label import Label
|
|
from pycs.database.Model import Model
|
|
from pycs.database.Model import Model
|
|
from pycs.database.Project import Project
|
|
from pycs.database.Project import Project
|
|
-from pycs.database.Label import Label
|
|
|
|
|
|
|
|
from tests.base import BaseTestCase
|
|
from tests.base import BaseTestCase
|
|
|
|
|
|
|
|
+
|
|
class _BaseProjectTests(BaseTestCase):
|
|
class _BaseProjectTests(BaseTestCase):
|
|
|
|
|
|
def setupModels(self):
|
|
def setupModels(self):
|
|
@@ -21,13 +24,13 @@ class _BaseProjectTests(BaseTestCase):
|
|
|
|
|
|
self.model = model
|
|
self.model = model
|
|
|
|
|
|
|
|
+
|
|
class ProjectCreationTests(_BaseProjectTests):
|
|
class ProjectCreationTests(_BaseProjectTests):
|
|
|
|
|
|
def setUp(self):
|
|
def setUp(self):
|
|
super().setUp()
|
|
super().setUp()
|
|
self.url = url_for("create_project")
|
|
self.url = url_for("create_project")
|
|
|
|
|
|
-
|
|
|
|
def test_project_creation_without_name(self):
|
|
def test_project_creation_without_name(self):
|
|
self.assertEqual(0, Project.query.count())
|
|
self.assertEqual(0, Project.query.count())
|
|
|
|
|
|
@@ -77,6 +80,7 @@ class ProjectCreationTests(_BaseProjectTests):
|
|
self.assertIsNotNone(project.model)
|
|
self.assertIsNotNone(project.model)
|
|
self.assertIsNone(project.label_provider)
|
|
self.assertIsNone(project.label_provider)
|
|
|
|
|
|
|
|
+
|
|
class ProjectDeletionTests(_BaseProjectTests):
|
|
class ProjectDeletionTests(_BaseProjectTests):
|
|
|
|
|
|
def setupModels(self):
|
|
def setupModels(self):
|
|
@@ -126,3 +130,69 @@ class ProjectDeletionTests(_BaseProjectTests):
|
|
|
|
|
|
self.assertEqual(0, Project.query.count())
|
|
self.assertEqual(0, Project.query.count())
|
|
self.assertEqual(0, Label.query.count())
|
|
self.assertEqual(0, Label.query.count())
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class ProjectListTests(_BaseProjectTests):
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def test_list_projects(self):
|
|
|
|
+ self.assertEqual(0, Project.query.count())
|
|
|
|
+
|
|
|
|
+ for i in range(1, 11):
|
|
|
|
+ Project.new(
|
|
|
|
+ name=f"TestProject{i}",
|
|
|
|
+ description=f"Project for a test case #{i}",
|
|
|
|
+ model=self.model,
|
|
|
|
+ root_folder=f"project_folder{i}",
|
|
|
|
+ external_data=False,
|
|
|
|
+ data_folder=f"project_folder{i}/data",
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ self.assertEqual(10, Project.query.count())
|
|
|
|
+
|
|
|
|
+ response = self.get(url_for("list_projects"))
|
|
|
|
+
|
|
|
|
+ self.assertTrue(response.is_json)
|
|
|
|
+ content = response.json
|
|
|
|
+
|
|
|
|
+ self.assertTrue(10, len(content))
|
|
|
|
+
|
|
|
|
+ for entry in content:
|
|
|
|
+ project = Project.query.get(entry["id"])
|
|
|
|
+ self.assertIsNotNone(project)
|
|
|
|
+ self.assertDictEqual(entry, project.serialize())
|
|
|
|
+
|
|
|
|
+ def test_list_project_collections(self):
|
|
|
|
+ project = Project.new(
|
|
|
|
+ name="TestProject",
|
|
|
|
+ description="Project for a test case #",
|
|
|
|
+ model=self.model,
|
|
|
|
+ root_folder="project_folder",
|
|
|
|
+ external_data=False,
|
|
|
|
+ data_folder="project_folder/data",
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ self.assertEqual(0, Collection.query.count())
|
|
|
|
+ for i in range(1, 11):
|
|
|
|
+ project.create_collection(
|
|
|
|
+ reference=f"collection_{i}",
|
|
|
|
+ name=f"Some collection {i}",
|
|
|
|
+ description=f"A description {i}",
|
|
|
|
+ position=i,
|
|
|
|
+ autoselect=i is 1
|
|
|
|
+ )
|
|
|
|
+ self.assertEqual(10, Collection.query.count())
|
|
|
|
+
|
|
|
|
+ response = self.get(url_for("list_collections",
|
|
|
|
+ project_id=project.id))
|
|
|
|
+
|
|
|
|
+ self.assertTrue(response.is_json)
|
|
|
|
+ content = response.json
|
|
|
|
+
|
|
|
|
+ self.assertTrue(10, len(content))
|
|
|
|
+
|
|
|
|
+ for entry in content:
|
|
|
|
+ collection = Collection.query.get(entry["id"])
|
|
|
|
+ self.assertIsNotNone(collection)
|
|
|
|
+ self.assertDictEqual(entry, collection.serialize())
|