udata 9.1.4.dev31143__py2.py3-none-any.whl → 9.1.4.dev31168__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of udata might be problematic. Click here for more details.

@@ -1,5 +1,6 @@
1
1
  import logging
2
2
 
3
+ from bson import ObjectId
3
4
  from mongoengine.errors import DoesNotExist
4
5
 
5
6
  from udata.api import API, api, fields
@@ -61,13 +62,19 @@ activity_parser.add_argument(
61
62
  help="Filter activities for that particular organization",
62
63
  location="args",
63
64
  )
65
+ activity_parser.add_argument(
66
+ "related_to",
67
+ type=str,
68
+ help="Filter activities for that particular object id (ex : reuse, dataset, etc.)",
69
+ location="args",
70
+ )
64
71
 
65
72
 
66
73
  @api.route("/activity", endpoint="activity")
67
74
  class SiteActivityAPI(API):
68
75
  @api.doc("activity")
69
76
  @api.expect(activity_parser)
70
- @api.marshal_list_with(activity_page_fields)
77
+ @api.marshal_with(activity_page_fields)
71
78
  def get(self):
72
79
  """Fetch site activity, optionally filtered by user of org."""
73
80
  args = activity_parser.parse_args()
@@ -79,6 +86,12 @@ class SiteActivityAPI(API):
79
86
  if args["user"]:
80
87
  qs = qs(actor=args["user"])
81
88
 
89
+ if args["related_to"]:
90
+ if not ObjectId.is_valid(args["related_to"]):
91
+ api.abort(400, "`related_to` arg must be an identifier")
92
+
93
+ qs = qs(related_to=args["related_to"])
94
+
82
95
  qs = qs.order_by("-created_at")
83
96
  qs = qs.paginate(args["page"], args["page_size"])
84
97
 
@@ -0,0 +1,69 @@
1
+ import pytest
2
+ from flask import url_for
3
+ from werkzeug.test import TestResponse
4
+
5
+ from udata.core.activity.models import Activity
6
+ from udata.core.dataset.factories import DatasetFactory
7
+ from udata.core.dataset.models import Dataset
8
+ from udata.core.reuse.factories import ReuseFactory
9
+ from udata.core.reuse.models import Reuse
10
+ from udata.core.user.factories import UserFactory
11
+ from udata.mongo import db
12
+ from udata.tests.helpers import assert200, assert400
13
+
14
+ pytestmark = [
15
+ pytest.mark.usefixtures("clean_db"),
16
+ ]
17
+
18
+
19
+ class FakeDatasetActivity(Activity):
20
+ key = "fakeDataset"
21
+ related_to = db.ReferenceField(Dataset, required=True)
22
+
23
+
24
+ class FakeReuseActivity(Activity):
25
+ key = "fakeReuse"
26
+ related_to = db.ReferenceField(Reuse, required=True)
27
+
28
+
29
+ class ActivityAPITest:
30
+ modules = []
31
+
32
+ def test_activity_api_list(self, api) -> None:
33
+ """It should fetch an activity list from the API"""
34
+ activities: list[Activity] = [
35
+ FakeDatasetActivity.objects.create(actor=UserFactory(), related_to=DatasetFactory()),
36
+ FakeReuseActivity.objects.create(actor=UserFactory(), related_to=ReuseFactory()),
37
+ ]
38
+
39
+ response: TestResponse = api.get(url_for("api.activity"))
40
+ assert200(response)
41
+ assert len(response.json["data"]) == len(activities)
42
+
43
+ def test_activity_api_list_filter_by_bogus_related_to(self, api) -> None:
44
+ """It should return a 400 error if the `related_to` parameter isn't a valid ObjectId."""
45
+ response: TestResponse = api.get(url_for("api.activity", related_to="foobar"))
46
+ assert400(response)
47
+
48
+ def test_activity_api_list_filtered_by_related_to(self, api) -> None:
49
+ """It should only return activities that correspond to the `related_to` parameter."""
50
+ dataset1: Dataset = DatasetFactory()
51
+ dataset2: Dataset = DatasetFactory()
52
+ reuse: Reuse = ReuseFactory()
53
+ _activities: list[Activity] = [
54
+ FakeDatasetActivity.objects.create(actor=UserFactory(), related_to=dataset1),
55
+ FakeDatasetActivity.objects.create(actor=UserFactory(), related_to=dataset1),
56
+ FakeDatasetActivity.objects.create(actor=UserFactory(), related_to=dataset2),
57
+ FakeReuseActivity.objects.create(actor=UserFactory(), related_to=reuse),
58
+ ]
59
+
60
+ response: TestResponse = api.get(url_for("api.activity", related_to=dataset1.id))
61
+ assert200(response)
62
+ len(response.json["data"]) == 2
63
+ assert response.json["data"][0]["related_to"] == dataset1.title
64
+ assert response.json["data"][1]["related_to"] == dataset1.title
65
+
66
+ response: TestResponse = api.get(url_for("api.activity", related_to=reuse.id))
67
+ assert200(response)
68
+ len(response.json["data"]) == 1
69
+ assert response.json["data"][0]["related_to"] == reuse.title
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: udata
3
- Version: 9.1.4.dev31143
3
+ Version: 9.1.4.dev31168
4
4
  Summary: Open data portal
5
5
  Home-page: https://github.com/opendatateam/udata
6
6
  Author: Opendata Team
@@ -145,6 +145,7 @@ It is collectively taken care of by members of the
145
145
  - Convert reuse to new API system [#3066](https://github.com/opendatateam/udata/pull/3066)
146
146
  - Fix circular import error [#3128](https://github.com/opendatateam/udata/pull/3128)
147
147
  - Add an option to specify the port when using `inv serve` [#3123](https://github.com/opendatateam/udata/pull/3123)
148
+ - Add a new `related_to` filter parameter to the activities API endpoint [#3127](https://github.com/opendatateam/udata/pull/3127)
148
149
 
149
150
  ## 9.1.3 (2024-08-01)
150
151
 
@@ -56,7 +56,7 @@ udata/commands/tests/test_fixtures.py,sha256=kFwqWA3Ha0mnCR5EE5aPz6jv3hfPheuwOMY
56
56
  udata/core/__init__.py,sha256=O7C9WWCXiLWnWPnPbFRszWhOmvRQiI4gD-5qkWvPGRo,385
57
57
  udata/core/owned.py,sha256=UEg5tp-ZunzC2avCdholpqibDIUZgFBsXS7BEcdnBy0,4567
58
58
  udata/core/activity/__init__.py,sha256=OaiFyq7HB4xL4SuMPD1N8IFNpntwx9ZayVzelciOieI,298
59
- udata/core/activity/api.py,sha256=blVYf3unQbkYbm8FY7jv0w7_W52Frghmj2vYATh9Tsc,3445
59
+ udata/core/activity/api.py,sha256=QFSLSVf65f-jz0dyVuMqaXm6qB4m-YlGnjqK33suwI8,3854
60
60
  udata/core/activity/models.py,sha256=Ln9YUsdCBMFmUlw5GA2gIJ50sMorMFzZGo8u8sy7pIE,2072
61
61
  udata/core/activity/signals.py,sha256=Io2A43as3yR-DZ5R3wzM_bTpn528pxWsZDUFZ9xtj2Y,191
62
62
  udata/core/activity/tasks.py,sha256=lEnISnHXPMeeErWIhJbSYOlxnrc6yAKC-T28qTEWQn0,1235
@@ -597,6 +597,7 @@ udata/tests/test_transfer.py,sha256=_0pBwYs3T7OSZ7bO3KmQ81SjwCJyT4EVf8YYHXOkwdk,
597
597
  udata/tests/test_uris.py,sha256=MxafZ0SyzSNRomVpZnH1ChzWaHOi1MQiXe1gmKnBc6o,8517
598
598
  udata/tests/test_utils.py,sha256=3BGnlvw-GOE6tLHQteo-uUeYuzq4rsjePOuytFGkpOg,7967
599
599
  udata/tests/api/__init__.py,sha256=y4sL7LD1-KwONHF0q_Rhk2W6BmGUlp7Uz2JnX3e27sk,1218
600
+ udata/tests/api/test_activities_api.py,sha256=RjDDeNle3T-ydVnh6BRypqxAE_244-DXaKkuUCT0HVU,2823
600
601
  udata/tests/api/test_auth_api.py,sha256=0Y_JXQ4x8jvc_pp4g3H6gZ_X0QVGM6TaZ2IN9LeOWEg,21657
601
602
  udata/tests/api/test_base_api.py,sha256=2w_vz0eEuq3P3aN-ByvxGc3VZAo7XtgatFfcrzf2uEU,2244
602
603
  udata/tests/api/test_contact_points.py,sha256=pyakkKnM4lH_asuEoXq9lQyJC9to6ZxSp4QQrHh1c1U,1041
@@ -696,9 +697,9 @@ udata/translations/pt/LC_MESSAGES/udata.mo,sha256=WpPzAqVd2Onv_kz45ULUySKPLrpjcc
696
697
  udata/translations/pt/LC_MESSAGES/udata.po,sha256=18Op9RUITewoDRewlOdYzzq6gjsf1lsvepACV1d7zxs,44976
697
698
  udata/translations/sr/LC_MESSAGES/udata.mo,sha256=NIYRNhVoETZUvIvWm3cCW7DtMBAnS2vXzZjMF5ZzD_c,28500
698
699
  udata/translations/sr/LC_MESSAGES/udata.po,sha256=rQB-4V4WJ7bURj6g2j653vItr5TMHadcLQxec7_fDmg,51545
699
- udata-9.1.4.dev31143.dist-info/LICENSE,sha256=V8j_M8nAz8PvAOZQocyRDX7keai8UJ9skgmnwqETmdY,34520
700
- udata-9.1.4.dev31143.dist-info/METADATA,sha256=cmYTKnza6rM9zflVa1Wbm7oSsIaxzVpHMVD87-hNuUY,128887
701
- udata-9.1.4.dev31143.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
702
- udata-9.1.4.dev31143.dist-info/entry_points.txt,sha256=3SKiqVy4HUqxf6iWspgMqH8d88Htk6KoLbG1BU-UddQ,451
703
- udata-9.1.4.dev31143.dist-info/top_level.txt,sha256=39OCg-VWFWOq4gCKnjKNu-s3OwFlZIu_dVH8Gl6ndHw,12
704
- udata-9.1.4.dev31143.dist-info/RECORD,,
700
+ udata-9.1.4.dev31168.dist-info/LICENSE,sha256=V8j_M8nAz8PvAOZQocyRDX7keai8UJ9skgmnwqETmdY,34520
701
+ udata-9.1.4.dev31168.dist-info/METADATA,sha256=YZ2NedcM5hDUSpvuREmEnsk_Fr0O4r5Ftx1CXTD_eI0,129017
702
+ udata-9.1.4.dev31168.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
703
+ udata-9.1.4.dev31168.dist-info/entry_points.txt,sha256=3SKiqVy4HUqxf6iWspgMqH8d88Htk6KoLbG1BU-UddQ,451
704
+ udata-9.1.4.dev31168.dist-info/top_level.txt,sha256=39OCg-VWFWOq4gCKnjKNu-s3OwFlZIu_dVH8Gl6ndHw,12
705
+ udata-9.1.4.dev31168.dist-info/RECORD,,