Skip to content

Commit

Permalink
feat: handle multiple tags on topics apiv2
Browse files Browse the repository at this point in the history
  • Loading branch information
abulte committed Nov 21, 2024
1 parent c088d01 commit b1893c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion udata/tests/api/test_topics_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
19 changes: 14 additions & 5 deletions udata/tests/apiv2/test_topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand All @@ -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)
Expand All @@ -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))
Expand Down

0 comments on commit b1893c0

Please sign in to comment.