Explorar o código

added tests for getting of results

Dimitri Korsch %!s(int64=3) %!d(string=hai) anos
pai
achega
aceec3db97
Modificáronse 1 ficheiros con 51 adicións e 0 borrados
  1. 51 0
      tests/client/result_tests.py

+ 51 - 0
tests/client/result_tests.py

@@ -88,3 +88,54 @@ class ResultCreationTests(_BaseResultTests):
         self.assertIsNone(result.label_id)
 
 
+class ResultGettingTests(_BaseResultTests):
+
+    def test_missing_file(self):
+        url = url_for("get_results", file_id=4242)
+        self.get(url, status_code=404)
+
+    def test_getting_of_results(self):
+
+        n = 5
+
+        self.assertEqual(0, Result.query.count())
+        results = {}
+        for i in range(n):
+            box = dict(x=0, y=0, w=0.9, h=1.0)
+            res = self.file.create_result("user", "bounding-box", data=box)
+            results[res.id] = res
+
+
+        self.assertEqual(5, Result.query.count())
+
+        file_uuid = str(uuid.uuid1())
+        another_file, is_new = self.project.add_file(
+            uuid=file_uuid,
+            file_type="image",
+            name=f"name2",
+            filename=f"image2",
+            extension=".jpg",
+            size=32*1024,
+        )
+        self.assertTrue(is_new)
+
+        for i in range(n):
+            box = dict(x=0, y=0, w=0.9, h=1.0)
+            another_file.create_result("user", "bounding-box", data=box)
+
+        self.assertEqual(10, Result.query.count())
+
+        url = url_for("get_results", file_id=self.file.id)
+
+        response = self.get(url)
+        self.assertTrue(response.is_json)
+
+        content = response.json
+
+        self.assertEqual(5, len(content))
+
+        for entry in content:
+            res = results[entry["id"]]
+
+            self.assertDictEqual(res.serialize(), entry)
+