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.
- udata/commands/tests/test_fixtures.py +2 -3
- udata/core/badges/tests/test_commands.py +2 -4
- udata/core/badges/tests/test_model.py +2 -2
- udata/core/pages/tests/test_api.py +0 -2
- udata/core/spatial/tests/test_api.py +17 -20
- udata/core/spatial/tests/test_models.py +3 -3
- udata/core/user/tests/test_user_model.py +2 -6
- udata/features/identicon/tests/test_backends.py +3 -13
- udata/harvest/tests/ckan/test_ckan_backend.py +300 -337
- udata/harvest/tests/ckan/test_ckan_backend_errors.py +94 -99
- udata/harvest/tests/ckan/test_ckan_backend_filters.py +128 -122
- udata/harvest/tests/ckan/test_dkan_backend.py +39 -51
- udata/harvest/tests/test_actions.py +7 -7
- udata/harvest/tests/test_api.py +2 -4
- udata/harvest/tests/test_base_backend.py +3 -4
- udata/harvest/tests/test_dcat_backend.py +4 -6
- udata/harvest/tests/test_models.py +2 -4
- udata/harvest/tests/test_notifications.py +2 -4
- udata/harvest/tests/test_tasks.py +2 -3
- udata/tests/__init__.py +40 -58
- udata/tests/api/__init__.py +87 -2
- udata/tests/api/test_activities_api.py +17 -23
- udata/tests/api/test_auth_api.py +2 -4
- udata/tests/api/test_contact_points.py +48 -54
- udata/tests/api/test_dataservices_api.py +0 -2
- udata/tests/api/test_datasets_api.py +15 -29
- udata/tests/api/test_me_api.py +4 -6
- udata/tests/api/test_organizations_api.py +19 -38
- udata/tests/api/test_reports_api.py +0 -4
- udata/tests/api/test_reuses_api.py +9 -19
- udata/tests/api/test_swagger.py +2 -3
- udata/tests/api/test_tags_api.py +6 -7
- udata/tests/api/test_transfer_api.py +0 -2
- udata/tests/api/test_user_api.py +8 -10
- udata/tests/apiv2/test_datasets.py +0 -4
- udata/tests/apiv2/test_me_api.py +0 -2
- udata/tests/apiv2/test_organizations.py +0 -2
- udata/tests/apiv2/test_swagger.py +2 -3
- udata/tests/apiv2/test_topics.py +0 -2
- udata/tests/cli/test_cli_base.py +14 -12
- udata/tests/cli/test_db_cli.py +51 -54
- udata/tests/contact_point/test_contact_point_models.py +2 -2
- udata/tests/dataservice/test_csv_adapter.py +2 -5
- udata/tests/dataservice/test_dataservice_rdf.py +3 -6
- udata/tests/dataservice/test_dataservice_tasks.py +36 -38
- udata/tests/dataset/test_csv_adapter.py +2 -5
- udata/tests/dataset/test_dataset_actions.py +2 -4
- udata/tests/dataset/test_dataset_commands.py +2 -4
- udata/tests/dataset/test_dataset_events.py +3 -3
- udata/tests/dataset/test_dataset_model.py +6 -7
- udata/tests/dataset/test_dataset_rdf.py +6 -9
- udata/tests/dataset/test_dataset_recommendations.py +2 -2
- udata/tests/dataset/test_dataset_tasks.py +66 -68
- udata/tests/dataset/test_resource_preview.py +39 -48
- udata/tests/dataset/test_transport_tasks.py +2 -2
- udata/tests/features/territories/__init__.py +0 -6
- udata/tests/features/territories/test_territories_api.py +25 -24
- udata/tests/forms/test_current_user_field.py +2 -2
- udata/tests/forms/test_dict_field.py +2 -4
- udata/tests/forms/test_extras_fields.py +2 -3
- udata/tests/forms/test_image_field.py +2 -2
- udata/tests/forms/test_model_field.py +2 -4
- udata/tests/forms/test_publish_as_field.py +2 -4
- udata/tests/forms/test_user_forms.py +26 -29
- udata/tests/frontend/test_auth.py +2 -3
- udata/tests/frontend/test_csv.py +5 -6
- udata/tests/frontend/test_error_handlers.py +2 -3
- udata/tests/frontend/test_hooks.py +5 -7
- udata/tests/frontend/test_markdown.py +3 -4
- udata/tests/helpers.py +2 -7
- udata/tests/metrics/test_metrics.py +52 -48
- udata/tests/metrics/test_tasks.py +154 -150
- udata/tests/organization/test_csv_adapter.py +2 -5
- udata/tests/organization/test_notifications.py +2 -4
- udata/tests/organization/test_organization_model.py +3 -4
- udata/tests/organization/test_organization_rdf.py +2 -8
- udata/tests/plugin.py +6 -110
- udata/tests/reuse/test_reuse_model.py +3 -4
- udata/tests/site/test_site_api.py +0 -2
- udata/tests/site/test_site_csv_exports.py +0 -2
- udata/tests/site/test_site_metrics.py +2 -4
- udata/tests/site/test_site_model.py +2 -2
- udata/tests/site/test_site_rdf.py +3 -6
- udata/tests/test_activity.py +3 -3
- udata/tests/test_api_fields.py +6 -9
- udata/tests/test_cors.py +0 -2
- udata/tests/test_dcat_commands.py +2 -3
- udata/tests/test_discussions.py +2 -7
- udata/tests/test_mail.py +4 -10
- udata/tests/test_migrations.py +413 -419
- udata/tests/test_model.py +10 -11
- udata/tests/test_notifications.py +2 -3
- udata/tests/test_owned.py +3 -3
- udata/tests/test_routing.py +5 -5
- udata/tests/test_storages.py +6 -5
- udata/tests/test_tags.py +2 -1
- udata/tests/test_topics.py +2 -4
- udata/tests/test_transfer.py +4 -5
- udata/tests/topic/test_topic_tasks.py +25 -27
- udata/tests/user/test_user_rdf.py +2 -8
- udata/tests/workers/test_jobs_commands.py +2 -2
- udata/tests/workers/test_tasks_routing.py +27 -27
- {udata-12.0.2.dev17.dist-info → udata-12.0.2.dev18.dist-info}/METADATA +1 -1
- {udata-12.0.2.dev17.dist-info → udata-12.0.2.dev18.dist-info}/RECORD +108 -110
- udata/tests/frontend/__init__.py +0 -23
- udata/tests/metrics/conftest.py +0 -15
- {udata-12.0.2.dev17.dist-info → udata-12.0.2.dev18.dist-info}/WHEEL +0 -0
- {udata-12.0.2.dev17.dist-info → udata-12.0.2.dev18.dist-info}/entry_points.txt +0 -0
- {udata-12.0.2.dev17.dist-info → udata-12.0.2.dev18.dist-info}/licenses/LICENSE +0 -0
- {udata-12.0.2.dev17.dist-info → udata-12.0.2.dev18.dist-info}/top_level.txt +0 -0
|
@@ -12,160 +12,164 @@ from udata.core.metrics.tasks import (
|
|
|
12
12
|
)
|
|
13
13
|
from udata.core.organization.factories import OrganizationFactory
|
|
14
14
|
from udata.core.reuse.factories import ReuseFactory
|
|
15
|
+
from udata.tests import PytestOnlyTestCase
|
|
15
16
|
|
|
16
17
|
from .helpers import mock_metrics_api
|
|
17
18
|
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
@pytest.mark.options(METRICS_API="http://metrics-api.fr/api")
|
|
21
|
+
class TasksMetricsTest(PytestOnlyTestCase):
|
|
22
|
+
def test_iterate_on_metrics(self, app, rmock):
|
|
23
|
+
mock_metrics_api(
|
|
24
|
+
app,
|
|
25
|
+
rmock,
|
|
26
|
+
"test_model",
|
|
27
|
+
["test_key", "second_key"],
|
|
28
|
+
[
|
|
29
|
+
{"id": 123},
|
|
30
|
+
{"id": 42},
|
|
31
|
+
{"id": 1337},
|
|
32
|
+
],
|
|
33
|
+
page_size=2,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
metrics_data = list(
|
|
37
|
+
iterate_on_metrics("test_model", ["test_key", "second_key"], page_size=2)
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
assert metrics_data == [
|
|
41
|
+
{"__id": 0, "id": 123},
|
|
42
|
+
{"__id": 1, "id": 42},
|
|
43
|
+
{"__id": 2, "id": 1337},
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
@pytest.mark.parametrize(
|
|
47
|
+
"endpoint,id_key,factory,func,api_key",
|
|
25
48
|
[
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
("dataservices", "dataservice_id", DataserviceFactory, update_dataservices, "visit"),
|
|
50
|
+
("reuses", "reuse_id", ReuseFactory, update_reuses, "visit"),
|
|
51
|
+
(
|
|
52
|
+
"organizations",
|
|
53
|
+
"organization_id",
|
|
54
|
+
OrganizationFactory,
|
|
55
|
+
update_organizations,
|
|
56
|
+
"visit_dataset",
|
|
57
|
+
),
|
|
29
58
|
],
|
|
30
|
-
page_size=2,
|
|
31
59
|
)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
[
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
{
|
|
149
|
-
"resource_id": str(community_resources[9].id),
|
|
150
|
-
"dataset_id": None,
|
|
151
|
-
"download_resource": 1,
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
update_resources_and_community_resources()
|
|
157
|
-
|
|
158
|
-
dataset_a_with_resources.reload()
|
|
159
|
-
dataset_b_with_resource.reload()
|
|
160
|
-
dataset_without_resource.reload()
|
|
161
|
-
[community_resource.reload() for community_resource in community_resources]
|
|
162
|
-
|
|
163
|
-
assert community_resources[3].metrics.get("views") == 16
|
|
164
|
-
assert community_resources[5].metrics.get("views") == 111
|
|
165
|
-
assert community_resources[9].metrics.get("views") == 1
|
|
166
|
-
|
|
167
|
-
assert dataset_a_with_resources.resources[0].metrics.get("views") == 42
|
|
168
|
-
assert dataset_a_with_resources.resources[1].metrics.get("views") == 1337
|
|
169
|
-
assert dataset_a_with_resources.resources[4].metrics.get("views") == 2
|
|
170
|
-
|
|
171
|
-
assert dataset_b_with_resource.resources[0].metrics.get("views") == 1404
|
|
60
|
+
def test_update_simple_visit_to_views_metrics(
|
|
61
|
+
self, app, rmock, endpoint, id_key, factory, func, api_key
|
|
62
|
+
):
|
|
63
|
+
models = [factory() for i in range(15)]
|
|
64
|
+
mock_metrics_api(
|
|
65
|
+
app,
|
|
66
|
+
rmock,
|
|
67
|
+
endpoint,
|
|
68
|
+
[api_key],
|
|
69
|
+
[
|
|
70
|
+
{id_key: str(models[1].id), api_key: 42},
|
|
71
|
+
{id_key: str(models[3].id), api_key: 1337},
|
|
72
|
+
{id_key: str(models[4].id), api_key: 2},
|
|
73
|
+
],
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
func()
|
|
77
|
+
[model.reload() for model in models]
|
|
78
|
+
|
|
79
|
+
assert models[1].metrics.get("views") == 42
|
|
80
|
+
assert models[3].metrics.get("views") == 1337
|
|
81
|
+
assert models[4].metrics.get("views") == 2
|
|
82
|
+
|
|
83
|
+
def test_update_datasets(self, app, rmock):
|
|
84
|
+
datasets = [DatasetFactory() for i in range(15)]
|
|
85
|
+
mock_metrics_api(
|
|
86
|
+
app,
|
|
87
|
+
rmock,
|
|
88
|
+
"datasets",
|
|
89
|
+
["visit", "download_resource"],
|
|
90
|
+
[
|
|
91
|
+
{"dataset_id": str(datasets[1].id), "visit": 42, "download_resource": 123},
|
|
92
|
+
{"dataset_id": str(datasets[3].id), "visit": 1337, "download_resource": 4242},
|
|
93
|
+
{"dataset_id": str(datasets[4].id), "visit": 2, "download_resource": 7},
|
|
94
|
+
],
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
update_datasets()
|
|
98
|
+
[model.reload() for model in datasets]
|
|
99
|
+
|
|
100
|
+
assert datasets[1].metrics.get("views") == 42
|
|
101
|
+
assert datasets[1].metrics.get("resources_downloads") == 123
|
|
102
|
+
assert datasets[3].metrics.get("views") == 1337
|
|
103
|
+
assert datasets[3].metrics.get("resources_downloads") == 4242
|
|
104
|
+
assert datasets[4].metrics.get("views") == 2
|
|
105
|
+
assert datasets[4].metrics.get("resources_downloads") == 7
|
|
106
|
+
|
|
107
|
+
def test_update_resources_metrics(self, app, rmock):
|
|
108
|
+
resources = [ResourceFactory() for i in range(5)]
|
|
109
|
+
dataset_a_with_resources = DatasetFactory(resources=resources)
|
|
110
|
+
dataset_b_with_resource = DatasetFactory(resources=[ResourceFactory()])
|
|
111
|
+
|
|
112
|
+
community_resources = [CommunityResourceFactory() for i in range(10)]
|
|
113
|
+
|
|
114
|
+
dataset_without_resource = DatasetFactory()
|
|
115
|
+
|
|
116
|
+
mock_metrics_api(
|
|
117
|
+
app,
|
|
118
|
+
rmock,
|
|
119
|
+
"resources",
|
|
120
|
+
["download_resource"],
|
|
121
|
+
[
|
|
122
|
+
{
|
|
123
|
+
"resource_id": str(dataset_a_with_resources.resources[0].id),
|
|
124
|
+
"dataset_id": str(dataset_a_with_resources.id),
|
|
125
|
+
"download_resource": 42,
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"resource_id": str(community_resources[3].id),
|
|
129
|
+
"dataset_id": None,
|
|
130
|
+
"download_resource": 16,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"resource_id": str(community_resources[5].id),
|
|
134
|
+
"dataset_id": None,
|
|
135
|
+
"download_resource": 111,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"resource_id": str(dataset_a_with_resources.resources[1].id),
|
|
139
|
+
"dataset_id": str(dataset_a_with_resources.id),
|
|
140
|
+
"download_resource": 1337,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"resource_id": str(dataset_b_with_resource.resources[0].id),
|
|
144
|
+
"dataset_id": str(dataset_b_with_resource.id),
|
|
145
|
+
"download_resource": 1404,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"resource_id": str(dataset_a_with_resources.resources[4].id),
|
|
149
|
+
"dataset_id": str(dataset_a_with_resources.id),
|
|
150
|
+
"download_resource": 2,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"resource_id": str(community_resources[9].id),
|
|
154
|
+
"dataset_id": None,
|
|
155
|
+
"download_resource": 1,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
update_resources_and_community_resources()
|
|
161
|
+
|
|
162
|
+
dataset_a_with_resources.reload()
|
|
163
|
+
dataset_b_with_resource.reload()
|
|
164
|
+
dataset_without_resource.reload()
|
|
165
|
+
[community_resource.reload() for community_resource in community_resources]
|
|
166
|
+
|
|
167
|
+
assert community_resources[3].metrics.get("views") == 16
|
|
168
|
+
assert community_resources[5].metrics.get("views") == 111
|
|
169
|
+
assert community_resources[9].metrics.get("views") == 1
|
|
170
|
+
|
|
171
|
+
assert dataset_a_with_resources.resources[0].metrics.get("views") == 42
|
|
172
|
+
assert dataset_a_with_resources.resources[1].metrics.get("views") == 1337
|
|
173
|
+
assert dataset_a_with_resources.resources[4].metrics.get("views") == 2
|
|
174
|
+
|
|
175
|
+
assert dataset_b_with_resource.resources[0].metrics.get("views") == 1404
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
|
|
3
1
|
from udata.core.dataset.factories import DatasetFactory
|
|
4
2
|
from udata.core.organization.csv import OrganizationCsvAdapter
|
|
5
3
|
from udata.core.organization.factories import OrganizationFactory
|
|
6
4
|
from udata.core.organization.models import Organization
|
|
5
|
+
from udata.tests.api import PytestOnlyDBTestCase
|
|
7
6
|
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
@pytest.mark.usefixtures("clean_db")
|
|
11
|
-
class OrganizationCSVAdapterTest:
|
|
8
|
+
class OrganizationCSVAdapterTest(PytestOnlyDBTestCase):
|
|
12
9
|
def test_organization_downloads_counts(self):
|
|
13
10
|
org_with_dataset = OrganizationFactory()
|
|
14
11
|
org_without_dataset = OrganizationFactory()
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
|
|
3
1
|
from udata.core.organization.factories import OrganizationFactory
|
|
4
2
|
from udata.core.organization.notifications import membership_request_notifications
|
|
5
3
|
from udata.core.user.factories import UserFactory
|
|
6
4
|
from udata.models import Member, MembershipRequest
|
|
5
|
+
from udata.tests.api import PytestOnlyDBTestCase
|
|
7
6
|
from udata.tests.helpers import assert_equal_dates
|
|
8
7
|
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
class OrganizationNotificationsTest:
|
|
9
|
+
class OrganizationNotificationsTest(PytestOnlyDBTestCase):
|
|
12
10
|
def test_pending_membership_requests(self):
|
|
13
11
|
admin = UserFactory()
|
|
14
12
|
editor = UserFactory()
|
|
@@ -12,12 +12,11 @@ from udata.core.organization.models import Organization, OrganizationBadge
|
|
|
12
12
|
from udata.core.reuse.factories import ReuseFactory, VisibleReuseFactory
|
|
13
13
|
from udata.core.user.factories import UserFactory
|
|
14
14
|
from udata.models import Dataset, Follow, Member, Reuse, db
|
|
15
|
+
from udata.tests.api import DBTestCase
|
|
15
16
|
from udata.tests.helpers import assert_emit
|
|
16
17
|
|
|
17
|
-
from .. import DBTestMixin, TestCase
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
class OrganizationModelTest(TestCase, DBTestMixin):
|
|
19
|
+
class OrganizationModelTest(DBTestCase):
|
|
21
20
|
# Load metrics
|
|
22
21
|
import udata.core.organization.metrics # noqa
|
|
23
22
|
import udata.core.followers.metrics # noqa
|
|
@@ -88,7 +87,7 @@ class OrganizationModelTest(TestCase, DBTestMixin):
|
|
|
88
87
|
OrganizationFactory(url="not-an-url")
|
|
89
88
|
|
|
90
89
|
|
|
91
|
-
class OrganizationBadgeTest(
|
|
90
|
+
class OrganizationBadgeTest(DBTestCase):
|
|
92
91
|
# Model badges can be extended in plugins, for example in udata-front
|
|
93
92
|
# for french only badges.
|
|
94
93
|
Organization.__badges__["new"] = "new"
|
|
@@ -3,7 +3,6 @@ from rdflib import BNode, Literal, URIRef
|
|
|
3
3
|
from rdflib.namespace import FOAF, RDF, RDFS
|
|
4
4
|
from rdflib.resource import Resource as RdfResource
|
|
5
5
|
|
|
6
|
-
from udata import api
|
|
7
6
|
from udata.core.dataservices.factories import DataserviceFactory
|
|
8
7
|
from udata.core.dataservices.models import Dataservice
|
|
9
8
|
from udata.core.dataset.factories import DatasetFactory
|
|
@@ -11,16 +10,11 @@ from udata.core.dataset.models import Dataset
|
|
|
11
10
|
from udata.core.organization.factories import OrganizationFactory
|
|
12
11
|
from udata.core.organization.rdf import build_org_catalog, organization_to_rdf
|
|
13
12
|
from udata.rdf import DCAT, DCT, HYDRA
|
|
14
|
-
from udata.tests import
|
|
13
|
+
from udata.tests.api import APITestCase
|
|
15
14
|
from udata.utils import faker
|
|
16
15
|
|
|
17
16
|
|
|
18
|
-
class OrganizationToRdfTest(
|
|
19
|
-
def create_app(self):
|
|
20
|
-
app = super(OrganizationToRdfTest, self).create_app()
|
|
21
|
-
api.init_app(app)
|
|
22
|
-
return app
|
|
23
|
-
|
|
17
|
+
class OrganizationToRdfTest(APITestCase):
|
|
24
18
|
def test_minimal(self):
|
|
25
19
|
org = OrganizationFactory.build() # Does not have an URL
|
|
26
20
|
o = organization_to_rdf(org)
|
udata/tests/plugin.py
CHANGED
|
@@ -1,44 +1,33 @@
|
|
|
1
1
|
import shlex
|
|
2
2
|
from contextlib import contextmanager
|
|
3
|
-
from urllib.parse import urlparse
|
|
4
3
|
|
|
5
4
|
import pytest
|
|
6
5
|
from flask import current_app, json, template_rendered, url_for
|
|
7
6
|
from flask.testing import FlaskClient
|
|
8
7
|
from flask_principal import Identity, identity_changed
|
|
9
8
|
from lxml import etree
|
|
10
|
-
from werkzeug.urls import url_encode
|
|
11
9
|
|
|
12
|
-
from udata import settings
|
|
13
|
-
from udata.app import create_app
|
|
14
10
|
from udata.core.user.factories import UserFactory
|
|
15
|
-
from udata.mongo import db
|
|
16
|
-
from udata.mongo.document import get_all_models
|
|
17
11
|
|
|
18
12
|
from .helpers import assert200, assert_command_ok
|
|
19
13
|
|
|
20
14
|
|
|
21
15
|
class TestClient(FlaskClient):
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return "?".join([url, url_encode(qs)])
|
|
16
|
+
"""
|
|
17
|
+
The goal of these `post`, `put` and `delete` functions is to
|
|
18
|
+
switch from `data` in kwargs to `data` in args and be able to
|
|
19
|
+
`client.post(url, data)` without doing `client.post(url, data=data)`
|
|
27
20
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return super(TestClient, self).get(url, **kwargs)
|
|
21
|
+
Same as in :TestClientOverride
|
|
22
|
+
"""
|
|
31
23
|
|
|
32
24
|
def post(self, url, data=None, **kwargs):
|
|
33
|
-
url = self._build_url(url, kwargs)
|
|
34
25
|
return super(TestClient, self).post(url, data=data, **kwargs)
|
|
35
26
|
|
|
36
27
|
def put(self, url, data=None, **kwargs):
|
|
37
|
-
url = self._build_url(url, kwargs)
|
|
38
28
|
return super(TestClient, self).put(url, data=data, **kwargs)
|
|
39
29
|
|
|
40
30
|
def delete(self, url, data=None, **kwargs):
|
|
41
|
-
url = self._build_url(url, kwargs)
|
|
42
31
|
return super(TestClient, self).delete(url, data=data, **kwargs)
|
|
43
32
|
|
|
44
33
|
def login(self, user=None):
|
|
@@ -60,38 +49,6 @@ class TestClient(FlaskClient):
|
|
|
60
49
|
del session["_id"]
|
|
61
50
|
|
|
62
51
|
|
|
63
|
-
@pytest.fixture
|
|
64
|
-
def app(request):
|
|
65
|
-
test_settings = get_settings(request)
|
|
66
|
-
app = create_app(settings.Defaults, override=test_settings)
|
|
67
|
-
app.test_client_class = TestClient
|
|
68
|
-
return app
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
@pytest.fixture(autouse=True)
|
|
72
|
-
def _load_frontend(request, _configure_application):
|
|
73
|
-
"""
|
|
74
|
-
Use `pytest.mark.frontend` to specify that frontend/api should be loaded
|
|
75
|
-
Pass an optionnal list of modules as parameter to restrict loaded modules.
|
|
76
|
-
|
|
77
|
-
Handle backward compatibility with Class.modules attribute too
|
|
78
|
-
"""
|
|
79
|
-
if "app" not in request.fixturenames:
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
app = request.getfixturevalue("app")
|
|
83
|
-
marker = request.node.get_closest_marker("frontend")
|
|
84
|
-
modules = set(marker.args[0] if marker and marker.args else [])
|
|
85
|
-
if getattr(request.cls, "modules", None):
|
|
86
|
-
modules |= set(request.cls.modules)
|
|
87
|
-
|
|
88
|
-
if marker or hasattr(request.cls, "modules"):
|
|
89
|
-
from udata import api, frontend
|
|
90
|
-
|
|
91
|
-
api.init_app(app)
|
|
92
|
-
frontend.init_app(app, modules)
|
|
93
|
-
|
|
94
|
-
|
|
95
52
|
@pytest.fixture
|
|
96
53
|
def client(app):
|
|
97
54
|
"""
|
|
@@ -100,67 +57,6 @@ def client(app):
|
|
|
100
57
|
return app.test_client()
|
|
101
58
|
|
|
102
59
|
|
|
103
|
-
def get_settings(request):
|
|
104
|
-
"""
|
|
105
|
-
Extract settings from the current test request
|
|
106
|
-
"""
|
|
107
|
-
marker = request.node.get_closest_marker("settings")
|
|
108
|
-
if marker:
|
|
109
|
-
return marker.args[0]
|
|
110
|
-
_settings = getattr(request.cls, "settings", settings.Testing)
|
|
111
|
-
# apply the options(plugins) marker from pytest_flask as soon as app is created
|
|
112
|
-
# https://github.com/pytest-dev/pytest-flask/blob/a62ea18cb0fe89e3f3911192ab9ea4f9b12f8a16/pytest_flask/plugin.py#L126
|
|
113
|
-
# this lets us have default settings for plugins applied while testing
|
|
114
|
-
plugins = getattr(_settings, "PLUGINS", [])
|
|
115
|
-
for options in request.node.iter_markers("options"):
|
|
116
|
-
option = options.kwargs.get("plugins", []) or options.kwargs.get("PLUGINS", [])
|
|
117
|
-
plugins += option
|
|
118
|
-
setattr(_settings, "PLUGINS", plugins)
|
|
119
|
-
return _settings
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
def drop_db(app):
|
|
123
|
-
"""Clear the database"""
|
|
124
|
-
parsed_url = urlparse(app.config["MONGODB_HOST"])
|
|
125
|
-
|
|
126
|
-
# drop the leading /
|
|
127
|
-
db_name = parsed_url.path[1:]
|
|
128
|
-
db.connection.drop_database(db_name)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
@pytest.fixture
|
|
132
|
-
def clean_db(app):
|
|
133
|
-
drop_db(app)
|
|
134
|
-
for model in get_all_models():
|
|
135
|
-
# When dropping the database, MongoEngine will keep the collection cached inside
|
|
136
|
-
# `_collection` (in memory). This cache is used to call `ensure_indexes` only on the
|
|
137
|
-
# first call to `_get_collection()`, on subsequent calls the value inside `_collection`
|
|
138
|
-
# is returned without calling `ensure_indexes`.
|
|
139
|
-
# In tests, the first test will have a clean memory state, so MongoEngine will initialise
|
|
140
|
-
# the collection and create the indexes, then the following test, with a clean database (no indexes)
|
|
141
|
-
# will have the collection cached, so MongoEngine will never create the indexes (except if `auto_create_index_on_save`
|
|
142
|
-
# is set on the model, which may be the reason it is present on most of the big models, we may remove it?)
|
|
143
|
-
model._collection = None
|
|
144
|
-
|
|
145
|
-
yield
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
@pytest.fixture(name="db")
|
|
149
|
-
def raw_db(app, clean_db):
|
|
150
|
-
"""Access to raw PyMongo DB client"""
|
|
151
|
-
from mongoengine.connection import get_db
|
|
152
|
-
|
|
153
|
-
yield get_db()
|
|
154
|
-
drop_db(app)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
@pytest.fixture
|
|
158
|
-
def enable_resource_event(app):
|
|
159
|
-
"""Enable resource event"""
|
|
160
|
-
app.config["PUBLISH_ON_RESOURCE_EVENTS"] = True
|
|
161
|
-
app.config["RESOURCES_ANALYSER_URI"] = "http://local.dev"
|
|
162
|
-
|
|
163
|
-
|
|
164
60
|
class ApiClient(object):
|
|
165
61
|
def __init__(self, client):
|
|
166
62
|
self.client = client
|
|
@@ -12,12 +12,11 @@ from udata.core.reuse.models import Reuse, ReuseBadge
|
|
|
12
12
|
from udata.core.user.factories import UserFactory
|
|
13
13
|
from udata.i18n import gettext as _
|
|
14
14
|
from udata.models import db
|
|
15
|
+
from udata.tests.api import DBTestCase
|
|
15
16
|
from udata.tests.helpers import assert_emit
|
|
16
17
|
|
|
17
|
-
from .. import DBTestMixin, TestCase
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
class ReuseModelTest(TestCase, DBTestMixin):
|
|
19
|
+
class ReuseModelTest(DBTestCase):
|
|
21
20
|
def test_owned_by_user(self):
|
|
22
21
|
user = UserFactory()
|
|
23
22
|
reuse = ReuseFactory(owner=user)
|
|
@@ -135,7 +134,7 @@ class ReuseModelTest(TestCase, DBTestMixin):
|
|
|
135
134
|
ReuseFactory(url="not-an-url")
|
|
136
135
|
|
|
137
136
|
|
|
138
|
-
class ReuseBadgeTest(
|
|
137
|
+
class ReuseBadgeTest(DBTestCase):
|
|
139
138
|
# Model badges can be extended in plugins, for example in udata-front
|
|
140
139
|
# for french only badges.
|
|
141
140
|
Reuse.__badges__["new"] = "new"
|
|
@@ -15,8 +15,6 @@ from udata.tests.api import APITestCase
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class SiteCsvExportsTest(APITestCase):
|
|
18
|
-
modules = []
|
|
19
|
-
|
|
20
18
|
def test_datasets_csv(self):
|
|
21
19
|
self.app.config["EXPORT_CSV_MODELS"] = []
|
|
22
20
|
datasets = [DatasetFactory(resources=[ResourceFactory()]) for _ in range(5)]
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
|
|
3
1
|
from udata.core.dataservices.factories import DataserviceFactory
|
|
4
2
|
from udata.core.dataset.factories import (
|
|
5
3
|
DatasetFactory,
|
|
@@ -10,10 +8,10 @@ from udata.core.organization.constants import PUBLIC_SERVICE
|
|
|
10
8
|
from udata.core.reuse.factories import VisibleReuseFactory
|
|
11
9
|
from udata.core.site.factories import SiteFactory
|
|
12
10
|
from udata.harvest.tests.factories import HarvestSourceFactory
|
|
11
|
+
from udata.tests.api import PytestOnlyDBTestCase
|
|
13
12
|
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
class SiteMetricTest:
|
|
14
|
+
class SiteMetricTest(PytestOnlyDBTestCase):
|
|
17
15
|
def test_orga_metric(self, app):
|
|
18
16
|
site = SiteFactory.create(id=app.config["SITE_ID"])
|
|
19
17
|
OrganizationFactory.create_batch(3)
|
|
@@ -5,10 +5,10 @@ from flask import current_app, g
|
|
|
5
5
|
from udata.core.dataset.factories import DatasetFactory
|
|
6
6
|
from udata.core.reuse.factories import ReuseFactory
|
|
7
7
|
from udata.core.site.models import Site, current_site, get_current_site
|
|
8
|
-
from udata.tests import
|
|
8
|
+
from udata.tests.api import DBTestCase
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
class SiteModelTest(
|
|
11
|
+
class SiteModelTest(DBTestCase):
|
|
12
12
|
def test_current_site(self):
|
|
13
13
|
current_app.config["SITE_ID"] = "old-id"
|
|
14
14
|
current_app.config["SITE_TITLE"] = "Test"
|