From 67cc6328733c8ca0218b65284a53c2dfb981db89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bult=C3=A9?= Date: Thu, 21 Nov 2024 10:58:34 +0100 Subject: [PATCH] feat: handle multiple tags on topics apiv2 --- udata/tests/api/test_topics_api.py | 2 +- udata/tests/apiv2/test_topics.py | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/udata/tests/api/test_topics_api.py b/udata/tests/api/test_topics_api.py index 7e57d0e38e..73c6f63e7e 100644 --- a/udata/tests/api/test_topics_api.py +++ b/udata/tests/api/test_topics_api.py @@ -40,7 +40,7 @@ def test_topic_api_list(self): self.assertEqual(len(response.json["data"]), 1) self.assertEqual(response.json["data"][0]["id"], str(name_topic.id)) - response = self.get(url_for("api.topics", tag="my-tag-1")) + response = self.get(url_for("api.topics", tag=["my-tag-shared", "my-tag-1"])) self.assert200(response) self.assertEqual(len(response.json["data"]), 1) self.assertEqual(response.json["data"][0]["id"], str(tag_topic_1.id)) diff --git a/udata/tests/apiv2/test_topics.py b/udata/tests/apiv2/test_topics.py index 9289ea894d..6e5569e026 100644 --- a/udata/tests/apiv2/test_topics.py +++ b/udata/tests/apiv2/test_topics.py @@ -19,7 +19,8 @@ def test_topic_api_list(self): org = OrganizationFactory() paca, _, _ = create_geozones_fixtures() - tag_topic = TopicFactory(tags=["energy"]) + tag_topic_1 = TopicFactory(tags=["my-tag-shared", "my-tag-1"]) + tag_topic_2 = TopicFactory(tags=["my-tag-shared", "my-tag-2"]) name_topic = TopicFactory(name="topic-for-query") private_topic = TopicFactory(private=True) geozone_topic = TopicFactory(spatial=SpatialCoverageFactory(zones=[paca.id])) @@ -30,7 +31,7 @@ def test_topic_api_list(self): response = self.get(url_for("apiv2.topics_list")) assert response.status_code == 200 data = response.json["data"] - assert len(data) == 6 + assert len(data) == 7 hateoas_fields = ["rel", "href", "type", "total"] assert all(k in data[0]["datasets"] for k in hateoas_fields) @@ -41,14 +42,22 @@ def test_topic_api_list(self): assert len(response.json["data"]) == 1 assert response.json["data"][0]["id"] == str(name_topic.id) - response = self.get(url_for("apiv2.topics_list", tag="energy")) + response = self.get(url_for("apiv2.topics_list", tag=["my-tag-shared", "my-tag-1"])) assert response.status_code == 200 assert len(response.json["data"]) == 1 - assert response.json["data"][0]["id"] == str(tag_topic.id) + assert response.json["data"][0]["id"] == str(tag_topic_1.id) + + response = self.get(url_for("apiv2.topics_list", tag=["my-tag-shared"])) + assert response.status_code == 200 + assert len(response.json["data"]) == 2 + self.assertEqual( + set([str(tag_topic_1.id), str(tag_topic_2.id)]), + set([t["id"] for t in response.json["data"]]), + ) response = self.get(url_for("api.topics", include_private="true")) assert response.status_code == 200 - assert len(response.json["data"]) == 7 + assert len(response.json["data"]) == 8 assert str(private_topic.id) in [t["id"] for t in response.json["data"]] response = self.get(url_for("api.topics", geozone=paca.id))