udata 12.0.2.dev17__py3-none-any.whl → 12.0.2.dev18__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.

Files changed (110) hide show
  1. udata/commands/tests/test_fixtures.py +2 -3
  2. udata/core/badges/tests/test_commands.py +2 -4
  3. udata/core/badges/tests/test_model.py +2 -2
  4. udata/core/pages/tests/test_api.py +0 -2
  5. udata/core/spatial/tests/test_api.py +17 -20
  6. udata/core/spatial/tests/test_models.py +3 -3
  7. udata/core/user/tests/test_user_model.py +2 -6
  8. udata/features/identicon/tests/test_backends.py +3 -13
  9. udata/harvest/tests/ckan/test_ckan_backend.py +300 -337
  10. udata/harvest/tests/ckan/test_ckan_backend_errors.py +94 -99
  11. udata/harvest/tests/ckan/test_ckan_backend_filters.py +128 -122
  12. udata/harvest/tests/ckan/test_dkan_backend.py +39 -51
  13. udata/harvest/tests/test_actions.py +7 -7
  14. udata/harvest/tests/test_api.py +2 -4
  15. udata/harvest/tests/test_base_backend.py +3 -4
  16. udata/harvest/tests/test_dcat_backend.py +4 -6
  17. udata/harvest/tests/test_models.py +2 -4
  18. udata/harvest/tests/test_notifications.py +2 -4
  19. udata/harvest/tests/test_tasks.py +2 -3
  20. udata/tests/__init__.py +40 -58
  21. udata/tests/api/__init__.py +87 -2
  22. udata/tests/api/test_activities_api.py +17 -23
  23. udata/tests/api/test_auth_api.py +2 -4
  24. udata/tests/api/test_contact_points.py +48 -54
  25. udata/tests/api/test_dataservices_api.py +0 -2
  26. udata/tests/api/test_datasets_api.py +15 -29
  27. udata/tests/api/test_me_api.py +4 -6
  28. udata/tests/api/test_organizations_api.py +19 -38
  29. udata/tests/api/test_reports_api.py +0 -4
  30. udata/tests/api/test_reuses_api.py +9 -19
  31. udata/tests/api/test_swagger.py +2 -3
  32. udata/tests/api/test_tags_api.py +6 -7
  33. udata/tests/api/test_transfer_api.py +0 -2
  34. udata/tests/api/test_user_api.py +8 -10
  35. udata/tests/apiv2/test_datasets.py +0 -4
  36. udata/tests/apiv2/test_me_api.py +0 -2
  37. udata/tests/apiv2/test_organizations.py +0 -2
  38. udata/tests/apiv2/test_swagger.py +2 -3
  39. udata/tests/apiv2/test_topics.py +0 -2
  40. udata/tests/cli/test_cli_base.py +14 -12
  41. udata/tests/cli/test_db_cli.py +51 -54
  42. udata/tests/contact_point/test_contact_point_models.py +2 -2
  43. udata/tests/dataservice/test_csv_adapter.py +2 -5
  44. udata/tests/dataservice/test_dataservice_rdf.py +3 -6
  45. udata/tests/dataservice/test_dataservice_tasks.py +36 -38
  46. udata/tests/dataset/test_csv_adapter.py +2 -5
  47. udata/tests/dataset/test_dataset_actions.py +2 -4
  48. udata/tests/dataset/test_dataset_commands.py +2 -4
  49. udata/tests/dataset/test_dataset_events.py +3 -3
  50. udata/tests/dataset/test_dataset_model.py +6 -7
  51. udata/tests/dataset/test_dataset_rdf.py +6 -9
  52. udata/tests/dataset/test_dataset_recommendations.py +2 -2
  53. udata/tests/dataset/test_dataset_tasks.py +66 -68
  54. udata/tests/dataset/test_resource_preview.py +39 -48
  55. udata/tests/dataset/test_transport_tasks.py +2 -2
  56. udata/tests/features/territories/__init__.py +0 -6
  57. udata/tests/features/territories/test_territories_api.py +25 -24
  58. udata/tests/forms/test_current_user_field.py +2 -2
  59. udata/tests/forms/test_dict_field.py +2 -4
  60. udata/tests/forms/test_extras_fields.py +2 -3
  61. udata/tests/forms/test_image_field.py +2 -2
  62. udata/tests/forms/test_model_field.py +2 -4
  63. udata/tests/forms/test_publish_as_field.py +2 -4
  64. udata/tests/forms/test_user_forms.py +26 -29
  65. udata/tests/frontend/test_auth.py +2 -3
  66. udata/tests/frontend/test_csv.py +5 -6
  67. udata/tests/frontend/test_error_handlers.py +2 -3
  68. udata/tests/frontend/test_hooks.py +5 -7
  69. udata/tests/frontend/test_markdown.py +3 -4
  70. udata/tests/helpers.py +2 -7
  71. udata/tests/metrics/test_metrics.py +52 -48
  72. udata/tests/metrics/test_tasks.py +154 -150
  73. udata/tests/organization/test_csv_adapter.py +2 -5
  74. udata/tests/organization/test_notifications.py +2 -4
  75. udata/tests/organization/test_organization_model.py +3 -4
  76. udata/tests/organization/test_organization_rdf.py +2 -8
  77. udata/tests/plugin.py +6 -110
  78. udata/tests/reuse/test_reuse_model.py +3 -4
  79. udata/tests/site/test_site_api.py +0 -2
  80. udata/tests/site/test_site_csv_exports.py +0 -2
  81. udata/tests/site/test_site_metrics.py +2 -4
  82. udata/tests/site/test_site_model.py +2 -2
  83. udata/tests/site/test_site_rdf.py +3 -6
  84. udata/tests/test_activity.py +3 -3
  85. udata/tests/test_api_fields.py +6 -9
  86. udata/tests/test_cors.py +0 -2
  87. udata/tests/test_dcat_commands.py +2 -3
  88. udata/tests/test_discussions.py +2 -7
  89. udata/tests/test_mail.py +4 -10
  90. udata/tests/test_migrations.py +413 -419
  91. udata/tests/test_model.py +10 -11
  92. udata/tests/test_notifications.py +2 -3
  93. udata/tests/test_owned.py +3 -3
  94. udata/tests/test_routing.py +5 -5
  95. udata/tests/test_storages.py +6 -5
  96. udata/tests/test_tags.py +2 -1
  97. udata/tests/test_topics.py +2 -4
  98. udata/tests/test_transfer.py +4 -5
  99. udata/tests/topic/test_topic_tasks.py +25 -27
  100. udata/tests/user/test_user_rdf.py +2 -8
  101. udata/tests/workers/test_jobs_commands.py +2 -2
  102. udata/tests/workers/test_tasks_routing.py +27 -27
  103. {udata-12.0.2.dev17.dist-info → udata-12.0.2.dev18.dist-info}/METADATA +1 -1
  104. {udata-12.0.2.dev17.dist-info → udata-12.0.2.dev18.dist-info}/RECORD +108 -110
  105. udata/tests/frontend/__init__.py +0 -23
  106. udata/tests/metrics/conftest.py +0 -15
  107. {udata-12.0.2.dev17.dist-info → udata-12.0.2.dev18.dist-info}/WHEEL +0 -0
  108. {udata-12.0.2.dev17.dist-info → udata-12.0.2.dev18.dist-info}/entry_points.txt +0 -0
  109. {udata-12.0.2.dev17.dist-info → udata-12.0.2.dev18.dist-info}/licenses/LICENSE +0 -0
  110. {udata-12.0.2.dev17.dist-info → udata-12.0.2.dev18.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,3 @@
1
- import pytest
2
1
  from flask import url_for
3
2
 
4
3
  from udata.core.contact_point.factories import ContactPointFactory
@@ -7,17 +6,12 @@ from udata.core.organization.factories import OrganizationFactory
7
6
  from udata.core.organization.models import Member
8
7
  from udata.i18n import gettext as _
9
8
  from udata.models import ContactPoint
9
+ from udata.tests.api import APITestCase
10
10
  from udata.tests.helpers import assert200, assert201, assert204, assert400, assert403
11
11
  from udata.utils import faker
12
12
 
13
- pytestmark = [
14
- pytest.mark.usefixtures("clean_db"),
15
- ]
16
-
17
-
18
- class ContactPointAPITest:
19
- modules = []
20
13
 
14
+ class ContactPointAPITest(APITestCase):
21
15
  def test_get_or_create(self):
22
16
  org = OrganizationFactory()
23
17
  contact_point, created = ContactPoint.objects().get_or_create(
@@ -51,46 +45,46 @@ class ContactPointAPITest:
51
45
  assert created
52
46
  assert contact_point.name == "Another"
53
47
 
54
- def test_contact_point_api_create(self, api):
55
- user = api.login()
48
+ def test_contact_point_api_create(self):
49
+ user = self.login()
56
50
  data = {
57
51
  "name": faker.word(),
58
52
  "email": faker.email(),
59
53
  "contact_form": faker.url(),
60
54
  "role": "contact",
61
55
  }
62
- response = api.post(url_for("api.contact_points"), data=data)
56
+ response = self.post(url_for("api.contact_points"), data=data)
63
57
  assert201(response)
64
58
  assert ContactPoint.objects.count() == 1
65
59
 
66
60
  contact_point = ContactPoint.objects.first()
67
61
  assert contact_point.owner.id == user.id
68
62
 
69
- def test_contact_point_api_create_email_or_contact_form(self, api):
70
- api.login()
63
+ def test_contact_point_api_create_email_or_contact_form(self):
64
+ self.login()
71
65
  data = {"name": faker.word(), "contact_form": faker.url(), "role": "contact"}
72
- response = api.post(url_for("api.contact_points"), data=data)
66
+ response = self.post(url_for("api.contact_points"), data=data)
73
67
  assert201(response)
74
68
  assert ContactPoint.objects.count() == 1
75
69
 
76
70
  data = {"name": faker.word(), "email": faker.email(), "role": "contact"}
77
- response = api.post(url_for("api.contact_points"), data=data)
71
+ response = self.post(url_for("api.contact_points"), data=data)
78
72
  assert201(response)
79
73
  assert ContactPoint.objects.count() == 2
80
74
 
81
- def test_contact_point_duplicate_creation(self, api):
82
- api.login()
75
+ def test_contact_point_duplicate_creation(self):
76
+ self.login()
83
77
  data = {"name": faker.word(), "contact_form": faker.url(), "role": "contact"}
84
- response = api.post(url_for("api.contact_points"), data=data)
78
+ response = self.post(url_for("api.contact_points"), data=data)
85
79
  assert201(response)
86
80
  assert ContactPoint.objects.count() == 1
87
81
 
88
- response = api.post(url_for("api.contact_points"), data=data)
82
+ response = self.post(url_for("api.contact_points"), data=data)
89
83
  assert200(response)
90
84
  assert ContactPoint.objects.count() == 1
91
85
 
92
- def test_contact_point_for_different_org(self, api):
93
- user = api.login()
86
+ def test_contact_point_for_different_org(self):
87
+ user = self.login()
94
88
  member = Member(user=user, role="editor")
95
89
  org_a = OrganizationFactory(members=[member])
96
90
 
@@ -100,11 +94,11 @@ class ContactPointAPITest:
100
94
  "role": "contact",
101
95
  "organization": str(org_a.id),
102
96
  }
103
- response = api.post(url_for("api.contact_points"), data=data)
97
+ response = self.post(url_for("api.contact_points"), data=data)
104
98
  assert201(response)
105
99
  assert ContactPoint.objects.count() == 1
106
100
 
107
- response = api.post(url_for("api.contact_points"), data=data)
101
+ response = self.post(url_for("api.contact_points"), data=data)
108
102
  assert200(response)
109
103
  assert ContactPoint.objects.count() == 1
110
104
 
@@ -114,39 +108,39 @@ class ContactPointAPITest:
114
108
 
115
109
  org_b = OrganizationFactory(members=[])
116
110
  data["organization"] = str(org_b.id)
117
- response = api.post(url_for("api.contact_points"), data=data)
111
+ response = self.post(url_for("api.contact_points"), data=data)
118
112
  assert400(response)
119
113
  assert ContactPoint.objects.count() == 1
120
114
 
121
115
  org_b.members = [Member(user=user, role="editor")]
122
116
  org_b.save()
123
117
 
124
- response = api.post(url_for("api.contact_points"), data=data)
118
+ response = self.post(url_for("api.contact_points"), data=data)
125
119
  assert201(response)
126
120
  assert ContactPoint.objects.count() == 2
127
121
 
128
- def test_contact_point_api_invalid_email(self, api):
129
- api.login()
122
+ def test_contact_point_api_invalid_email(self):
123
+ self.login()
130
124
  data = {"name": faker.word(), "email": faker.word(), "role": "contact"}
131
- response = api.post(url_for("api.contact_points"), data=data)
125
+ response = self.post(url_for("api.contact_points"), data=data)
132
126
  assert400(response)
133
127
  assert "email" in response.json["errors"]
134
128
  assert ContactPoint.objects.count() == 0
135
129
 
136
- def test_contact_point_missing_contact_information(self, api):
137
- api.login()
130
+ def test_contact_point_missing_contact_information(self):
131
+ self.login()
138
132
  data = {"name": faker.word(), "role": "contact"}
139
- response = api.post(url_for("api.contact_points"), data=data)
133
+ response = self.post(url_for("api.contact_points"), data=data)
140
134
  assert400(response)
141
135
  assert response.json["message"] == _(
142
136
  "At least an email or a contact form is required for a contact point"
143
137
  )
144
138
  assert ContactPoint.objects.count() == 0
145
139
 
146
- def test_contact_point_missing_role(self, api):
147
- api.login()
140
+ def test_contact_point_missing_role(self):
141
+ self.login()
148
142
  data = {"name": faker.word(), "email": faker.email()}
149
- response = api.post(url_for("api.contact_points"), data=data)
143
+ response = self.post(url_for("api.contact_points"), data=data)
150
144
  assert400(response)
151
145
  assert (
152
146
  response.json["message"]
@@ -154,70 +148,70 @@ class ContactPointAPITest:
154
148
  )
155
149
  assert ContactPoint.objects.count() == 0
156
150
 
157
- def test_contact_point_no_need_for_email_for_role_other_than_contact(self, api):
158
- api.login()
151
+ def test_contact_point_no_need_for_email_for_role_other_than_contact(self):
152
+ self.login()
159
153
  roles_other_than_contact = [role_ for role_ in CONTACT_ROLES.keys() if role_ != "contact"]
160
154
  for index, role in enumerate(roles_other_than_contact):
161
155
  data = {"name": faker.word(), "role": role}
162
- response = api.post(url_for("api.contact_points"), data=data)
156
+ response = self.post(url_for("api.contact_points"), data=data)
163
157
  assert201(response)
164
158
  assert ContactPoint.objects.count() == index + 1
165
159
 
166
- def test_contact_point_api_update(self, api):
167
- user = api.login()
160
+ def test_contact_point_api_update(self):
161
+ user = self.login()
168
162
  member = Member(user=user, role="editor")
169
163
  org = OrganizationFactory(members=[member])
170
164
  contact_point = ContactPointFactory(organization=org)
171
165
  data = contact_point.to_dict()
172
166
  data["email"] = "new.email@newdomain.com"
173
- response = api.put(url_for("api.contact_point", contact_point=contact_point), data)
167
+ response = self.put(url_for("api.contact_point", contact_point=contact_point), data)
174
168
  assert200(response)
175
169
  assert ContactPoint.objects.count() == 1
176
170
  assert ContactPoint.objects.first().email == "new.email@newdomain.com"
177
171
 
178
- def test_contact_point_api_update_to_existing_contact_point(self, api):
179
- user = api.login()
172
+ def test_contact_point_api_update_to_existing_contact_point(self):
173
+ user = self.login()
180
174
  contact_point_a = ContactPointFactory(email="a@example.org", owner=user)
181
175
  contact_point_b = ContactPointFactory(email="b@example.org", owner=user)
182
176
 
183
177
  data_b = contact_point_b.to_dict()
184
- response = api.put(url_for("api.contact_point", contact_point=contact_point_a), data_b)
178
+ response = self.put(url_for("api.contact_point", contact_point=contact_point_a), data_b)
185
179
  assert400(response)
186
180
  assert ContactPoint.objects.count() == 2
187
181
 
188
182
  contact_point_a.reload()
189
183
  assert contact_point_a.email == "a@example.org"
190
184
 
191
- def test_contact_point_api_update_forbidden(self, api):
192
- api.login()
185
+ def test_contact_point_api_update_forbidden(self):
186
+ self.login()
193
187
  org = OrganizationFactory()
194
188
  contact_point = ContactPointFactory(organization=org)
195
189
  data = contact_point.to_dict()
196
190
  data["email"] = "new.email@newdomain.com"
197
- response = api.put(url_for("api.contact_point", contact_point=contact_point), data)
191
+ response = self.put(url_for("api.contact_point", contact_point=contact_point), data)
198
192
  assert403(response)
199
193
  assert ContactPoint.objects.count() == 1
200
194
  assert ContactPoint.objects.first().email == contact_point.email
201
195
 
202
- def test_contact_point_api_delete(self, api):
203
- user = api.login()
196
+ def test_contact_point_api_delete(self):
197
+ user = self.login()
204
198
  member = Member(user=user, role="editor")
205
199
  org = OrganizationFactory(members=[member])
206
200
  contact_point = ContactPointFactory(organization=org)
207
- response = api.delete(url_for("api.contact_point", contact_point=contact_point))
201
+ response = self.delete(url_for("api.contact_point", contact_point=contact_point))
208
202
  assert204(response)
209
203
  assert ContactPoint.objects.count() == 0
210
204
 
211
- def test_contact_point_roles_list(self, api):
205
+ def test_contact_point_roles_list(self):
212
206
  """It should fetch the contact point roles list from the API"""
213
- response = api.get(url_for("api.contact_point_roles"))
207
+ response = self.get(url_for("api.contact_point_roles"))
214
208
  assert200(response)
215
209
  assert len(response.json) == len(CONTACT_ROLES)
216
210
 
217
- def test_contact_point_api_delete_forbidden(self, api):
218
- api.login()
211
+ def test_contact_point_api_delete_forbidden(self):
212
+ self.login()
219
213
  org = OrganizationFactory()
220
214
  contact_point = ContactPointFactory(organization=org)
221
- response = api.delete(url_for("api.contact_point", contact_point=contact_point))
215
+ response = self.delete(url_for("api.contact_point", contact_point=contact_point))
222
216
  assert403(response)
223
217
  assert ContactPoint.objects.count() == 1
@@ -34,8 +34,6 @@ def dataservice_in_response(response: TestResponse, dataservice: Dataservice) ->
34
34
 
35
35
 
36
36
  class DataserviceAPITest(APITestCase):
37
- modules = []
38
-
39
37
  def test_dataservice_api_get(self):
40
38
  """It should fetch a dataservice from the API"""
41
39
  dataservice = DataserviceFactory()
@@ -47,7 +47,7 @@ from udata.tests.features.territories import create_geozones_fixtures
47
47
  from udata.tests.helpers import assert200, assert404
48
48
  from udata.utils import faker, unique_string
49
49
 
50
- from . import APITestCase
50
+ from . import APITestCase, PytestOnlyAPITestCase
51
51
 
52
52
  SAMPLE_GEOM = {
53
53
  "type": "MultiPolygon",
@@ -67,8 +67,6 @@ def dataset_in_response(response: TestResponse, dataset: Dataset) -> bool:
67
67
 
68
68
 
69
69
  class DatasetAPITest(APITestCase):
70
- modules = []
71
-
72
70
  def test_dataset_api_list(self):
73
71
  """It should fetch a dataset list from the API"""
74
72
  datasets = [DatasetFactory() for i in range(2)]
@@ -1505,8 +1503,6 @@ class DatasetBadgeAPITest(APITestCase):
1505
1503
 
1506
1504
 
1507
1505
  class DatasetResourceAPITest(APITestCase):
1508
- modules = None
1509
-
1510
1506
  def setUp(self):
1511
1507
  self.login()
1512
1508
  self.dataset = DatasetFactory(owner=self.user)
@@ -1957,7 +1953,7 @@ class DatasetResourceAPITest(APITestCase):
1957
1953
 
1958
1954
  @pytest.mark.options(ALLOWED_RESOURCES_EXTENSIONS=["txt", "html", "kml", "kml-1", "qml", "xml"])
1959
1955
  def test_suggest_formats_api(self):
1960
- response = self.get(url_for("api.suggest_formats"), qs={"q": "km", "size": "5"})
1956
+ response = self.get(url_for("api.suggest_formats", q="km", size=5))
1961
1957
  self.assert200(response)
1962
1958
 
1963
1959
  self.assertEqual(len(response.json), 2)
@@ -1966,14 +1962,14 @@ class DatasetResourceAPITest(APITestCase):
1966
1962
 
1967
1963
  @pytest.mark.options(ALLOWED_RESOURCES_EXTENSIONS=["txt", "html", "kml", "kml-1", "qml", "xml"])
1968
1964
  def test_suggest_format_api_no_match(self):
1969
- response = self.get(url_for("api.suggest_formats"), qs={"q": "test", "size": "5"})
1965
+ response = self.get(url_for("api.suggest_formats", q="test", size=5))
1970
1966
  self.assert200(response)
1971
1967
  self.assertEqual(len(response.json), 0)
1972
1968
 
1973
1969
  @pytest.mark.options(ALLOWED_RESOURCES_EXTENSIONS=[])
1974
1970
  def test_suggest_format_api_empty(self):
1975
1971
  """It should not provide format suggestion if no data"""
1976
- response = self.get(url_for("api.suggest_formats"), qs={"q": "txt", "size": "5"})
1972
+ response = self.get(url_for("api.suggest_formats", q="txt", size=5))
1977
1973
  self.assert200(response)
1978
1974
  self.assertEqual(len(response.json), 0)
1979
1975
 
@@ -1991,7 +1987,7 @@ class DatasetResourceAPITest(APITestCase):
1991
1987
  ]
1992
1988
  )
1993
1989
 
1994
- response = self.get(url_for("api.suggest_mime"), qs={"q": "js", "size": "5"})
1990
+ response = self.get(url_for("api.suggest_mime", q="js", size=5))
1995
1991
  self.assert200(response)
1996
1992
  self.assertLessEqual(len(response.json), 5)
1997
1993
 
@@ -2002,7 +1998,7 @@ class DatasetResourceAPITest(APITestCase):
2002
1998
  """It should suggest mime types"""
2003
1999
  DatasetFactory(resources=[ResourceFactory(mime="application/xhtml+xml")])
2004
2000
 
2005
- response = self.get(url_for("api.suggest_mime"), qs={"q": "xml", "size": "5"})
2001
+ response = self.get(url_for("api.suggest_mime", q="xml", size=5))
2006
2002
  self.assert200(response)
2007
2003
 
2008
2004
  self.assertEqual(len(response.json), 5)
@@ -2011,13 +2007,13 @@ class DatasetResourceAPITest(APITestCase):
2011
2007
  """It should not provide format suggestion if no match"""
2012
2008
  DatasetFactory(resources=[ResourceFactory(mime=faker.word()) for _ in range(3)])
2013
2009
 
2014
- response = self.get(url_for("api.suggest_mime"), qs={"q": "test", "size": "5"})
2010
+ response = self.get(url_for("api.suggest_mime", q="test", size=5))
2015
2011
  self.assert200(response)
2016
2012
  self.assertEqual(len(response.json), 0)
2017
2013
 
2018
2014
  def test_suggest_mime_api_empty(self):
2019
2015
  """It should not provide mime suggestion if no data"""
2020
- response = self.get(url_for("api.suggest_mime"), qs={"q": "test", "size": "5"})
2016
+ response = self.get(url_for("api.suggest_mime", q="test", size=5))
2021
2017
  self.assert200(response)
2022
2018
  self.assertEqual(len(response.json), 0)
2023
2019
 
@@ -2033,7 +2029,7 @@ class DatasetResourceAPITest(APITestCase):
2033
2029
  title="title-test-4", visible=True, metrics={"followers": 10}
2034
2030
  )
2035
2031
 
2036
- response = self.get(url_for("api.suggest_datasets"), qs={"q": "title-test", "size": "5"})
2032
+ response = self.get(url_for("api.suggest_datasets", q="title-test", size=5))
2037
2033
  self.assert200(response)
2038
2034
 
2039
2035
  self.assertLessEqual(len(response.json), 5)
@@ -2056,7 +2052,7 @@ class DatasetResourceAPITest(APITestCase):
2056
2052
  visible=True,
2057
2053
  )
2058
2054
 
2059
- response = self.get(url_for("api.suggest_datasets"), qs={"q": "acronym-test", "size": "5"})
2055
+ response = self.get(url_for("api.suggest_datasets", q="acronym-test", size=5))
2060
2056
  self.assert200(response)
2061
2057
 
2062
2058
  self.assertLessEqual(len(response.json), 5)
@@ -2078,7 +2074,7 @@ class DatasetResourceAPITest(APITestCase):
2078
2074
  resources=[ResourceFactory()],
2079
2075
  )
2080
2076
 
2081
- response = self.get(url_for("api.suggest_datasets"), qs={"q": "title-testé", "size": "5"})
2077
+ response = self.get(url_for("api.suggest_datasets", q="title-testé", size=5))
2082
2078
  self.assert200(response)
2083
2079
 
2084
2080
  self.assertLessEqual(len(response.json), 5)
@@ -2096,13 +2092,13 @@ class DatasetResourceAPITest(APITestCase):
2096
2092
  for i in range(3):
2097
2093
  DatasetFactory(resources=[ResourceFactory()])
2098
2094
 
2099
- response = self.get(url_for("api.suggest_datasets"), qs={"q": "xxxxxx", "size": "5"})
2095
+ response = self.get(url_for("api.suggest_datasets", q="xxxxxx", size=5))
2100
2096
  self.assert200(response)
2101
2097
  self.assertEqual(len(response.json), 0)
2102
2098
 
2103
2099
  def test_suggest_datasets_api_empty(self):
2104
2100
  """It should not provide dataset suggestion if no data"""
2105
- response = self.get(url_for("api.suggest_datasets"), qs={"q": "xxxxxx", "size": "5"})
2101
+ response = self.get(url_for("api.suggest_datasets", q="xxxxxx", size=5))
2106
2102
  self.assert200(response)
2107
2103
  self.assertEqual(len(response.json), 0)
2108
2104
 
@@ -2132,8 +2128,6 @@ class DatasetReferencesAPITest(APITestCase):
2132
2128
 
2133
2129
 
2134
2130
  class DatasetArchivedAPITest(APITestCase):
2135
- modules = []
2136
-
2137
2131
  def test_dataset_api_search_archived(self):
2138
2132
  """It should search datasets from the API, excluding archived ones"""
2139
2133
  DatasetFactory(archived=None)
@@ -2152,8 +2146,6 @@ class DatasetArchivedAPITest(APITestCase):
2152
2146
 
2153
2147
 
2154
2148
  class CommunityResourceAPITest(APITestCase):
2155
- modules = []
2156
-
2157
2149
  def test_community_resource_api_get(self):
2158
2150
  """It should fetch a community resource from the API"""
2159
2151
  community_resource = CommunityResourceFactory()
@@ -2407,10 +2399,7 @@ class ResourcesTypesAPITest(APITestCase):
2407
2399
  self.assertEqual(len(response.json), len(RESOURCE_TYPES))
2408
2400
 
2409
2401
 
2410
- @pytest.mark.usefixtures("clean_db")
2411
- class DatasetSchemasAPITest:
2412
- modules = []
2413
-
2402
+ class DatasetSchemasAPITest(PytestOnlyAPITestCase):
2414
2403
  def test_dataset_schemas_api_list(self, api, rmock, app):
2415
2404
  # Can't use @pytest.mark.options otherwise a request will be
2416
2405
  # made before setting up rmock at module load, resulting in a 404
@@ -2471,10 +2460,7 @@ class DatasetSchemasAPITest:
2471
2460
  )
2472
2461
 
2473
2462
 
2474
- @pytest.mark.usefixtures("clean_db")
2475
- class HarvestMetadataAPITest:
2476
- modules = []
2477
-
2463
+ class HarvestMetadataAPITest(PytestOnlyAPITestCase):
2478
2464
  def test_dataset_with_harvest_metadata(self, api):
2479
2465
  date = datetime(2022, 2, 22, tzinfo=pytz.UTC)
2480
2466
  harvest_metadata = HarvestDatasetMetadata(
@@ -18,8 +18,6 @@ from . import APITestCase
18
18
 
19
19
 
20
20
  class MeAPITest(APITestCase):
21
- modules = []
22
-
23
21
  def test_get_profile(self):
24
22
  """It should fetch my user data on GET"""
25
23
  self.login()
@@ -105,7 +103,7 @@ class MeAPITest(APITestCase):
105
103
  DatasetFactory(owner=user)
106
104
  DatasetFactory(organization=organization)
107
105
 
108
- response = self.get(url_for("api.my_org_datasets"), qs={"q": "foô"})
106
+ response = self.get(url_for("api.my_org_datasets", q="foô"))
109
107
  self.assert200(response)
110
108
  self.assertEqual(len(response.json), len(datasets) + len(org_datasets))
111
109
 
@@ -139,7 +137,7 @@ class MeAPITest(APITestCase):
139
137
  CommunityResourceFactory(owner=user)
140
138
  CommunityResourceFactory(organization=organization)
141
139
 
142
- response = self.get(url_for("api.my_org_community_resources"), qs={"q": "foô"})
140
+ response = self.get(url_for("api.my_org_community_resources", q="foô"))
143
141
  self.assert200(response)
144
142
  self.assertEqual(
145
143
  len(response.json), len(community_resources) + len(org_community_resources)
@@ -171,7 +169,7 @@ class MeAPITest(APITestCase):
171
169
  ReuseFactory(owner=user)
172
170
  ReuseFactory(organization=organization)
173
171
 
174
- response = self.get(url_for("api.my_org_reuses"), qs={"q": "foô"})
172
+ response = self.get(url_for("api.my_org_reuses", q="foô"))
175
173
  self.assert200(response)
176
174
  self.assertEqual(len(response.json), len(reuses) + len(org_reuses))
177
175
 
@@ -221,7 +219,7 @@ class MeAPITest(APITestCase):
221
219
  Discussion.objects.create(subject=DatasetFactory(), title="foô", user=user)
222
220
  Discussion.objects.create(subject=ReuseFactory(), title="foô", user=user)
223
221
 
224
- response = self.get(url_for("api.my_org_discussions"), qs={"q": "foô"})
222
+ response = self.get(url_for("api.my_org_discussions", q="foô"))
225
223
  self.assert200(response)
226
224
  self.assertEqual(len(response.json), len(discussions))
227
225
 
@@ -16,6 +16,7 @@ from udata.core.reuse.factories import ReuseFactory
16
16
  from udata.core.user.factories import AdminFactory, UserFactory
17
17
  from udata.i18n import _
18
18
  from udata.models import Discussion, Follow, Member, MembershipRequest, Organization
19
+ from udata.tests.api import PytestOnlyAPITestCase
19
20
  from udata.tests.helpers import (
20
21
  assert200,
21
22
  assert201,
@@ -31,14 +32,8 @@ from udata.tests.helpers import (
31
32
  )
32
33
  from udata.utils import faker
33
34
 
34
- pytestmark = [
35
- pytest.mark.usefixtures("clean_db"),
36
- ]
37
-
38
-
39
- class OrganizationAPITest:
40
- modules = []
41
35
 
36
+ class OrganizationAPITest(PytestOnlyAPITestCase):
42
37
  def test_organization_api_list(self, api):
43
38
  """It should fetch an organization list from the API"""
44
39
  organizations = OrganizationFactory.create_batch(3)
@@ -235,9 +230,7 @@ class OrganizationAPITest:
235
230
  assert Organization.objects[0].deleted is None
236
231
 
237
232
 
238
- class MembershipAPITest:
239
- modules = []
240
-
233
+ class MembershipAPITest(PytestOnlyAPITestCase):
241
234
  def test_request_membership(self, api):
242
235
  organization = OrganizationFactory()
243
236
  user = api.login()
@@ -678,7 +671,7 @@ class MembershipAPITest:
678
671
  name="test-{0}".format(i) if i % 2 else faker.word(), metrics={"followers": i}
679
672
  )
680
673
  max_follower_organization = OrganizationFactory(name="test-4", metrics={"followers": 10})
681
- response = api.get(url_for("api.suggest_organizations"), qs={"q": "tes", "size": "5"})
674
+ response = api.get(url_for("api.suggest_organizations", q="tes", size=5))
682
675
  assert200(response)
683
676
 
684
677
  assert len(response.json) <= 5
@@ -698,7 +691,7 @@ class MembershipAPITest:
698
691
  for i in range(4):
699
692
  OrganizationFactory(name="testé-{0}".format(i) if i % 2 else faker.word())
700
693
 
701
- response = api.get(url_for("api.suggest_organizations"), qs={"q": "testé", "size": "5"})
694
+ response = api.get(url_for("api.suggest_organizations", q="testé", size=5))
702
695
  assert200(response)
703
696
 
704
697
  assert len(response.json) <= 5
@@ -716,7 +709,7 @@ class MembershipAPITest:
716
709
  for i in range(4):
717
710
  OrganizationFactory(name="mon testé-{0}".format(i) if i % 2 else faker.word())
718
711
 
719
- response = api.get(url_for("api.suggest_organizations"), qs={"q": "mon testé", "size": "5"})
712
+ response = api.get(url_for("api.suggest_organizations", q="mon testé", size=5))
720
713
  assert200(response)
721
714
 
722
715
  assert len(response.json) <= 5
@@ -736,7 +729,7 @@ class MembershipAPITest:
736
729
  name="Ministère de l'intérieur {0}".format(i) if i % 2 else faker.word()
737
730
  )
738
731
 
739
- response = api.get(url_for("api.suggest_organizations"), qs={"q": "Ministère", "size": "5"})
732
+ response = api.get(url_for("api.suggest_organizations", q="Ministère", size=5))
740
733
  assert200(response)
741
734
 
742
735
  assert len(response.json) <= 5
@@ -753,13 +746,13 @@ class MembershipAPITest:
753
746
  """It should not provide organization suggestion if no match"""
754
747
  OrganizationFactory.create_batch(3)
755
748
 
756
- response = api.get(url_for("api.suggest_organizations"), qs={"q": "xxxxxx", "size": "5"})
749
+ response = api.get(url_for("api.suggest_organizations", q="xxxxxx", size=5))
757
750
  assert200(response)
758
751
  assert len(response.json) == 0
759
752
 
760
753
  def test_suggest_organizations_api_empty(self, api):
761
754
  """It should not provide organization suggestion if no data"""
762
- response = api.get(url_for("api.suggest_organizations"), qs={"q": "xxxxxx", "size": "5"})
755
+ response = api.get(url_for("api.suggest_organizations", q="xxxxxx", size=5))
763
756
  assert200(response)
764
757
  assert len(response.json) == 0
765
758
 
@@ -767,7 +760,7 @@ class MembershipAPITest:
767
760
  """It should suggest organizations and not deduplicate homonyms"""
768
761
  OrganizationFactory.create_batch(2, name="homonym")
769
762
 
770
- response = api.get(url_for("api.suggest_organizations"), qs={"q": "homonym", "size": "5"})
763
+ response = api.get(url_for("api.suggest_organizations", q="homonym", size=5))
771
764
  assert200(response)
772
765
 
773
766
  assert len(response.json) == 2
@@ -787,7 +780,7 @@ class MembershipAPITest:
787
780
  max_follower_organization = OrganizationFactory(
788
781
  name=faker.word(), acronym="UDATA4", metrics={"followers": 10}
789
782
  )
790
- response = api.get(url_for("api.suggest_organizations"), qs={"q": "uDaTa", "size": "5"})
783
+ response = api.get(url_for("api.suggest_organizations", q="uDaTa", size=5))
791
784
  assert200(response)
792
785
 
793
786
  assert len(response.json) == 2
@@ -802,9 +795,7 @@ class MembershipAPITest:
802
795
  assert response.json[0]["id"] == str(max_follower_organization.id)
803
796
 
804
797
 
805
- class OrganizationDatasetsAPITest:
806
- modules = []
807
-
798
+ class OrganizationDatasetsAPITest(PytestOnlyAPITestCase):
808
799
  def test_list_org_datasets(self, api):
809
800
  """Should list organization datasets"""
810
801
  org = OrganizationFactory()
@@ -843,15 +834,13 @@ class OrganizationDatasetsAPITest:
843
834
  org = OrganizationFactory()
844
835
  DatasetFactory.create_batch(3, organization=org)
845
836
 
846
- response = api.get(url_for("api.org_datasets", org=org), qs={"page_size": 2})
837
+ response = api.get(url_for("api.org_datasets", org=org, page_size=2))
847
838
 
848
839
  assert200(response)
849
840
  assert len(response.json["data"]) == 2
850
841
 
851
842
 
852
- class OrganizationReusesAPITest:
853
- modules = []
854
-
843
+ class OrganizationReusesAPITest(PytestOnlyAPITestCase):
855
844
  def test_list_org_reuses(self, api):
856
845
  """Should list organization reuses"""
857
846
  org = OrganizationFactory()
@@ -886,9 +875,7 @@ class OrganizationReusesAPITest:
886
875
  assert len(response.json) == len(reuses)
887
876
 
888
877
 
889
- class OrganizationDiscussionsAPITest:
890
- modules = []
891
-
878
+ class OrganizationDiscussionsAPITest(PytestOnlyAPITestCase):
892
879
  def test_list_org_discussions(self, api):
893
880
  """Should list organization discussions"""
894
881
  user = UserFactory()
@@ -910,11 +897,9 @@ class OrganizationDiscussionsAPITest:
910
897
  assert discussion["id"] in discussions_ids
911
898
 
912
899
 
913
- class OrganizationBadgeAPITest:
914
- modules = []
915
-
900
+ class OrganizationBadgeAPITest(PytestOnlyAPITestCase):
916
901
  @pytest.fixture(autouse=True)
917
- def setUp(self, api, clean_db):
902
+ def setup_func(self, api):
918
903
  self.factory = badge_factory(Organization)
919
904
  self.user = api.login(AdminFactory())
920
905
  self.organization = OrganizationFactory()
@@ -978,9 +963,7 @@ class OrganizationBadgeAPITest:
978
963
  assert404(response)
979
964
 
980
965
 
981
- class OrganizationContactPointsAPITest:
982
- modules = []
983
-
966
+ class OrganizationContactPointsAPITest(PytestOnlyAPITestCase):
984
967
  def test_org_contact_points(self, api):
985
968
  user = api.login()
986
969
  member = Member(user=user, role="admin")
@@ -1027,9 +1010,7 @@ class OrganizationContactPointsAPITest:
1027
1010
  assert len(response.json) == 0
1028
1011
 
1029
1012
 
1030
- class OrganizationCsvExportsTest:
1031
- modules = []
1032
-
1013
+ class OrganizationCsvExportsTest(PytestOnlyAPITestCase):
1033
1014
  def test_datasets_csv(self, api):
1034
1015
  org = OrganizationFactory()
1035
1016
  [DatasetFactory(organization=org, resources=[ResourceFactory()]) for _ in range(3)]
@@ -15,8 +15,6 @@ from . import APITestCase
15
15
 
16
16
 
17
17
  class ReportsReasonsAPITest(APITestCase):
18
- modules = []
19
-
20
18
  def test_reports_reasons_api(self):
21
19
  response = self.get(url_for("api.reports_reasons"))
22
20
  self.assert200(response)
@@ -24,8 +22,6 @@ class ReportsReasonsAPITest(APITestCase):
24
22
 
25
23
 
26
24
  class ReportsAPITest(APITestCase):
27
- modules = []
28
-
29
25
  def test_reports_api_create(self):
30
26
  user = UserFactory()
31
27