udata 7.0.7.dev28351__py2.py3-none-any.whl → 7.0.7.dev28410__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.

@@ -16,6 +16,7 @@ class TopicFactory(ModelFactory):
16
16
  description = factory.Faker('text')
17
17
  tags = factory.LazyAttribute(lambda o: [utils.unique_string(16)
18
18
  for _ in range(3)])
19
+ private = False
19
20
 
20
21
  @factory.lazy_attribute
21
22
  def datasets(self):
@@ -1,15 +1,24 @@
1
+ from bson.objectid import ObjectId
2
+
3
+ from udata.api import api
1
4
  from udata.api.parsers import ModelApiParser
2
5
 
3
6
 
4
7
  class TopicApiParser(ModelApiParser):
5
8
  sorts = {
6
9
  'name': 'name',
7
- 'created': 'created_at'
10
+ 'created': 'created_at',
11
+ 'last_modified': 'last_modified',
8
12
  }
9
13
 
10
14
  def __init__(self):
11
15
  super().__init__()
12
16
  self.parser.add_argument('tag', type=str, location='args')
17
+ self.parser.add_argument('include_private', type=bool, location='args')
18
+ self.parser.add_argument('geozone', type=str, location='args')
19
+ self.parser.add_argument('granularity', type=str, location='args')
20
+ self.parser.add_argument('organization', type=str, location='args')
21
+ self.parser.add_argument('owner', type=str, location='args')
13
22
 
14
23
  @staticmethod
15
24
  def parse_filters(topics, args):
@@ -22,4 +31,18 @@ class TopicApiParser(ModelApiParser):
22
31
  topics = topics.search_text(phrase_query)
23
32
  if args.get('tag'):
24
33
  topics = topics.filter(tags=args['tag'])
34
+ if not args.get('include_private'):
35
+ topics = topics.filter(private=False)
36
+ if args.get('geozone'):
37
+ topics = topics.filter(spatial__zones=args['geozone'])
38
+ if args.get('granularity'):
39
+ topics = topics.filter(spatial__granularity=args['granularity'])
40
+ if args.get('organization'):
41
+ if not ObjectId.is_valid(args['organization']):
42
+ api.abort(400, 'Organization arg must be an identifier')
43
+ topics = topics.filter(organization=args['organization'])
44
+ if args.get('owner'):
45
+ if not ObjectId.is_valid(args['owner']):
46
+ api.abort(400, 'Owner arg must be an identifier')
47
+ topics = topics.filter(owner=args['owner'])
25
48
  return topics
@@ -1,9 +1,10 @@
1
1
  from flask import url_for
2
2
 
3
3
  from udata.core.organization.factories import OrganizationFactory
4
+ from udata.core.spatial.factories import SpatialCoverageFactory
4
5
  from udata.core.spatial.models import spatial_granularities
5
- from udata.core.topic.models import Topic
6
6
  from udata.core.topic.factories import TopicFactory
7
+ from udata.core.topic.models import Topic
7
8
  from udata.core.user.factories import UserFactory
8
9
  from udata.models import Member, Discussion
9
10
  from udata.tests.api.test_datasets_api import SAMPLE_GEOM
@@ -17,13 +18,23 @@ class TopicsAPITest(APITestCase):
17
18
 
18
19
  def test_topic_api_list(self):
19
20
  '''It should fetch a topic list from the API'''
20
- TopicFactory.create_batch(3)
21
+ owner = UserFactory()
22
+ org = OrganizationFactory()
23
+ paca, _, _ = create_geozones_fixtures()
24
+
21
25
  tag_topic = TopicFactory(tags=['energy'])
22
26
  name_topic = TopicFactory(name='topic-for-query')
27
+ private_topic = TopicFactory(private=True)
28
+ geozone_topic = TopicFactory(spatial=SpatialCoverageFactory(zones=[paca.id]))
29
+ granularity_topic = TopicFactory(
30
+ spatial=SpatialCoverageFactory(granularity='country')
31
+ )
32
+ owner_topic = TopicFactory(owner=owner)
33
+ org_topic = TopicFactory(organization=org)
23
34
 
24
35
  response = self.get(url_for('api.topics'))
25
36
  self.assert200(response)
26
- self.assertEqual(len(response.json['data']), 5)
37
+ self.assertEqual(len(response.json['data']), 6)
27
38
 
28
39
  response = self.get(url_for('api.topics', q='topic-for'))
29
40
  self.assert200(response)
@@ -49,6 +60,32 @@ class TopicsAPITest(APITestCase):
49
60
  self.assertIsNotNone(reuse['uri'])
50
61
  self.assertEqual(len(reuses), 3)
51
62
 
63
+ response = self.get(url_for('api.topics', include_private='true'))
64
+ self.assert200(response)
65
+ self.assertEqual(len(response.json['data']), 7)
66
+ self.assertIn(str(private_topic.id), [t['id'] for t in response.json['data']])
67
+
68
+ response = self.get(url_for('api.topics', geozone=paca.id))
69
+ self.assert200(response)
70
+ self.assertEqual(len(response.json['data']), 1)
71
+ self.assertIn(str(geozone_topic.id), [t['id'] for t in response.json['data']])
72
+
73
+ response = self.get(url_for('api.topics', granularity='country'))
74
+ self.assert200(response)
75
+ self.assertEqual(len(response.json['data']), 1)
76
+ self.assertIn(str(granularity_topic.id), [t['id'] for t in response.json['data']])
77
+
78
+ response = self.get(url_for('api.topics', owner=owner.id))
79
+ self.assert200(response)
80
+ self.assertEqual(len(response.json['data']), 1)
81
+ self.assertIn(str(owner_topic.id), [t['id'] for t in response.json['data']])
82
+
83
+ response = self.get(url_for('api.topics', organization=org.id))
84
+ self.assert200(response)
85
+ self.assertEqual(len(response.json['data']), 1)
86
+ self.assertIn(str(org_topic.id), [t['id'] for t in response.json['data']])
87
+
88
+
52
89
  def test_topic_api_get(self):
53
90
  '''It should fetch a topic from the API'''
54
91
  topic = TopicFactory()
@@ -1,10 +1,13 @@
1
1
  from flask import url_for
2
2
 
3
- from udata.tests.api import APITestCase
4
3
  from udata.core.dataset.factories import DatasetFactory
5
- from udata.core.topic.factories import TopicFactory
4
+ from udata.core.organization.factories import OrganizationFactory
5
+ from udata.core.spatial.factories import SpatialCoverageFactory
6
6
  from udata.core.reuse.factories import ReuseFactory
7
+ from udata.core.topic.factories import TopicFactory
7
8
  from udata.core.user.factories import UserFactory
9
+ from udata.tests.api import APITestCase
10
+ from udata.tests.features.territories import create_geozones_fixtures
8
11
 
9
12
 
10
13
  class TopicsAPITest(APITestCase):
@@ -12,14 +15,24 @@ class TopicsAPITest(APITestCase):
12
15
 
13
16
  def test_topic_api_list(self):
14
17
  '''It should fetch a topic list from the API'''
15
- TopicFactory.create_batch(3)
18
+ owner = UserFactory()
19
+ org = OrganizationFactory()
20
+ paca, _, _ = create_geozones_fixtures()
21
+
16
22
  tag_topic = TopicFactory(tags=['energy'])
17
23
  name_topic = TopicFactory(name='topic-for-query')
24
+ private_topic = TopicFactory(private=True)
25
+ geozone_topic = TopicFactory(spatial=SpatialCoverageFactory(zones=[paca.id]))
26
+ granularity_topic = TopicFactory(
27
+ spatial=SpatialCoverageFactory(granularity='country')
28
+ )
29
+ owner_topic = TopicFactory(owner=owner)
30
+ org_topic = TopicFactory(organization=org)
18
31
 
19
32
  response = self.get(url_for('apiv2.topics_list'))
20
33
  assert response.status_code == 200
21
34
  data = response.json['data']
22
- assert len(data) == 5
35
+ assert len(data) == 6
23
36
 
24
37
  hateoas_fields = ["rel", "href", "type", "total"]
25
38
  assert all(k in data[0]["datasets"] for k in hateoas_fields)
@@ -35,6 +48,31 @@ class TopicsAPITest(APITestCase):
35
48
  assert len(response.json['data']) == 1
36
49
  assert response.json['data'][0]['id'] == str(tag_topic.id)
37
50
 
51
+ response = self.get(url_for('api.topics', include_private='true'))
52
+ assert response.status_code == 200
53
+ assert len(response.json['data']) == 7
54
+ assert str(private_topic.id) in [t['id'] for t in response.json['data']]
55
+
56
+ response = self.get(url_for('api.topics', geozone=paca.id))
57
+ assert response.status_code == 200
58
+ assert len(response.json['data']) == 1
59
+ assert str(geozone_topic.id) in [t['id'] for t in response.json['data']]
60
+
61
+ response = self.get(url_for('api.topics', granularity='country'))
62
+ assert response.status_code == 200
63
+ assert len(response.json['data']) == 1
64
+ assert str(granularity_topic.id) in [t['id'] for t in response.json['data']]
65
+
66
+ response = self.get(url_for('api.topics', owner=owner.id))
67
+ assert response.status_code == 200
68
+ assert len(response.json['data']) == 1
69
+ assert str(owner_topic.id) in [t['id'] for t in response.json['data']]
70
+
71
+ response = self.get(url_for('api.topics', organization=org.id))
72
+ assert response.status_code == 200
73
+ assert len(response.json['data']) == 1
74
+ assert str(org_topic.id) in [t['id'] for t in response.json['data']]
75
+
38
76
  def test_topic_api_get(self):
39
77
  '''It should fetch a topic from the API'''
40
78
  topic = TopicFactory()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: udata
3
- Version: 7.0.7.dev28351
3
+ Version: 7.0.7.dev28410
4
4
  Summary: Open data portal
5
5
  Home-page: https://github.com/opendatateam/udata
6
6
  Author: Opendata Team
@@ -138,7 +138,7 @@ It is collectively taken care of by members of the
138
138
 
139
139
  ## Current (in progress)
140
140
 
141
- - Nothing yet
141
+ - Topic: add filters in API [#3007](https://github.com/opendatateam/udata/pull/3007)
142
142
 
143
143
  ## 7.0.6 (2024-03-29)
144
144
 
@@ -203,10 +203,10 @@ udata/core/tags/views.py,sha256=BoBktrbx0tqkIu3yYLj_XJjB7ZHu_tq5vfEBrh0MUwI,384
203
203
  udata/core/topic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
204
204
  udata/core/topic/api.py,sha256=G3hN4e9rK5mIYvDLvPpAOo_DN2SySAGykVVvXGx4uMY,5105
205
205
  udata/core/topic/apiv2.py,sha256=cf-WUSZ7P6Tss3S8utS-uhreLgGI5XR3nn_1UWiZ_Xs,9846
206
- udata/core/topic/factories.py,sha256=Vy9dMVSI6XMeAWhxLH1OFJ0vbmEoOtStPDE6HF_nIc4,697
206
+ udata/core/topic/factories.py,sha256=ksWcIAoYiKCS48q2-RKMYbNJfz1z9H0fBYM9lswFr-8,717
207
207
  udata/core/topic/forms.py,sha256=XqGI4nANdsm2UkIiGAuVqEdZkN5N9sqJ4VaM_PhTaVQ,987
208
208
  udata/core/topic/models.py,sha256=PZsYfiuEU86iL1x-qvDevn4Io8lKGahAbqky03j1N2k,2071
209
- udata/core/topic/parsers.py,sha256=oe_4ehnlgPKre2GG1LA6hcQa6H5V5q1adUsQIzVqb_Q,876
209
+ udata/core/topic/parsers.py,sha256=p2JCGfjeqb5GQTstZssclzLRLqUHy7KWJ7TDcLSF51M,2103
210
210
  udata/core/topic/permissions.py,sha256=RtFPPlxuU_Bv7ip6LDO4AoPrKFnIOEs9cCMXaSSmEdk,118
211
211
  udata/core/user/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
212
212
  udata/core/user/activities.py,sha256=AMRbYgum8uJXAS3L-ddQN-xKtKRvsmesDZ0ItBY_jS0,2799
@@ -579,14 +579,14 @@ udata/tests/api/test_organizations_api.py,sha256=HxeTqP14wlWGaQt4fpQljuRy98HWnmL
579
579
  udata/tests/api/test_reuses_api.py,sha256=gQ-o4JXK2S6z2yW13-i8e81pCdr9j2yyM1KinPbkc5g,16971
580
580
  udata/tests/api/test_swagger.py,sha256=tLg452rCD5Q0AgFXOVZKMM6jGiWwC5diX5PxbdYni0o,760
581
581
  udata/tests/api/test_tags_api.py,sha256=xSIx_x5gqKz6BJCXKEsTqA_CR4BF1nG5NxEyfp9dy0o,2579
582
- udata/tests/api/test_topics_api.py,sha256=BYkfBJpz58DbCZ_fgPvpH0unKPJ1PY8B5dm9Km4YWkQ,7586
582
+ udata/tests/api/test_topics_api.py,sha256=RItjoO7g2o2BZ34cOHJvPoSus_jIe-AYHFrX_iaHQ4o,9322
583
583
  udata/tests/api/test_transfer_api.py,sha256=aGGJp79YYHQQyMAKhp7urk4eD587v3kbIy-8rJ_kk1s,2901
584
584
  udata/tests/api/test_user_api.py,sha256=NVXsn-sRrMQYbbUyJ2_I2_C3UPfzgCZv-us6RvM5VE8,13597
585
585
  udata/tests/apiv2/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
586
586
  udata/tests/apiv2/test_datasets.py,sha256=j2cuaGtTnpF5TAvuzMEmx0uEXvuANlIKS5quupJocx4,17953
587
587
  udata/tests/apiv2/test_organizations.py,sha256=CpNG8xl13rZXxTN2-JRx9ZkyI7IuQUaOsNuumUxuB3I,6704
588
588
  udata/tests/apiv2/test_swagger.py,sha256=D8jpRqDUmqVkNVYkYaXfvMPUc7OBVs_dMsC13KZciWE,785
589
- udata/tests/apiv2/test_topics.py,sha256=d30tJU167B5r8WWBHvI9rKdjnGrVpf7-HyvKlWyaxtc,8260
589
+ udata/tests/apiv2/test_topics.py,sha256=UA5LcILq7zUa9TXi1iplrvtcY5C0u-0R8PvTCUWPs2Q,10106
590
590
  udata/tests/cli/test_cli_base.py,sha256=piqoq4Ib5bdZQpuUAJh583qfjCSglWZQclKzhO3Yr_0,321
591
591
  udata/tests/cli/test_db_cli.py,sha256=-hw9SU3RvNT7fvqVtQHxEpKstnjMU4L_DY9tiBH-ybs,1726
592
592
  udata/tests/data/image.jpg,sha256=hdmpaCjOhmAAfNGuTqWKEjv7IC4GXJx-nP_rT274hc8,337049
@@ -664,9 +664,9 @@ udata/translations/pt/LC_MESSAGES/udata.mo,sha256=zCVMB-a4-mLM1jNyYMk58rgVRaVIwQ
664
664
  udata/translations/pt/LC_MESSAGES/udata.po,sha256=avfWczvlLBKSohyB55-4TLmUGMU_Rze4XmAo4OTk2v0,43513
665
665
  udata/translations/sr/LC_MESSAGES/udata.mo,sha256=ScuqdpaV4y1ZIpBAEfxeaKdzkyGZL0mJmKMoG6w0iRQ,28553
666
666
  udata/translations/sr/LC_MESSAGES/udata.po,sha256=QpgEXh1eHjztPa7oNLXd_sds1DC95A-STTtZyTE4m-E,50093
667
- udata-7.0.7.dev28351.dist-info/LICENSE,sha256=V8j_M8nAz8PvAOZQocyRDX7keai8UJ9skgmnwqETmdY,34520
668
- udata-7.0.7.dev28351.dist-info/METADATA,sha256=O7c7cWQ0rDluGfxbKvfyguPOtWQl62dHJuKvWtCddmI,120163
669
- udata-7.0.7.dev28351.dist-info/WHEEL,sha256=-G_t0oGuE7UD0DrSpVZnq1hHMBV9DD2XkS5v7XpmTnk,110
670
- udata-7.0.7.dev28351.dist-info/entry_points.txt,sha256=3SKiqVy4HUqxf6iWspgMqH8d88Htk6KoLbG1BU-UddQ,451
671
- udata-7.0.7.dev28351.dist-info/top_level.txt,sha256=39OCg-VWFWOq4gCKnjKNu-s3OwFlZIu_dVH8Gl6ndHw,12
672
- udata-7.0.7.dev28351.dist-info/RECORD,,
667
+ udata-7.0.7.dev28410.dist-info/LICENSE,sha256=V8j_M8nAz8PvAOZQocyRDX7keai8UJ9skgmnwqETmdY,34520
668
+ udata-7.0.7.dev28410.dist-info/METADATA,sha256=7NK8ToqaPXg_f86QirGUcBqziTraRBZ8oWQLcYmStyE,120234
669
+ udata-7.0.7.dev28410.dist-info/WHEEL,sha256=-G_t0oGuE7UD0DrSpVZnq1hHMBV9DD2XkS5v7XpmTnk,110
670
+ udata-7.0.7.dev28410.dist-info/entry_points.txt,sha256=3SKiqVy4HUqxf6iWspgMqH8d88Htk6KoLbG1BU-UddQ,451
671
+ udata-7.0.7.dev28410.dist-info/top_level.txt,sha256=39OCg-VWFWOq4gCKnjKNu-s3OwFlZIu_dVH8Gl6ndHw,12
672
+ udata-7.0.7.dev28410.dist-info/RECORD,,