udata 12.0.2.dev16__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 (116) hide show
  1. udata/commands/tests/test_fixtures.py +6 -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/forms/fields.py +3 -3
  10. udata/forms/widgets.py +2 -2
  11. udata/harvest/tests/ckan/test_ckan_backend.py +300 -337
  12. udata/harvest/tests/ckan/test_ckan_backend_errors.py +94 -99
  13. udata/harvest/tests/ckan/test_ckan_backend_filters.py +128 -122
  14. udata/harvest/tests/ckan/test_dkan_backend.py +39 -51
  15. udata/harvest/tests/test_actions.py +7 -7
  16. udata/harvest/tests/test_api.py +2 -4
  17. udata/harvest/tests/test_base_backend.py +3 -4
  18. udata/harvest/tests/test_dcat_backend.py +5 -16
  19. udata/harvest/tests/test_models.py +2 -4
  20. udata/harvest/tests/test_notifications.py +2 -4
  21. udata/harvest/tests/test_tasks.py +2 -3
  22. udata/mongo/taglist_field.py +3 -3
  23. udata/settings.py +3 -0
  24. udata/tags.py +5 -5
  25. udata/tests/__init__.py +40 -58
  26. udata/tests/api/__init__.py +87 -2
  27. udata/tests/api/test_activities_api.py +17 -23
  28. udata/tests/api/test_auth_api.py +2 -4
  29. udata/tests/api/test_contact_points.py +48 -54
  30. udata/tests/api/test_dataservices_api.py +0 -2
  31. udata/tests/api/test_datasets_api.py +27 -49
  32. udata/tests/api/test_me_api.py +4 -6
  33. udata/tests/api/test_organizations_api.py +19 -38
  34. udata/tests/api/test_reports_api.py +0 -4
  35. udata/tests/api/test_reuses_api.py +9 -19
  36. udata/tests/api/test_swagger.py +2 -3
  37. udata/tests/api/test_tags_api.py +6 -7
  38. udata/tests/api/test_transfer_api.py +0 -2
  39. udata/tests/api/test_user_api.py +8 -10
  40. udata/tests/apiv2/test_datasets.py +0 -4
  41. udata/tests/apiv2/test_me_api.py +0 -2
  42. udata/tests/apiv2/test_organizations.py +0 -2
  43. udata/tests/apiv2/test_swagger.py +2 -3
  44. udata/tests/apiv2/test_topics.py +0 -2
  45. udata/tests/cli/test_cli_base.py +14 -12
  46. udata/tests/cli/test_db_cli.py +51 -54
  47. udata/tests/contact_point/test_contact_point_models.py +2 -2
  48. udata/tests/dataservice/test_csv_adapter.py +2 -5
  49. udata/tests/dataservice/test_dataservice_rdf.py +3 -6
  50. udata/tests/dataservice/test_dataservice_tasks.py +36 -38
  51. udata/tests/dataset/test_csv_adapter.py +2 -5
  52. udata/tests/dataset/test_dataset_actions.py +2 -4
  53. udata/tests/dataset/test_dataset_commands.py +2 -4
  54. udata/tests/dataset/test_dataset_events.py +3 -3
  55. udata/tests/dataset/test_dataset_model.py +6 -7
  56. udata/tests/dataset/test_dataset_rdf.py +6 -9
  57. udata/tests/dataset/test_dataset_recommendations.py +2 -2
  58. udata/tests/dataset/test_dataset_tasks.py +66 -68
  59. udata/tests/dataset/test_resource_preview.py +39 -48
  60. udata/tests/dataset/test_transport_tasks.py +2 -2
  61. udata/tests/features/territories/__init__.py +0 -6
  62. udata/tests/features/territories/test_territories_api.py +25 -24
  63. udata/tests/forms/test_current_user_field.py +2 -2
  64. udata/tests/forms/test_dict_field.py +2 -4
  65. udata/tests/forms/test_extras_fields.py +2 -3
  66. udata/tests/forms/test_image_field.py +2 -2
  67. udata/tests/forms/test_model_field.py +2 -4
  68. udata/tests/forms/test_publish_as_field.py +2 -4
  69. udata/tests/forms/test_user_forms.py +26 -29
  70. udata/tests/frontend/test_auth.py +2 -3
  71. udata/tests/frontend/test_csv.py +5 -6
  72. udata/tests/frontend/test_error_handlers.py +2 -3
  73. udata/tests/frontend/test_hooks.py +5 -7
  74. udata/tests/frontend/test_markdown.py +3 -4
  75. udata/tests/helpers.py +2 -7
  76. udata/tests/metrics/test_metrics.py +52 -48
  77. udata/tests/metrics/test_tasks.py +154 -150
  78. udata/tests/organization/test_csv_adapter.py +2 -5
  79. udata/tests/organization/test_notifications.py +2 -4
  80. udata/tests/organization/test_organization_model.py +3 -4
  81. udata/tests/organization/test_organization_rdf.py +2 -8
  82. udata/tests/plugin.py +6 -110
  83. udata/tests/reuse/test_reuse_model.py +3 -4
  84. udata/tests/site/test_site_api.py +0 -2
  85. udata/tests/site/test_site_csv_exports.py +0 -2
  86. udata/tests/site/test_site_metrics.py +2 -4
  87. udata/tests/site/test_site_model.py +2 -2
  88. udata/tests/site/test_site_rdf.py +3 -6
  89. udata/tests/test_activity.py +3 -3
  90. udata/tests/test_api_fields.py +6 -9
  91. udata/tests/test_cors.py +0 -2
  92. udata/tests/test_dcat_commands.py +2 -3
  93. udata/tests/test_discussions.py +2 -7
  94. udata/tests/test_mail.py +4 -10
  95. udata/tests/test_migrations.py +413 -419
  96. udata/tests/test_model.py +10 -11
  97. udata/tests/test_notifications.py +2 -3
  98. udata/tests/test_owned.py +3 -3
  99. udata/tests/test_routing.py +5 -5
  100. udata/tests/test_storages.py +6 -5
  101. udata/tests/test_tags.py +2 -4
  102. udata/tests/test_topics.py +2 -4
  103. udata/tests/test_transfer.py +4 -5
  104. udata/tests/topic/test_topic_tasks.py +25 -27
  105. udata/tests/user/test_user_rdf.py +2 -8
  106. udata/tests/workers/test_jobs_commands.py +2 -2
  107. udata/tests/workers/test_tasks_routing.py +27 -27
  108. udata/utils.py +1 -1
  109. {udata-12.0.2.dev16.dist-info → udata-12.0.2.dev18.dist-info}/METADATA +1 -1
  110. {udata-12.0.2.dev16.dist-info → udata-12.0.2.dev18.dist-info}/RECORD +114 -116
  111. udata/tests/frontend/__init__.py +0 -23
  112. udata/tests/metrics/conftest.py +0 -15
  113. {udata-12.0.2.dev16.dist-info → udata-12.0.2.dev18.dist-info}/WHEEL +0 -0
  114. {udata-12.0.2.dev16.dist-info → udata-12.0.2.dev18.dist-info}/entry_points.txt +0 -0
  115. {udata-12.0.2.dev16.dist-info → udata-12.0.2.dev18.dist-info}/licenses/LICENSE +0 -0
  116. {udata-12.0.2.dev16.dist-info → udata-12.0.2.dev18.dist-info}/top_level.txt +0 -0
@@ -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
 
@@ -13,7 +13,7 @@ from udata.core.reuse.constants import REUSE_TOPICS, REUSE_TYPES
13
13
  from udata.core.reuse.factories import ReuseFactory
14
14
  from udata.core.user.factories import AdminFactory, UserFactory
15
15
  from udata.models import Follow, Member, Reuse
16
- from udata.tests.api import APITestCase
16
+ from udata.tests.api import APITestCase, PytestOnlyAPITestCase
17
17
  from udata.tests.helpers import (
18
18
  assert200,
19
19
  assert201,
@@ -24,19 +24,13 @@ from udata.tests.helpers import (
24
24
  )
25
25
  from udata.utils import faker
26
26
 
27
- pytestmark = [
28
- pytest.mark.usefixtures("clean_db"),
29
- ]
30
-
31
27
 
32
28
  def reuse_in_response(response: TestResponse, reuse: Reuse) -> bool:
33
29
  only_reuse = [r for r in response.json["data"] if r["id"] == str(reuse.id)]
34
30
  return len(only_reuse) > 0
35
31
 
36
32
 
37
- class ReuseAPITest:
38
- modules = []
39
-
33
+ class ReuseAPITest(PytestOnlyAPITestCase):
40
34
  def test_reuse_api_list(self, api):
41
35
  """It should fetch a reuse list from the API"""
42
36
  reuses = ReuseFactory.create_batch(3, visible=True)
@@ -523,7 +517,7 @@ class ReuseAPITest:
523
517
  title="arealtestprefix-4", visible=True, metrics={"followers": 10}
524
518
  )
525
519
 
526
- response = api.get(url_for("api.suggest_reuses"), qs={"q": "arealtestpref", "size": "5"})
520
+ response = api.get(url_for("api.suggest_reuses", q="arealtestpref", size=5))
527
521
  assert200(response)
528
522
 
529
523
  assert len(response.json) <= 5
@@ -542,7 +536,7 @@ class ReuseAPITest:
542
536
  for i in range(4):
543
537
  ReuseFactory(title="testé-{0}".format(i) if i % 2 else faker.word(), visible=True)
544
538
 
545
- response = api.get(url_for("api.suggest_reuses"), qs={"q": "testé", "size": "5"})
539
+ response = api.get(url_for("api.suggest_reuses", q="testé", size=5))
546
540
  assert200(response)
547
541
 
548
542
  assert len(response.json) <= 5
@@ -559,14 +553,14 @@ class ReuseAPITest:
559
553
  """It should not provide reuse suggestion if no match"""
560
554
  ReuseFactory.create_batch(3, visible=True)
561
555
 
562
- response = api.get(url_for("api.suggest_reuses"), qs={"q": "xxxxxx", "size": "5"})
556
+ response = api.get(url_for("api.suggest_reuses", q="xxxxxx", size=5))
563
557
  assert200(response)
564
558
  assert len(response.json) == 0
565
559
 
566
560
  def test_suggest_reuses_api_empty(self, api):
567
561
  """It should not provide reuse suggestion if no data"""
568
562
  # self.init_search()
569
- response = api.get(url_for("api.suggest_reuses"), qs={"q": "xxxxxx", "size": "5"})
563
+ response = api.get(url_for("api.suggest_reuses", q="xxxxxx", size=5))
570
564
  assert200(response)
571
565
  assert len(response.json) == 0
572
566
 
@@ -630,11 +624,9 @@ class ReusesFeedAPItest(APITestCase):
630
624
  self.assertEqual(author.href, org.url_for())
631
625
 
632
626
 
633
- class ReuseBadgeAPITest:
634
- modules = []
635
-
627
+ class ReuseBadgeAPITest(PytestOnlyAPITestCase):
636
628
  @pytest.fixture(autouse=True)
637
- def setup(self, api, clean_db):
629
+ def setup_func(self, api):
638
630
  # Register at least two badges
639
631
  Reuse.__badges__["test-1"] = "Test 1"
640
632
  Reuse.__badges__["test-2"] = "Test 2"
@@ -695,9 +687,7 @@ class ReuseBadgeAPITest:
695
687
  assert404(response)
696
688
 
697
689
 
698
- class ReuseReferencesAPITest:
699
- modules = []
700
-
690
+ class ReuseReferencesAPITest(PytestOnlyAPITestCase):
701
691
  def test_reuse_types_list(self, api):
702
692
  """It should fetch the reuse types list from the API"""
703
693
  response = api.get(url_for("api.reuse_types"))
@@ -3,12 +3,11 @@ import json
3
3
  from flask import url_for
4
4
  from flask_restx import schemas
5
5
 
6
+ from udata.tests.api import PytestOnlyAPITestCase
6
7
  from udata.tests.helpers import assert200
7
8
 
8
9
 
9
- class SwaggerBlueprintTest:
10
- modules = []
11
-
10
+ class SwaggerBlueprintTest(PytestOnlyAPITestCase):
12
11
  def test_swagger_resource_type(self, api):
13
12
  response = api.get(url_for("api.specs"))
14
13
  assert200(response)
@@ -1,15 +1,14 @@
1
- import pytest
2
1
  from flask import url_for
3
2
 
4
3
  from udata.core.dataset.factories import DatasetFactory
5
4
  from udata.core.reuse.factories import ReuseFactory
6
5
  from udata.core.tags.tasks import count_tags
6
+ from udata.tests.api import PytestOnlyAPITestCase
7
7
  from udata.tests.helpers import assert200
8
8
  from udata.utils import faker
9
9
 
10
10
 
11
- @pytest.mark.frontend
12
- class TagsAPITest:
11
+ class TagsAPITest(PytestOnlyAPITestCase):
13
12
  def test_suggest_tags_api(self, api):
14
13
  """It should suggest tags"""
15
14
  for i in range(3):
@@ -19,7 +18,7 @@ class TagsAPITest:
19
18
 
20
19
  count_tags()
21
20
 
22
- response = api.get(url_for("api.suggest_tags"), qs={"q": "tes", "size": "5"})
21
+ response = api.get(url_for("api.suggest_tags", q="tes", size=5))
23
22
  assert200(response)
24
23
 
25
24
  assert len(response.json) <= 5
@@ -39,7 +38,7 @@ class TagsAPITest:
39
38
 
40
39
  count_tags()
41
40
 
42
- response = api.get(url_for("api.suggest_tags"), qs={"q": "testé", "size": "5"})
41
+ response = api.get(url_for("api.suggest_tags", q="testé", size=5))
43
42
  assert200(response)
44
43
 
45
44
  assert len(response.json) <= 5
@@ -59,12 +58,12 @@ class TagsAPITest:
59
58
 
60
59
  count_tags()
61
60
 
62
- response = api.get(url_for("api.suggest_tags"), qs={"q": "bbbb", "size": "5"})
61
+ response = api.get(url_for("api.suggest_tags", q="bbbb", size=5))
63
62
  assert200(response)
64
63
  assert len(response.json) == 0
65
64
 
66
65
  def test_suggest_tags_api_empty(self, api):
67
66
  """It should not provide tag suggestion if no data"""
68
- response = api.get(url_for("api.suggest_tags"), qs={"q": "bbbb", "size": "5"})
67
+ response = api.get(url_for("api.suggest_tags", q="bbbb", size=5))
69
68
  assert200(response)
70
69
  assert len(response.json) == 0
@@ -12,8 +12,6 @@ from . import APITestCase
12
12
 
13
13
 
14
14
  class TransferAPITest(APITestCase):
15
- modules = []
16
-
17
15
  def test_request_dataset_transfer(self):
18
16
  user = self.login()
19
17
  recipient_user = UserFactory()
@@ -11,8 +11,6 @@ from . import APITestCase
11
11
 
12
12
 
13
13
  class UserAPITest(APITestCase):
14
- modules = []
15
-
16
14
  def test_follow_user(self):
17
15
  """It should follow an user on POST"""
18
16
  user = self.login()
@@ -65,7 +63,7 @@ class UserAPITest(APITestCase):
65
63
  for i in range(4):
66
64
  UserFactory(first_name="first-name-test-{0}".format(i) if i % 2 else faker.word())
67
65
 
68
- response = self.get(url_for("api.suggest_users"), qs={"q": "first-name-test", "size": "5"})
66
+ response = self.get(url_for("api.suggest_users", q="first-name-test", size=5))
69
67
  self.assert200(response)
70
68
 
71
69
  self.assertLessEqual(len(response.json), 5)
@@ -84,7 +82,7 @@ class UserAPITest(APITestCase):
84
82
  for i in range(4):
85
83
  UserFactory(last_name="last-name-test-{0}".format(i) if i % 2 else faker.word())
86
84
 
87
- response = self.get(url_for("api.suggest_users"), qs={"q": "last-name-test", "size": "5"})
85
+ response = self.get(url_for("api.suggest_users", q="last-name-test", size=5))
88
86
  self.assert200(response)
89
87
 
90
88
  self.assertLessEqual(len(response.json), 5)
@@ -102,7 +100,7 @@ class UserAPITest(APITestCase):
102
100
  for i in range(4):
103
101
  UserFactory(last_name="last-name-testé-{0}".format(i) if i % 2 else faker.word())
104
102
 
105
- response = self.get(url_for("api.suggest_users"), qs={"q": "last-name-testé", "size": "5"})
103
+ response = self.get(url_for("api.suggest_users", q="last-name-testé", size=5))
106
104
  self.assert200(response)
107
105
 
108
106
  self.assertLessEqual(len(response.json), 5)
@@ -119,13 +117,13 @@ class UserAPITest(APITestCase):
119
117
  """It should not provide user suggestion if no match"""
120
118
  UserFactory.create_batch(3)
121
119
 
122
- response = self.get(url_for("api.suggest_users"), qs={"q": "xxxxxx", "size": "5"})
120
+ response = self.get(url_for("api.suggest_users", q="xxxxxx", size=5))
123
121
  self.assert200(response)
124
122
  self.assertEqual(len(response.json), 0)
125
123
 
126
124
  def test_suggest_users_api_empty(self):
127
125
  """It should not provide user suggestion if no data"""
128
- response = self.get(url_for("api.suggest_users"), qs={"q": "xxxxxx", "size": "5"})
126
+ response = self.get(url_for("api.suggest_users", q="xxxxxx", size=5))
129
127
  self.assert200(response)
130
128
  self.assertEqual(len(response.json), 0)
131
129
 
@@ -133,7 +131,7 @@ class UserAPITest(APITestCase):
133
131
  """It should suggest users without deduplicating homonyms"""
134
132
  UserFactory.create_batch(2, first_name="test", last_name="homonym")
135
133
 
136
- response = self.get(url_for("api.suggest_users"), qs={"q": "homonym", "size": "5"})
134
+ response = self.get(url_for("api.suggest_users", q="homonym", size=5))
137
135
  self.assert200(response)
138
136
 
139
137
  self.assertEqual(len(response.json), 2)
@@ -144,11 +142,11 @@ class UserAPITest(APITestCase):
144
142
 
145
143
  def test_suggest_users_api_size_validation(self):
146
144
  """It should validate that the size parameter is between 1 and 20."""
147
- response = self.get(url_for("api.suggest_users"), qs={"q": "foobar", "size": "0"})
145
+ response = self.get(url_for("api.suggest_users", q="foobar", size=0))
148
146
  self.assert400(response)
149
147
  self.assertIn("between 1 and 20", response.json["errors"]["size"])
150
148
 
151
- response = self.get(url_for("api.suggest_users"), qs={"q": "foobar", "size": "21"})
149
+ response = self.get(url_for("api.suggest_users", q="foobar", size=21))
152
150
 
153
151
  self.assert400(response)
154
152
  self.assertIn("between 1 and 20", response.json["errors"]["size"])
@@ -367,8 +367,6 @@ class DatasetResourceAPIV2Test(APITestCase):
367
367
 
368
368
 
369
369
  class DatasetExtrasAPITest(APITestCase):
370
- modules = None
371
-
372
370
  def setUp(self):
373
371
  self.login()
374
372
  self.dataset = DatasetFactory(owner=self.user)
@@ -503,8 +501,6 @@ class DatasetExtrasAPITest(APITestCase):
503
501
 
504
502
 
505
503
  class DatasetResourceExtrasAPITest(APITestCase):
506
- modules = None
507
-
508
504
  def setUp(self):
509
505
  self.login()
510
506
  self.dataset = DatasetFactory(owner=self.user)
@@ -7,8 +7,6 @@ from udata.tests.api import APITestCase
7
7
 
8
8
 
9
9
  class MeAPIv2Test(APITestCase):
10
- modules = []
11
-
12
10
  def test_my_org_topics(self):
13
11
  user = self.login()
14
12
  member = Member(user=user, role="editor")
@@ -5,8 +5,6 @@ from udata.tests.api import APITestCase
5
5
 
6
6
 
7
7
  class OrganizationExtrasAPITest(APITestCase):
8
- modules = None
9
-
10
8
  def setUp(self):
11
9
  self.login()
12
10
  member = Member(user=self.user, role="admin")
@@ -3,12 +3,11 @@ import json
3
3
  from flask import url_for
4
4
  from flask_restx import schemas
5
5
 
6
+ from udata.tests.api import PytestOnlyAPITestCase
6
7
  from udata.tests.helpers import assert200
7
8
 
8
9
 
9
- class SwaggerBlueprintTest:
10
- modules = []
11
-
10
+ class SwaggerBlueprintTest(PytestOnlyAPITestCase):
12
11
  def test_swagger_resource_type(self, api):
13
12
  response = api.get(url_for("apiv2.specs"))
14
13
  assert200(response)
@@ -27,8 +27,6 @@ from udata.tests.features.territories import create_geozones_fixtures
27
27
 
28
28
 
29
29
  class TopicsListAPITest(APITestCase):
30
- modules = []
31
-
32
30
  def test_topic_api_list(self):
33
31
  """It should fetch a topic list from the API"""
34
32
  owner = UserFactory()
@@ -1,16 +1,18 @@
1
- def test_cli_help(cli):
2
- """Should display help without errors"""
3
- cli()
4
- cli("-?")
5
- cli("-h")
6
- cli("--help")
1
+ from udata.tests import PytestOnlyTestCase
7
2
 
8
3
 
9
- def test_cli_log_and_printing(cli):
10
- """Should properly log and print"""
11
- cli("test log")
4
+ class CliBaseTest(PytestOnlyTestCase):
5
+ def test_cli_help(self, cli):
6
+ """Should display help without errors"""
7
+ cli()
8
+ cli("-?")
9
+ cli("-h")
10
+ cli("--help")
12
11
 
12
+ def test_cli_log_and_printing(self, cli):
13
+ """Should properly log and print"""
14
+ cli("test log")
13
15
 
14
- def test_cli_version(cli):
15
- """Should display version without errors"""
16
- cli("--version")
16
+ def test_cli_version(self, cli):
17
+ """Should display version without errors"""
18
+ cli("--version")
@@ -2,13 +2,15 @@ from datetime import datetime
2
2
 
3
3
  import pytest
4
4
  from bson import ObjectId
5
+ from mongoengine.connection import get_db
5
6
 
6
7
  from udata.models import Reuse
8
+ from udata.tests.api import PytestOnlyDBTestCase
7
9
 
8
10
 
9
11
  @pytest.fixture
10
- def migrations(db):
11
- db.migrations.insert_one(
12
+ def migrations():
13
+ get_db().migrations.insert_one(
12
14
  {
13
15
  "plugin": "udata",
14
16
  "filename": "test.py",
@@ -17,55 +19,50 @@ def migrations(db):
17
19
  "output": "ok",
18
20
  }
19
21
  )
20
- return db.migrations
21
-
22
-
23
- def test_unrecord_with_complete_filename(cli, migrations):
24
- """Should display help without errors"""
25
- result = cli("db unrecord udata test.py")
26
- assert result.exit_code == 0
27
- assert migrations.count_documents({}) == 0
28
-
29
-
30
- def test_unrecord_with_filename_without_extension(cli, migrations):
31
- """Should display help without errors"""
32
- result = cli("db unrecord udata test")
33
- assert result.exit_code == 0
34
- assert migrations.count_documents({}) == 0
35
-
36
-
37
- def test_unrecord_with_single_parameter(cli, migrations):
38
- """Should display help without errors"""
39
- result = cli("db unrecord udata:test.py")
40
- assert result.exit_code == 0
41
- assert migrations.count_documents({}) == 0
42
-
43
-
44
- def test_unrecord_with_single_parameter_without_extension(cli, migrations):
45
- """Should display help without errors"""
46
- result = cli("db unrecord udata:test")
47
- assert result.exit_code == 0
48
- assert migrations.count_documents({}) == 0
49
-
50
-
51
- def test_unrecord_without_parameters(cli, migrations):
52
- """Should display help without errors"""
53
- result = cli("db unrecord", check=False)
54
- assert result.exit_code != 0
55
- assert migrations.count_documents({}) == 1
56
-
57
-
58
- def test_unrecord_with_too_many_parameters(cli, migrations):
59
- """Should display help without errors"""
60
- result = cli("db unrecord udata test.py too many", check=False)
61
- assert result.exit_code != 0
62
- assert migrations.count_documents({}) == 1
63
-
64
-
65
- def test_check_references_report_listfield_missing(cli, clean_db):
66
- # The cli command `udata db check-integrity` should catch reuse object missing datasets field
67
- Reuse._get_collection().insert_one({"_id": ObjectId()})
68
-
69
- result = cli("db check-integrity --models Reuse", check=False)
70
- assert "Reuse.datasets(Dataset) — list…: 1" in result.output
71
- assert result.exit_code != 0
22
+ return get_db().migrations
23
+
24
+
25
+ class DBCliTest(PytestOnlyDBTestCase):
26
+ def test_unrecord_with_complete_filename(self, cli, migrations):
27
+ """Should display help without errors"""
28
+ result = cli("db unrecord udata test.py")
29
+ assert result.exit_code == 0
30
+ assert migrations.count_documents({}) == 0
31
+
32
+ def test_unrecord_with_filename_without_extension(self, cli, migrations):
33
+ """Should display help without errors"""
34
+ result = cli("db unrecord udata test")
35
+ assert result.exit_code == 0
36
+ assert migrations.count_documents({}) == 0
37
+
38
+ def test_unrecord_with_single_parameter(self, cli, migrations):
39
+ """Should display help without errors"""
40
+ result = cli("db unrecord udata:test.py")
41
+ assert result.exit_code == 0
42
+ assert migrations.count_documents({}) == 0
43
+
44
+ def test_unrecord_with_single_parameter_without_extension(self, cli, migrations):
45
+ """Should display help without errors"""
46
+ result = cli("db unrecord udata:test")
47
+ assert result.exit_code == 0
48
+ assert migrations.count_documents({}) == 0
49
+
50
+ def test_unrecord_without_parameters(self, cli, migrations):
51
+ """Should display help without errors"""
52
+ result = cli("db unrecord", check=False)
53
+ assert result.exit_code != 0
54
+ assert migrations.count_documents({}) == 1
55
+
56
+ def test_unrecord_with_too_many_parameters(self, cli, migrations):
57
+ """Should display help without errors"""
58
+ result = cli("db unrecord udata test.py too many", check=False)
59
+ assert result.exit_code != 0
60
+ assert migrations.count_documents({}) == 1
61
+
62
+ def test_check_references_report_listfield_missing(self, cli):
63
+ # The cli command `udata db check-integrity` should catch reuse object missing datasets field
64
+ Reuse._get_collection().insert_one({"_id": ObjectId()})
65
+
66
+ result = cli("db check-integrity --models Reuse", check=False)
67
+ assert "Reuse.datasets(Dataset) — list…: 1" in result.output
68
+ assert result.exit_code != 0