udata 7.0.6__py2.py3-none-any.whl → 7.0.6.dev28209__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of udata might be problematic. Click here for more details.
- udata/__init__.py +1 -1
- udata/commands/__init__.py +3 -0
- udata/commands/dcat.py +4 -7
- udata/core/activity/api.py +1 -1
- udata/core/activity/models.py +3 -4
- udata/core/activity/tasks.py +5 -6
- udata/core/dataset/factories.py +4 -2
- udata/core/dataset/models.py +5 -2
- udata/core/dataset/rdf.py +25 -65
- udata/core/dataset/search.py +1 -0
- udata/core/spatial/tests/test_api.py +10 -7
- udata/core/topic/factories.py +2 -2
- udata/harvest/backends/dcat.py +24 -128
- udata/harvest/tests/test_dcat_backend.py +5 -78
- udata/rdf.py +0 -1
- udata/search/__init__.py +2 -2
- udata/tests/api/test_datasets_api.py +45 -45
- udata/tests/api/test_me_api.py +14 -13
- udata/tests/dataset/test_dataset_actions.py +2 -2
- udata/tests/dataset/test_dataset_commands.py +3 -3
- udata/tests/dataset/test_dataset_model.py +1 -2
- udata/tests/organization/test_organization_model.py +3 -3
- udata/tests/organization/test_organization_rdf.py +3 -3
- udata/tests/reuse/test_reuse_model.py +2 -2
- udata/tests/search/test_adapter.py +12 -12
- udata/tests/search/test_results.py +4 -4
- udata/tests/site/test_site_api.py +3 -3
- udata/tests/site/test_site_metrics.py +3 -3
- udata/tests/site/test_site_rdf.py +6 -6
- udata/tests/test_activity.py +0 -12
- udata/tests/test_transfer.py +17 -18
- {udata-7.0.6.dist-info → udata-7.0.6.dev28209.dist-info}/METADATA +4 -9
- {udata-7.0.6.dist-info → udata-7.0.6.dev28209.dist-info}/RECORD +37 -43
- {udata-7.0.6.dist-info → udata-7.0.6.dev28209.dist-info}/entry_points.txt +0 -1
- udata/harvest/tests/csw_dcat/XSLT.xml +0 -4298
- udata/harvest/tests/csw_dcat/geonetwork-iso-page-1.xml +0 -1291
- udata/harvest/tests/csw_dcat/geonetwork-iso-page-3.xml +0 -1139
- udata/harvest/tests/csw_dcat/geonetwork-iso-page-5.xml +0 -1266
- udata/harvest/tests/dcat/evian.json +0 -464
- udata/migrations/2024-03-22-migrate-activity-kwargs-to-extras.py +0 -16
- {udata-7.0.6.dist-info → udata-7.0.6.dev28209.dist-info}/LICENSE +0 -0
- {udata-7.0.6.dist-info → udata-7.0.6.dev28209.dist-info}/WHEEL +0 -0
- {udata-7.0.6.dist-info → udata-7.0.6.dev28209.dist-info}/top_level.txt +0 -0
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
from datetime import date
|
|
2
1
|
import logging
|
|
3
2
|
import os
|
|
4
|
-
import
|
|
3
|
+
from flask import current_app
|
|
5
4
|
|
|
6
5
|
import pytest
|
|
7
6
|
|
|
7
|
+
from datetime import date
|
|
8
8
|
import boto3
|
|
9
|
-
from flask import current_app
|
|
10
9
|
import xml.etree.ElementTree as ET
|
|
11
|
-
|
|
12
10
|
from udata.harvest.models import HarvestJob
|
|
11
|
+
|
|
13
12
|
from udata.models import Dataset
|
|
14
13
|
from udata.core.organization.factories import OrganizationFactory
|
|
15
14
|
from udata.core.dataset.factories import LicenseFactory, ResourceSchemaMockData
|
|
16
15
|
from udata.storage.s3 import get_from_json
|
|
17
16
|
|
|
18
17
|
from .factories import HarvestSourceFactory
|
|
19
|
-
from ..backends.dcat import URIS_TO_REPLACE
|
|
18
|
+
from ..backends.dcat import URIS_TO_REPLACE
|
|
20
19
|
from .. import actions
|
|
21
20
|
|
|
22
21
|
log = logging.getLogger(__name__)
|
|
@@ -161,21 +160,6 @@ class DcatBackendTest:
|
|
|
161
160
|
assert len(datasets['1'].resources) == 2
|
|
162
161
|
assert len(datasets['2'].resources) == 2
|
|
163
162
|
|
|
164
|
-
def test_harvest_literal_spatial(self, rmock):
|
|
165
|
-
url = mock_dcat(rmock, 'evian.json')
|
|
166
|
-
org = OrganizationFactory()
|
|
167
|
-
source = HarvestSourceFactory(backend='dcat',
|
|
168
|
-
url=url,
|
|
169
|
-
organization=org)
|
|
170
|
-
|
|
171
|
-
actions.run(source.slug)
|
|
172
|
-
|
|
173
|
-
datasets = {d.harvest.dct_identifier: d for d in Dataset.objects}
|
|
174
|
-
assert len(datasets) == 8
|
|
175
|
-
assert datasets['https://www.arcgis.com/home/item.html?id=f6565516d1354383b25793e630cf3f2b&sublayer=5'].spatial is not None
|
|
176
|
-
assert datasets['https://www.arcgis.com/home/item.html?id=f6565516d1354383b25793e630cf3f2b&sublayer=5'].spatial.geom == {'type': 'MultiPolygon', 'coordinates': [[[[6.5735, 46.3912], [6.6069, 46.3912], [6.6069, 46.4028], [6.5735, 46.4028], [6.5735, 46.3912]]]]}
|
|
177
|
-
|
|
178
|
-
|
|
179
163
|
@pytest.mark.skip(reason="Mocking S3 requires `moto` which is not available for our current Python 3.7. We can manually test it.")
|
|
180
164
|
@pytest.mark.options(SCHEMA_CATALOG_URL='https://example.com/schemas', HARVEST_JOBS_RETENTION_DAYS=0)
|
|
181
165
|
# @mock_s3
|
|
@@ -630,7 +614,7 @@ class DcatBackendTest:
|
|
|
630
614
|
|
|
631
615
|
|
|
632
616
|
@pytest.mark.usefixtures('clean_db')
|
|
633
|
-
@pytest.mark.options(PLUGINS=['csw'])
|
|
617
|
+
@pytest.mark.options(PLUGINS=['csw-dcat'])
|
|
634
618
|
class CswDcatBackendTest:
|
|
635
619
|
|
|
636
620
|
def test_geonetworkv4(self, rmock):
|
|
@@ -678,60 +662,3 @@ class CswDcatBackendTest:
|
|
|
678
662
|
|
|
679
663
|
assert 'User-Agent' in get_mock.last_request.headers
|
|
680
664
|
assert get_mock.last_request.headers['User-Agent'] == 'uData/0.1 csw-dcat'
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
@pytest.mark.usefixtures('clean_db')
|
|
684
|
-
@pytest.mark.options(PLUGINS=['csw'])
|
|
685
|
-
class CswIso19139DcatBackendTest:
|
|
686
|
-
|
|
687
|
-
def test_geo2france(self, rmock):
|
|
688
|
-
|
|
689
|
-
with open(os.path.join(CSW_DCAT_FILES_DIR, "XSLT.xml"), "r") as f:
|
|
690
|
-
xslt = f.read()
|
|
691
|
-
url = mock_csw_pagination(rmock, 'geonetwork/srv/eng/csw.rdf', 'geonetwork-iso-page-{}.xml')
|
|
692
|
-
rmock.get(CswIso19139DcatBackend.XSL_URL, text=xslt)
|
|
693
|
-
org = OrganizationFactory()
|
|
694
|
-
source = HarvestSourceFactory(backend='csw-iso-19139',
|
|
695
|
-
url=url,
|
|
696
|
-
organization=org)
|
|
697
|
-
|
|
698
|
-
actions.run(source.slug)
|
|
699
|
-
|
|
700
|
-
source.reload()
|
|
701
|
-
|
|
702
|
-
job = source.get_last_job()
|
|
703
|
-
assert len(job.items) == 6
|
|
704
|
-
|
|
705
|
-
datasets = {d.harvest.dct_identifier: d for d in Dataset.objects}
|
|
706
|
-
|
|
707
|
-
assert len(datasets) == 6
|
|
708
|
-
|
|
709
|
-
# First dataset
|
|
710
|
-
# dataset identifier is gmd:RS_Identifier > gmd:codeSpace + gmd:code
|
|
711
|
-
dataset = datasets['http://catalogue.geo-ide.developpement-durable.gouv.fr/fr-120066022-orphan-residentifier-140d31c6-643d-42a9-85df-2737a118e144']
|
|
712
|
-
assert dataset.title == "Plan local d'urbanisme de la commune de Cartigny"
|
|
713
|
-
assert dataset.description == "Le présent standard de données COVADIS concerne les documents de plans locaux d'urbanisme (PLU) et les plans d'occupation des sols (POS qui valent PLU)."
|
|
714
|
-
assert set(dataset.tags) == set([
|
|
715
|
-
'amenagement-urbanisme-zonages-planification', 'cartigny',
|
|
716
|
-
'document-durbanisme', 'donnees-ouvertes', 'plu', 'usage-des-sols'
|
|
717
|
-
])
|
|
718
|
-
assert dataset.harvest.created_at.date() == date(2017, 10, 7)
|
|
719
|
-
assert dataset.spatial.geom == {'type': 'MultiPolygon', 'coordinates':
|
|
720
|
-
[[[[3.28133559, 50.48188019], [1.31279111, 50.48188019], [1.31279111, 49.38547516], [3.28133559, 49.38547516], [3.28133559, 50.48188019]]]]
|
|
721
|
-
}
|
|
722
|
-
assert dataset.contact_point.name == 'DDTM 80 (Direction Départementale des Territoires et de la Mer de la Somme)'
|
|
723
|
-
assert dataset.contact_point.email == 'ddtm-sap-bsig@somme.gouv.fr'
|
|
724
|
-
|
|
725
|
-
# License is not properly mapped in XSLT conversion
|
|
726
|
-
assert dataset.license is None
|
|
727
|
-
|
|
728
|
-
# Distributions don't get properly mapped to distribution with this XSLT if missing CI_OnLineFunctionCode.
|
|
729
|
-
# A CI_OnLineFunctionCode was added explicitely on one of the Online Resources.
|
|
730
|
-
# (See mapping at: https://semiceu.github.io/GeoDCAT-AP/releases/2.0.0/#resource-locator---on-line-resource)
|
|
731
|
-
assert len(dataset.resources) == 1
|
|
732
|
-
resource = dataset.resources[0]
|
|
733
|
-
assert resource.title == 'Téléchargement direct du lot et des documents associés'
|
|
734
|
-
assert resource.url == 'http://atom.geo-ide.developpement-durable.gouv.fr/atomArchive/GetResource?id=fr-120066022-ldd-cab63273-b3ae-4e8a-ae1c-6192e45faa94&datasetAggregate=true'
|
|
735
|
-
|
|
736
|
-
# Sadly resource format is parsed as a blank node. Format parsing should be improved.
|
|
737
|
-
assert re.match(r'n[0-9a-f]{32}', resource.format)
|
udata/rdf.py
CHANGED
udata/search/__init__.py
CHANGED
|
@@ -24,7 +24,7 @@ def reindex(classname, id):
|
|
|
24
24
|
document = adapter_class.serialize(obj)
|
|
25
25
|
if adapter_class.is_indexable(obj):
|
|
26
26
|
log.info('Indexing %s (%s)', model.__name__, obj.id)
|
|
27
|
-
url = f"{current_app.config['SEARCH_SERVICE_API_URL']}{adapter_class.search_url}index"
|
|
27
|
+
url = f"{current_app.config['SEARCH_SERVICE_API_URL']}{adapter_class.search_url}/index"
|
|
28
28
|
try:
|
|
29
29
|
payload = {
|
|
30
30
|
'document': document
|
|
@@ -35,7 +35,7 @@ def reindex(classname, id):
|
|
|
35
35
|
log.exception('Unable to index/unindex %s "%s"', model.__name__, str(obj.id))
|
|
36
36
|
else:
|
|
37
37
|
log.info('Unindexing %s (%s)', model.__name__, obj.id)
|
|
38
|
-
url = f"{current_app.config['SEARCH_SERVICE_API_URL']}{adapter_class.search_url}{str(obj.id)}/unindex"
|
|
38
|
+
url = f"{current_app.config['SEARCH_SERVICE_API_URL']}{adapter_class.search_url}/{str(obj.id)}/unindex"
|
|
39
39
|
try:
|
|
40
40
|
r = requests.delete(url)
|
|
41
41
|
if r.status_code == 404:
|
|
@@ -17,7 +17,7 @@ from udata.core.dataset.api_fields import (dataset_harvest_fields,
|
|
|
17
17
|
from udata.core.dataset.factories import (CommunityResourceFactory,
|
|
18
18
|
DatasetFactory, LicenseFactory,
|
|
19
19
|
ResourceFactory, ResourceSchemaMockData,
|
|
20
|
-
|
|
20
|
+
VisibleDatasetFactory)
|
|
21
21
|
from udata.core.dataset.models import (HarvestDatasetMetadata,
|
|
22
22
|
HarvestResourceMetadata, ResourceMixin)
|
|
23
23
|
from udata.core.organization.factories import OrganizationFactory
|
|
@@ -44,13 +44,12 @@ SAMPLE_GEOM = {
|
|
|
44
44
|
]
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
47
|
class DatasetAPITest(APITestCase):
|
|
49
48
|
modules = []
|
|
50
49
|
|
|
51
50
|
def test_dataset_api_list(self):
|
|
52
51
|
'''It should fetch a dataset list from the API'''
|
|
53
|
-
datasets = [
|
|
52
|
+
datasets = [VisibleDatasetFactory() for i in range(2)]
|
|
54
53
|
|
|
55
54
|
response = self.get(url_for('api.datasets'))
|
|
56
55
|
self.assert200(response)
|
|
@@ -59,10 +58,10 @@ class DatasetAPITest(APITestCase):
|
|
|
59
58
|
|
|
60
59
|
def test_dataset_api_full_text_search(self):
|
|
61
60
|
'''Should proceed to full text search on datasets'''
|
|
62
|
-
[
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
dataset =
|
|
61
|
+
[VisibleDatasetFactory() for i in range(2)]
|
|
62
|
+
VisibleDatasetFactory(title="some spécial integer")
|
|
63
|
+
VisibleDatasetFactory(title="some spécial float")
|
|
64
|
+
dataset = VisibleDatasetFactory(title="some spécial chars")
|
|
66
65
|
|
|
67
66
|
# with accent
|
|
68
67
|
response = self.get(url_for('api.datasets', q='some spécial chars'))
|
|
@@ -83,9 +82,9 @@ class DatasetAPITest(APITestCase):
|
|
|
83
82
|
def test_dataset_api_sorting(self):
|
|
84
83
|
'''Should sort datasets results from the API'''
|
|
85
84
|
self.login()
|
|
86
|
-
[
|
|
85
|
+
[VisibleDatasetFactory() for i in range(2)]
|
|
87
86
|
|
|
88
|
-
to_follow =
|
|
87
|
+
to_follow = VisibleDatasetFactory(title="dataset to follow")
|
|
89
88
|
|
|
90
89
|
response = self.post(url_for('api.dataset_followers', id=to_follow.id))
|
|
91
90
|
self.assert201(response)
|
|
@@ -101,8 +100,8 @@ class DatasetAPITest(APITestCase):
|
|
|
101
100
|
|
|
102
101
|
def test_dataset_api_sorting_created(self):
|
|
103
102
|
self.login()
|
|
104
|
-
first =
|
|
105
|
-
second =
|
|
103
|
+
first = VisibleDatasetFactory(title="first created dataset")
|
|
104
|
+
second = VisibleDatasetFactory(title="second created dataset")
|
|
106
105
|
response = self.get(url_for('api.datasets', sort='created'))
|
|
107
106
|
self.assert200(response)
|
|
108
107
|
self.assertEqual(response.json['data'][0]['id'], str(first.id))
|
|
@@ -124,8 +123,8 @@ class DatasetAPITest(APITestCase):
|
|
|
124
123
|
def test_dataset_api_default_sorting(self):
|
|
125
124
|
# Default sort should be -created
|
|
126
125
|
self.login()
|
|
127
|
-
[
|
|
128
|
-
last =
|
|
126
|
+
[VisibleDatasetFactory(title="some created dataset") for i in range(10)]
|
|
127
|
+
last = VisibleDatasetFactory(title="last created dataset")
|
|
129
128
|
response = self.get(url_for('api.datasets'))
|
|
130
129
|
self.assert200(response)
|
|
131
130
|
self.assertEqual(response.json['data'][0]['id'], str(last.id))
|
|
@@ -135,31 +134,31 @@ class DatasetAPITest(APITestCase):
|
|
|
135
134
|
owner = UserFactory()
|
|
136
135
|
org = OrganizationFactory()
|
|
137
136
|
|
|
138
|
-
[
|
|
137
|
+
[VisibleDatasetFactory() for i in range(2)]
|
|
139
138
|
|
|
140
|
-
tag_dataset =
|
|
141
|
-
license_dataset =
|
|
139
|
+
tag_dataset = VisibleDatasetFactory(tags=['my-tag', 'other'])
|
|
140
|
+
license_dataset = VisibleDatasetFactory(license=LicenseFactory(id='cc-by'))
|
|
142
141
|
format_dataset = DatasetFactory(resources=[ResourceFactory(format='my-format')])
|
|
143
|
-
featured_dataset =
|
|
144
|
-
topic_dataset =
|
|
142
|
+
featured_dataset = VisibleDatasetFactory(featured=True)
|
|
143
|
+
topic_dataset = VisibleDatasetFactory()
|
|
145
144
|
topic = TopicFactory(datasets=[topic_dataset])
|
|
146
145
|
|
|
147
146
|
paca, _, _ = create_geozones_fixtures()
|
|
148
|
-
geozone_dataset =
|
|
149
|
-
granularity_dataset =
|
|
147
|
+
geozone_dataset = VisibleDatasetFactory(spatial=SpatialCoverageFactory(zones=[paca.id]))
|
|
148
|
+
granularity_dataset = VisibleDatasetFactory(
|
|
150
149
|
spatial=SpatialCoverageFactory(granularity='country')
|
|
151
150
|
)
|
|
152
151
|
|
|
153
152
|
temporal_coverage = db.DateRange(start='2022-05-03', end='2022-05-04')
|
|
154
153
|
temporal_coverage_dataset = DatasetFactory(temporal_coverage=temporal_coverage)
|
|
155
154
|
|
|
156
|
-
owner_dataset =
|
|
157
|
-
org_dataset =
|
|
155
|
+
owner_dataset = VisibleDatasetFactory(owner=owner)
|
|
156
|
+
org_dataset = VisibleDatasetFactory(organization=org)
|
|
158
157
|
|
|
159
|
-
schema_dataset =
|
|
158
|
+
schema_dataset = VisibleDatasetFactory(resources=[
|
|
160
159
|
ResourceFactory(schema={'name': 'my-schema', 'url': 'https://example.org', 'version': '1.0.0'})
|
|
161
160
|
])
|
|
162
|
-
schema_version2_dataset =
|
|
161
|
+
schema_version2_dataset = VisibleDatasetFactory(resources=[
|
|
163
162
|
ResourceFactory(schema={'name': 'other-schema', 'url': 'https://example.org', 'version': '2.0.0'})
|
|
164
163
|
])
|
|
165
164
|
|
|
@@ -271,7 +270,7 @@ class DatasetAPITest(APITestCase):
|
|
|
271
270
|
|
|
272
271
|
def test_dataset_api_get_deleted(self):
|
|
273
272
|
'''It should not fetch a deleted dataset from the API and raise 410'''
|
|
274
|
-
dataset =
|
|
273
|
+
dataset = VisibleDatasetFactory(deleted=datetime.utcnow())
|
|
275
274
|
|
|
276
275
|
response = self.get(url_for('api.dataset', dataset=dataset))
|
|
277
276
|
self.assert410(response)
|
|
@@ -279,7 +278,7 @@ class DatasetAPITest(APITestCase):
|
|
|
279
278
|
def test_dataset_api_get_deleted_but_authorized(self):
|
|
280
279
|
'''It should a deleted dataset from the API if user is authorized'''
|
|
281
280
|
self.login()
|
|
282
|
-
dataset =
|
|
281
|
+
dataset = VisibleDatasetFactory(owner=self.user,
|
|
283
282
|
deleted=datetime.utcnow())
|
|
284
283
|
|
|
285
284
|
response = self.get(url_for('api.dataset', dataset=dataset))
|
|
@@ -452,7 +451,7 @@ class DatasetAPITest(APITestCase):
|
|
|
452
451
|
def test_dataset_api_update_with_resources(self):
|
|
453
452
|
'''It should update a dataset from the API with resources parameters'''
|
|
454
453
|
user = self.login()
|
|
455
|
-
dataset =
|
|
454
|
+
dataset = VisibleDatasetFactory(owner=user)
|
|
456
455
|
initial_length = len(dataset.resources)
|
|
457
456
|
data = dataset.to_dict()
|
|
458
457
|
data['resources'].append(ResourceFactory.as_dict())
|
|
@@ -465,7 +464,7 @@ class DatasetAPITest(APITestCase):
|
|
|
465
464
|
|
|
466
465
|
def test_dataset_api_update_private(self):
|
|
467
466
|
user = self.login()
|
|
468
|
-
dataset =
|
|
467
|
+
dataset = DatasetFactory(owner=user, private=True)
|
|
469
468
|
data = dataset.to_dict()
|
|
470
469
|
data['description'] = 'new description'
|
|
471
470
|
del data['private']
|
|
@@ -488,10 +487,12 @@ class DatasetAPITest(APITestCase):
|
|
|
488
487
|
dataset.reload()
|
|
489
488
|
self.assertEqual(dataset.private, True)
|
|
490
489
|
|
|
490
|
+
|
|
491
|
+
|
|
491
492
|
def test_dataset_api_update_new_resource_with_extras(self):
|
|
492
493
|
'''It should update a dataset with a new resource with extras'''
|
|
493
494
|
user = self.login()
|
|
494
|
-
dataset =
|
|
495
|
+
dataset = VisibleDatasetFactory(owner=user)
|
|
495
496
|
data = dataset.to_dict()
|
|
496
497
|
resource_data = ResourceFactory.as_dict()
|
|
497
498
|
resource_data['extras'] = {'extra:id': 'id'}
|
|
@@ -507,7 +508,7 @@ class DatasetAPITest(APITestCase):
|
|
|
507
508
|
def test_dataset_api_update_existing_resource_with_extras(self):
|
|
508
509
|
'''It should update a dataset's existing resource with extras'''
|
|
509
510
|
user = self.login()
|
|
510
|
-
dataset =
|
|
511
|
+
dataset = VisibleDatasetFactory(owner=user)
|
|
511
512
|
data = dataset.to_dict()
|
|
512
513
|
data['resources'][0]['extras'] = {'extra:id': 'id'}
|
|
513
514
|
response = self.put(url_for('api.dataset', dataset=dataset), data)
|
|
@@ -682,7 +683,7 @@ class DatasetAPITest(APITestCase):
|
|
|
682
683
|
def test_dataset_api_delete(self):
|
|
683
684
|
'''It should delete a dataset from the API'''
|
|
684
685
|
user = self.login()
|
|
685
|
-
dataset =
|
|
686
|
+
dataset = VisibleDatasetFactory(owner=user)
|
|
686
687
|
response = self.delete(url_for('api.dataset', dataset=dataset))
|
|
687
688
|
|
|
688
689
|
self.assertStatus(response, 204)
|
|
@@ -696,7 +697,7 @@ class DatasetAPITest(APITestCase):
|
|
|
696
697
|
def test_dataset_api_delete_deleted(self):
|
|
697
698
|
'''It should delete a deleted dataset from the API and raise 410'''
|
|
698
699
|
user = self.login()
|
|
699
|
-
dataset =
|
|
700
|
+
dataset = VisibleDatasetFactory(owner=user, deleted=datetime.utcnow())
|
|
700
701
|
response = self.delete(url_for('api.dataset', dataset=dataset))
|
|
701
702
|
|
|
702
703
|
self.assert410(response)
|
|
@@ -1471,8 +1472,8 @@ class DatasetArchivedAPITest(APITestCase):
|
|
|
1471
1472
|
|
|
1472
1473
|
def test_dataset_api_search_archived(self):
|
|
1473
1474
|
'''It should search datasets from the API, excluding archived ones'''
|
|
1474
|
-
|
|
1475
|
-
dataset =
|
|
1475
|
+
VisibleDatasetFactory(archived=None)
|
|
1476
|
+
dataset = VisibleDatasetFactory(archived=datetime.utcnow())
|
|
1476
1477
|
|
|
1477
1478
|
response = self.get(url_for('api.datasets', q=''))
|
|
1478
1479
|
self.assert200(response)
|
|
@@ -1482,7 +1483,7 @@ class DatasetArchivedAPITest(APITestCase):
|
|
|
1482
1483
|
|
|
1483
1484
|
def test_dataset_api_get_archived(self):
|
|
1484
1485
|
'''It should fetch an archived dataset from the API and return 200'''
|
|
1485
|
-
dataset =
|
|
1486
|
+
dataset = VisibleDatasetFactory(archived=datetime.utcnow())
|
|
1486
1487
|
response = self.get(url_for('api.dataset', dataset=dataset))
|
|
1487
1488
|
self.assert200(response)
|
|
1488
1489
|
|
|
@@ -1527,7 +1528,7 @@ class CommunityResourceAPITest(APITestCase):
|
|
|
1527
1528
|
|
|
1528
1529
|
def test_community_resource_api_create_dataset_binding(self):
|
|
1529
1530
|
'''It should create a community resource linked to the right dataset'''
|
|
1530
|
-
dataset =
|
|
1531
|
+
dataset = VisibleDatasetFactory()
|
|
1531
1532
|
self.login()
|
|
1532
1533
|
response = self.post(
|
|
1533
1534
|
url_for('api.upload_new_community_resource', dataset=dataset),
|
|
@@ -1539,7 +1540,7 @@ class CommunityResourceAPITest(APITestCase):
|
|
|
1539
1540
|
|
|
1540
1541
|
def test_community_resource_api_create(self):
|
|
1541
1542
|
'''It should create a community resource from the API'''
|
|
1542
|
-
dataset =
|
|
1543
|
+
dataset = VisibleDatasetFactory()
|
|
1543
1544
|
self.login()
|
|
1544
1545
|
response = self.post(
|
|
1545
1546
|
url_for('api.upload_new_community_resource', dataset=dataset),
|
|
@@ -1559,7 +1560,7 @@ class CommunityResourceAPITest(APITestCase):
|
|
|
1559
1560
|
|
|
1560
1561
|
def test_community_resource_api_create_as_org(self):
|
|
1561
1562
|
'''It should create a community resource as org from the API'''
|
|
1562
|
-
dataset =
|
|
1563
|
+
dataset = VisibleDatasetFactory()
|
|
1563
1564
|
user = self.login()
|
|
1564
1565
|
org = OrganizationFactory(members=[
|
|
1565
1566
|
Member(user=user, role='admin')
|
|
@@ -1611,7 +1612,7 @@ class CommunityResourceAPITest(APITestCase):
|
|
|
1611
1612
|
|
|
1612
1613
|
def test_community_resource_api_update_with_file(self):
|
|
1613
1614
|
'''It should update a community resource file from the API'''
|
|
1614
|
-
dataset =
|
|
1615
|
+
dataset = VisibleDatasetFactory()
|
|
1615
1616
|
user = self.login()
|
|
1616
1617
|
community_resource = CommunityResourceFactory(dataset=dataset,
|
|
1617
1618
|
owner=user)
|
|
@@ -1636,7 +1637,7 @@ class CommunityResourceAPITest(APITestCase):
|
|
|
1636
1637
|
|
|
1637
1638
|
def test_community_resource_file_update_old_file_deletion(self):
|
|
1638
1639
|
'''It should update a community resource's file and delete the old one'''
|
|
1639
|
-
dataset =
|
|
1640
|
+
dataset = VisibleDatasetFactory()
|
|
1640
1641
|
user = self.login()
|
|
1641
1642
|
community_resource = CommunityResourceFactory(dataset=dataset,
|
|
1642
1643
|
owner=user)
|
|
@@ -1663,7 +1664,7 @@ class CommunityResourceAPITest(APITestCase):
|
|
|
1663
1664
|
def test_community_resource_api_create_remote(self):
|
|
1664
1665
|
'''It should create a remote community resource from the API'''
|
|
1665
1666
|
user = self.login()
|
|
1666
|
-
dataset =
|
|
1667
|
+
dataset = VisibleDatasetFactory()
|
|
1667
1668
|
attrs = CommunityResourceFactory.as_dict()
|
|
1668
1669
|
attrs['filetype'] = 'remote'
|
|
1669
1670
|
attrs['dataset'] = str(dataset.id)
|
|
@@ -1684,7 +1685,7 @@ class CommunityResourceAPITest(APITestCase):
|
|
|
1684
1685
|
def test_community_resource_api_unallowed_create_filetype_file(self):
|
|
1685
1686
|
'''It should create a remote community resource from the API'''
|
|
1686
1687
|
self.login()
|
|
1687
|
-
dataset =
|
|
1688
|
+
dataset = VisibleDatasetFactory()
|
|
1688
1689
|
attrs = CommunityResourceFactory.as_dict()
|
|
1689
1690
|
attrs['filetype'] = 'file' # to be explicit
|
|
1690
1691
|
attrs['dataset'] = str(dataset.id)
|
|
@@ -1733,7 +1734,7 @@ class CommunityResourceAPITest(APITestCase):
|
|
|
1733
1734
|
self.assertEqual(CommunityResource.objects.count(), 0)
|
|
1734
1735
|
|
|
1735
1736
|
def test_community_resource_api_delete(self):
|
|
1736
|
-
dataset =
|
|
1737
|
+
dataset = VisibleDatasetFactory()
|
|
1737
1738
|
self.login()
|
|
1738
1739
|
|
|
1739
1740
|
response = self.post(
|
|
@@ -1790,8 +1791,7 @@ class DatasetSchemasAPITest:
|
|
|
1790
1791
|
assert response.json == []
|
|
1791
1792
|
|
|
1792
1793
|
@pytest.mark.options(SCHEMA_CATALOG_URL='https://example.com/notfound')
|
|
1793
|
-
def test_dataset_schemas_api_list_not_found(self, api
|
|
1794
|
-
rmock.get('https://example.com/notfound', status_code=404)
|
|
1794
|
+
def test_dataset_schemas_api_list_not_found(self, api):
|
|
1795
1795
|
response = api.get(url_for('api.schemas'))
|
|
1796
1796
|
assert404(response)
|
|
1797
1797
|
|
udata/tests/api/test_me_api.py
CHANGED
|
@@ -6,7 +6,8 @@ from udata.models import Discussion, Follow, Member, User
|
|
|
6
6
|
from udata.core.discussions.models import Message as DiscMsg
|
|
7
7
|
from udata.core.dataset.factories import (
|
|
8
8
|
CommunityResourceFactory,
|
|
9
|
-
DatasetFactory
|
|
9
|
+
DatasetFactory,
|
|
10
|
+
VisibleDatasetFactory,
|
|
10
11
|
)
|
|
11
12
|
from udata.core.dataset.activities import UserCreatedDataset
|
|
12
13
|
from udata.core.discussions.factories import DiscussionFactory
|
|
@@ -88,9 +89,9 @@ class MeAPITest(APITestCase):
|
|
|
88
89
|
member = Member(user=user, role='editor')
|
|
89
90
|
organization = OrganizationFactory(members=[member])
|
|
90
91
|
community_resources = [
|
|
91
|
-
|
|
92
|
+
VisibleDatasetFactory(owner=user) for _ in range(2)]
|
|
92
93
|
org_datasets = [
|
|
93
|
-
|
|
94
|
+
VisibleDatasetFactory(organization=organization)
|
|
94
95
|
for _ in range(2)]
|
|
95
96
|
|
|
96
97
|
response = self.get(url_for('api.my_org_datasets'))
|
|
@@ -104,15 +105,15 @@ class MeAPITest(APITestCase):
|
|
|
104
105
|
member = Member(user=user, role='editor')
|
|
105
106
|
organization = OrganizationFactory(members=[member])
|
|
106
107
|
datasets = [
|
|
107
|
-
|
|
108
|
+
VisibleDatasetFactory(owner=user, title='foô'),
|
|
108
109
|
]
|
|
109
110
|
org_datasets = [
|
|
110
|
-
|
|
111
|
+
VisibleDatasetFactory(organization=organization, title='foô'),
|
|
111
112
|
]
|
|
112
113
|
|
|
113
114
|
# Should not be listed.
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
VisibleDatasetFactory(owner=user)
|
|
116
|
+
VisibleDatasetFactory(organization=organization)
|
|
116
117
|
|
|
117
118
|
response = self.get(url_for('api.my_org_datasets'),
|
|
118
119
|
qs={'q': 'foô'})
|
|
@@ -194,8 +195,8 @@ class MeAPITest(APITestCase):
|
|
|
194
195
|
organization = OrganizationFactory(members=[member])
|
|
195
196
|
reuse = ReuseFactory(owner=user)
|
|
196
197
|
org_reuse = ReuseFactory(organization=organization)
|
|
197
|
-
dataset =
|
|
198
|
-
org_dataset =
|
|
198
|
+
dataset = VisibleDatasetFactory(owner=user)
|
|
199
|
+
org_dataset = VisibleDatasetFactory(organization=organization)
|
|
199
200
|
|
|
200
201
|
discussions = [
|
|
201
202
|
Discussion.objects.create(subject=dataset, title='', user=user),
|
|
@@ -205,7 +206,7 @@ class MeAPITest(APITestCase):
|
|
|
205
206
|
]
|
|
206
207
|
|
|
207
208
|
# Should not be listed
|
|
208
|
-
Discussion.objects.create(subject=
|
|
209
|
+
Discussion.objects.create(subject=VisibleDatasetFactory(), title='', user=user)
|
|
209
210
|
Discussion.objects.create(subject=ReuseFactory(), title='', user=user)
|
|
210
211
|
|
|
211
212
|
response = self.get(url_for('api.my_org_discussions'))
|
|
@@ -218,8 +219,8 @@ class MeAPITest(APITestCase):
|
|
|
218
219
|
organization = OrganizationFactory(members=[member])
|
|
219
220
|
reuse = ReuseFactory(owner=user)
|
|
220
221
|
org_reuse = ReuseFactory(organization=organization)
|
|
221
|
-
dataset =
|
|
222
|
-
org_dataset =
|
|
222
|
+
dataset = VisibleDatasetFactory(owner=user)
|
|
223
|
+
org_dataset = VisibleDatasetFactory(organization=organization)
|
|
223
224
|
|
|
224
225
|
discussions = [
|
|
225
226
|
Discussion.objects.create(subject=dataset, title='foô', user=user),
|
|
@@ -231,7 +232,7 @@ class MeAPITest(APITestCase):
|
|
|
231
232
|
Discussion.objects.create(subject=org_dataset, title='', user=user),
|
|
232
233
|
|
|
233
234
|
# Should really not be listed.
|
|
234
|
-
Discussion.objects.create(subject=
|
|
235
|
+
Discussion.objects.create(subject=VisibleDatasetFactory(), title='foô', user=user)
|
|
235
236
|
Discussion.objects.create(subject=ReuseFactory(), title='foô', user=user)
|
|
236
237
|
|
|
237
238
|
response = self.get(url_for('api.my_org_discussions'), qs={'q': 'foô'})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import pytest
|
|
2
2
|
|
|
3
3
|
from udata.core.dataset.actions import archive
|
|
4
|
-
from udata.core.dataset.factories import
|
|
4
|
+
from udata.core.dataset.factories import VisibleDatasetFactory
|
|
5
5
|
from udata.core.discussions.models import Discussion
|
|
6
6
|
from udata.core.user.factories import UserFactory
|
|
7
7
|
|
|
@@ -13,7 +13,7 @@ class DatasetActionsTest:
|
|
|
13
13
|
user = UserFactory()
|
|
14
14
|
app.config['ARCHIVE_COMMENT_USER_ID'] = user.id
|
|
15
15
|
|
|
16
|
-
dataset =
|
|
16
|
+
dataset = VisibleDatasetFactory()
|
|
17
17
|
|
|
18
18
|
archive(dataset, comment=True)
|
|
19
19
|
|
|
@@ -2,14 +2,14 @@ import pytest
|
|
|
2
2
|
|
|
3
3
|
from tempfile import NamedTemporaryFile
|
|
4
4
|
|
|
5
|
-
from udata.core.dataset.factories import
|
|
5
|
+
from udata.core.dataset.factories import VisibleDatasetFactory
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
@pytest.mark.usefixtures('clean_db')
|
|
9
9
|
class DatasetCommandTest:
|
|
10
10
|
|
|
11
11
|
def test_dataset_archive_one(self, cli):
|
|
12
|
-
dataset =
|
|
12
|
+
dataset = VisibleDatasetFactory()
|
|
13
13
|
|
|
14
14
|
cli('dataset', 'archive-one', str(dataset.id))
|
|
15
15
|
|
|
@@ -17,7 +17,7 @@ class DatasetCommandTest:
|
|
|
17
17
|
assert dataset.archived is not None
|
|
18
18
|
|
|
19
19
|
def test_dataset_archive(self, cli):
|
|
20
|
-
datasets = [
|
|
20
|
+
datasets = [VisibleDatasetFactory() for _ in range(2)]
|
|
21
21
|
|
|
22
22
|
with NamedTemporaryFile(mode='w', encoding='utf8') as temp:
|
|
23
23
|
temp.write('\n'.join((str(d.id) for d in datasets)))
|
|
@@ -524,8 +524,7 @@ class LicenseModelTest:
|
|
|
524
524
|
|
|
525
525
|
class ResourceSchemaTest:
|
|
526
526
|
@pytest.mark.options(SCHEMA_CATALOG_URL='https://example.com/notfound')
|
|
527
|
-
def test_resource_schema_objects_404_endpoint(self
|
|
528
|
-
rmock.get('https://example.com/notfound', status_code=404)
|
|
527
|
+
def test_resource_schema_objects_404_endpoint(self):
|
|
529
528
|
with pytest.raises(SchemasCatalogNotFoundException):
|
|
530
529
|
ResourceSchema.objects()
|
|
531
530
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
|
|
3
|
-
from udata.core.dataset.factories import DatasetFactory,
|
|
3
|
+
from udata.core.dataset.factories import DatasetFactory, VisibleDatasetFactory
|
|
4
4
|
from udata.core.organization.factories import OrganizationFactory
|
|
5
5
|
from udata.core.followers.signals import on_follow, on_unfollow
|
|
6
6
|
from udata.core.reuse.factories import ReuseFactory, VisibleReuseFactory
|
|
@@ -27,8 +27,8 @@ class OrganizationModelTest(TestCase, DBTestMixin):
|
|
|
27
27
|
reuse = VisibleReuseFactory(organization=org)
|
|
28
28
|
ReuseFactory(organization=org)
|
|
29
29
|
with assert_emit(Dataset.on_create):
|
|
30
|
-
dataset =
|
|
31
|
-
|
|
30
|
+
dataset = VisibleDatasetFactory(organization=org)
|
|
31
|
+
DatasetFactory(organization=org)
|
|
32
32
|
with assert_emit(on_follow):
|
|
33
33
|
follow = Follow.objects.create(following=org, follower=UserFactory(),
|
|
34
34
|
since=datetime.utcnow())
|
|
@@ -9,7 +9,7 @@ from udata.rdf import DCAT, DCT, HYDRA
|
|
|
9
9
|
from udata.tests import TestCase, DBTestMixin
|
|
10
10
|
from udata.core.organization.factories import OrganizationFactory
|
|
11
11
|
from udata.core.organization.rdf import organization_to_rdf, build_org_catalog
|
|
12
|
-
from udata.core.dataset.factories import
|
|
12
|
+
from udata.core.dataset.factories import VisibleDatasetFactory
|
|
13
13
|
from udata.core.dataset.models import Dataset
|
|
14
14
|
from udata.utils import faker
|
|
15
15
|
|
|
@@ -57,7 +57,7 @@ class OrganizationToRdfTest(DBTestMixin, TestCase):
|
|
|
57
57
|
origin_org = OrganizationFactory()
|
|
58
58
|
uri = url_for('api.organization_rdf', org=origin_org.id, _external=True)
|
|
59
59
|
|
|
60
|
-
datasets =
|
|
60
|
+
datasets = VisibleDatasetFactory.create_batch(3, organization=origin_org)
|
|
61
61
|
catalog = build_org_catalog(origin_org, datasets)
|
|
62
62
|
|
|
63
63
|
graph = catalog.graph
|
|
@@ -93,7 +93,7 @@ class OrganizationToRdfTest(DBTestMixin, TestCase):
|
|
|
93
93
|
page=1, page_size=page_size, _external=True)
|
|
94
94
|
uri_last = url_for('api.organization_rdf_format', org=origin_org.id, format='json',
|
|
95
95
|
page=2, page_size=page_size, _external=True)
|
|
96
|
-
|
|
96
|
+
VisibleDatasetFactory.create_batch(total, organization=origin_org)
|
|
97
97
|
|
|
98
98
|
# First page
|
|
99
99
|
datasets = Dataset.objects.paginate(1, page_size)
|
|
@@ -5,7 +5,7 @@ from udata.models import Reuse
|
|
|
5
5
|
from udata.core.dataset import tasks as dataset_tasks
|
|
6
6
|
from udata.core.organization.factories import OrganizationFactory
|
|
7
7
|
from udata.core.reuse.factories import ReuseFactory, VisibleReuseFactory
|
|
8
|
-
from udata.core.dataset.factories import
|
|
8
|
+
from udata.core.dataset.factories import VisibleDatasetFactory
|
|
9
9
|
from udata.core.user.factories import UserFactory
|
|
10
10
|
from udata.core.discussions.factories import DiscussionFactory
|
|
11
11
|
from udata.i18n import gettext as _
|
|
@@ -65,7 +65,7 @@ class ReuseModelTest(TestCase, DBTestMixin):
|
|
|
65
65
|
reuse.save()
|
|
66
66
|
|
|
67
67
|
def test_reuse_metrics(self):
|
|
68
|
-
dataset =
|
|
68
|
+
dataset = VisibleDatasetFactory()
|
|
69
69
|
reuse = VisibleReuseFactory()
|
|
70
70
|
DiscussionFactory(subject=reuse)
|
|
71
71
|
|