6
0
ソースを参照

added test for label removal and fixed a bug about it

Dimitri Korsch 3 年 前
コミット
2dad92dc59
2 ファイル変更45 行追加7 行削除
  1. 4 4
      pycs/frontend/endpoints/labels/RemoveLabel.py
  2. 41 3
      test/test_client.py

+ 4 - 4
pycs/frontend/endpoints/labels/RemoveLabel.py

@@ -19,18 +19,18 @@ class RemoveLabel(View):
         # extract request data
         data = request.get_json(force=True)
 
-        if data.get('remove', False):
-            abort(400)
+        if not data.get('remove', False):
+            abort(400, "\"remove\" command was not found!")
 
         # find project
         project = Project.query.get(project_id)
         if project is None:
-            abort(404)
+            abort(404, f"Project with id {project_id} not found")
 
         # find label
         label = project.label(label_id)
         if label is None:
-            abort(404)
+            abort(404, f"Label with id {label_id} not found")
 
         # start transaction
         with db.session.begin_nested():

+ 41 - 3
test/test_client.py

@@ -289,9 +289,47 @@ class ClientTests(BaseTestCase):
 
             self._post(
                 f"/projects/{project_id}/labels",
-                json=dict(
-                    name=f"Label {i}",
-                )
+                json=dict(name=f"Label {i}")
             )
 
             self.assertEqual(i, Label.query.filter(Label.project_id == project_id).count())
+
+    def test_label_removal(self):
+        self._post(
+            "/projects",
+            json=dict(
+                name="some project",
+                description="project description",
+                model=self.model_id,
+                label=None,
+                external=None,
+            )
+        )
+
+        project = Project.query.first()
+        project_id = project.id
+        self.assertIsNotNone(project)
+
+        self.assertEqual(0, Label.query.filter(Label.project_id == project_id).count())
+
+        for i in range(1, 11):
+
+            self._post(
+                f"/projects/{project_id}/labels",
+                json=dict(name=f"Label {i}")
+            )
+        self.assertEqual(10, Label.query.filter(Label.project_id == project_id).count())
+
+        label = Label.query.get(5)
+        label_id = label.id
+        self.assertIsNotNone(label)
+
+        self._post(
+            f"/projects/{project_id}/labels/{label_id}/remove",
+            json=dict(remove=True)
+        )
+
+        self.assertEqual(9, Label.query.filter(Label.project_id == project_id).count())
+        label = Label.query.get(5)
+        self.assertIsNone(label)
+