From 9f41df7bdf4f4a9757a4f68211ad314059d372c2 Mon Sep 17 00:00:00 2001 From: Erwan Rouchet <rouchet@teklia.com> Date: Tue, 26 Mar 2024 11:52:26 +0100 Subject: [PATCH] Update query counts --- arkindex/training/tests/test_datasets_api.py | 62 ++++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/arkindex/training/tests/test_datasets_api.py b/arkindex/training/tests/test_datasets_api.py index 9dcef03ffc..073d299eb3 100644 --- a/arkindex/training/tests/test_datasets_api.py +++ b/arkindex/training/tests/test_datasets_api.py @@ -267,7 +267,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_create(self): self.client.force_login(self.user) - with self.assertNumQueries(11): + with self.assertNumQueries(8): response = self.client.post( reverse("api:corpus-datasets", kwargs={"pk": self.corpus.pk}), data={"name": "My dataset", "description": "My dataset for my experiments."}, @@ -301,7 +301,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_create_state_ignored(self): self.client.force_login(self.user) - with self.assertNumQueries(11): + with self.assertNumQueries(8): response = self.client.post( reverse("api:corpus-datasets", kwargs={"pk": self.corpus.pk}), data={"name": "My dataset", "description": "My dataset for my experiments.", "state": "complete"}, @@ -336,7 +336,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_create_sets(self): self.client.force_login(self.user) - with self.assertNumQueries(11): + with self.assertNumQueries(8): response = self.client.post( reverse("api:corpus-datasets", kwargs={"pk": self.corpus.pk}), data={"name": "My dataset", "description": "My dataset for my experiments.", "set_names": ["a", "b", "c", "d"]}, @@ -455,7 +455,7 @@ class TestDatasetsAPI(FixtureAPITestCase): @patch("arkindex.project.mixins.has_access", return_value=False) def test_update_requires_write_corpus(self, has_access_mock): self.client.force_login(self.read_user) - with self.assertNumQueries(3): + with self.assertNumQueries(4): response = self.client.put( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -486,7 +486,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_update_name_too_long(self): self.client.force_login(self.user) - with self.assertNumQueries(3): + with self.assertNumQueries(4): response = self.client.put( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -501,7 +501,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_update_name_already_exists_in_corpus(self): Dataset.objects.create(name="Another Dataset", description="A set of data", corpus=self.corpus, creator=self.dataset_creator) self.client.force_login(self.user) - with self.assertNumQueries(4): + with self.assertNumQueries(5): response = self.client.put( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -515,7 +515,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_update_requires_all_fields(self): self.client.force_login(self.user) - with self.assertNumQueries(3): + with self.assertNumQueries(4): response = self.client.put( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={"name": "Shin Seiki Evangelion"}, @@ -527,7 +527,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_update_sets_forbidden(self): self.client.force_login(self.user) self.assertIsNone(self.dataset.task_id) - with self.assertNumQueries(3): + with self.assertNumQueries(4): response = self.client.put( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -542,7 +542,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_update_empty_or_blank_description_or_name(self): self.client.force_login(self.user) - with self.assertNumQueries(3): + with self.assertNumQueries(4): response = self.client.put( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -559,7 +559,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_update_all_errors(self): self.client.force_login(self.user) - with self.assertNumQueries(3): + with self.assertNumQueries(4): response = self.client.put( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -580,7 +580,7 @@ class TestDatasetsAPI(FixtureAPITestCase): self.client.force_login(self.user) self.dataset.state = DatasetState.Building self.dataset.save() - with self.assertNumQueries(4): + with self.assertNumQueries(5): response = self.client.put( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -598,7 +598,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_update_ponos_task_state_update(self): self.dataset.state = DatasetState.Building self.dataset.save() - with self.assertNumQueries(8): + with self.assertNumQueries(6): response = self.client.put( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), HTTP_AUTHORIZATION=f"Ponos {self.task.token}", @@ -663,7 +663,7 @@ class TestDatasetsAPI(FixtureAPITestCase): self.client.force_login(self.user) for new_state in DatasetState: with self.subTest(new_state=new_state): - with self.assertNumQueries(3): + with self.assertNumQueries(4): response = self.client.put( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -681,7 +681,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_update_ponos_task_state_requires_dataset_in_process(self): self.process.process_datasets.all().delete() - with self.assertNumQueries(4): + with self.assertNumQueries(5): response = self.client.put( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), HTTP_AUTHORIZATION=f"Ponos {self.task.token}", @@ -698,7 +698,7 @@ class TestDatasetsAPI(FixtureAPITestCase): }) def test_update_ponos_task_bad_state(self): - with self.assertNumQueries(2): + with self.assertNumQueries(3): response = self.client.put( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), HTTP_AUTHORIZATION=f"Ponos {self.task.token}", @@ -741,7 +741,7 @@ class TestDatasetsAPI(FixtureAPITestCase): @patch("arkindex.project.mixins.has_access", return_value=False) def test_partial_update_requires_write_corpus(self, has_access_mock): self.client.force_login(self.read_user) - with self.assertNumQueries(3): + with self.assertNumQueries(4): response = self.client.patch( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={"name": "Shin Seiki Evangelion"}, @@ -755,7 +755,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_partial_update_name_too_long(self): self.client.force_login(self.user) - with self.assertNumQueries(3): + with self.assertNumQueries(4): response = self.client.patch( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -769,7 +769,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_partial_update_name_already_exists_in_corpus(self): Dataset.objects.create(name="Another Dataset", description="A set of data", corpus=self.corpus, creator=self.dataset_creator) self.client.force_login(self.user) - with self.assertNumQueries(4): + with self.assertNumQueries(5): response = self.client.patch( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -782,7 +782,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_partial_update(self): self.client.force_login(self.user) - with self.assertNumQueries(8): + with self.assertNumQueries(6): response = self.client.patch( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -799,7 +799,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_partial_update_empty_or_blank_description_or_name(self): self.client.force_login(self.user) - with self.assertNumQueries(3): + with self.assertNumQueries(4): response = self.client.patch( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -813,7 +813,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_partial_update_requires_ponos_auth(self): self.client.force_login(self.user) - with self.assertNumQueries(4): + with self.assertNumQueries(5): response = self.client.patch( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -827,7 +827,7 @@ class TestDatasetsAPI(FixtureAPITestCase): }) def test_partial_update_ponos_task_state_update(self): - with self.assertNumQueries(8): + with self.assertNumQueries(6): response = self.client.patch( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), HTTP_AUTHORIZATION=f"Ponos {self.task.token}", @@ -842,7 +842,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_partial_update_ponos_task_state_requires_dataset_in_process(self): self.process.process_datasets.all().delete() - with self.assertNumQueries(4): + with self.assertNumQueries(5): response = self.client.patch( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), HTTP_AUTHORIZATION=f"Ponos {self.task.token}", @@ -857,7 +857,7 @@ class TestDatasetsAPI(FixtureAPITestCase): }) def test_partial_update_ponos_task_bad_state(self): - with self.assertNumQueries(2): + with self.assertNumQueries(3): response = self.client.patch( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), HTTP_AUTHORIZATION=f"Ponos {self.task.token}", @@ -919,7 +919,7 @@ class TestDatasetsAPI(FixtureAPITestCase): self.client.force_login(self.user) for new_state in DatasetState: with self.subTest(new_state=new_state): - with self.assertNumQueries(3): + with self.assertNumQueries(4): response = self.client.patch( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}), data={ @@ -981,7 +981,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_retrieve(self): self.client.force_login(self.user) - with self.assertNumQueries(6): + with self.assertNumQueries(4): response = self.client.get( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}) ) @@ -1010,7 +1010,7 @@ class TestDatasetsAPI(FixtureAPITestCase): self.client.force_login(self.user) self.dataset.task = self.task self.dataset.save() - with self.assertNumQueries(6): + with self.assertNumQueries(4): response = self.client.get( reverse("api:dataset-update", kwargs={"pk": self.dataset.pk}) ) @@ -1882,7 +1882,7 @@ class TestDatasetsAPI(FixtureAPITestCase): with self.assertNumQueries(8): response = self.client.get(reverse("api:element-datasets", kwargs={"pk": str(self.page1.id)}), {"with_neighbors": True}) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.maxDiff = None + self.assertDictEqual(response.json(), { "count": 3, "next": None, @@ -2044,7 +2044,7 @@ class TestDatasetsAPI(FixtureAPITestCase): self.assertCountEqual(self.corpus.datasets.values_list("name", flat=True), ["First Dataset", "Second Dataset"]) self.client.force_login(self.user) - with self.assertNumQueries(16): + with self.assertNumQueries(14): response = self.client.post( reverse("api:dataset-clone", kwargs={"pk": self.dataset.id}), format="json", @@ -2101,7 +2101,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_clone_existing_name(self): self.corpus.datasets.create(name="Clone of First Dataset", creator=self.user) self.client.force_login(self.user) - with self.assertNumQueries(15): + with self.assertNumQueries(13): response = self.client.post( reverse("api:dataset-clone", kwargs={"pk": self.dataset.id}), format="json", @@ -2151,7 +2151,7 @@ class TestDatasetsAPI(FixtureAPITestCase): def test_clone_name_too_long(self): dataset = self.corpus.datasets.create(name="A" * 99, creator=self.user) self.client.force_login(self.user) - with self.assertNumQueries(13): + with self.assertNumQueries(12): response = self.client.post( reverse("api:dataset-clone", kwargs={"pk": dataset.id}), format="json", -- GitLab