udata 10.2.1.dev34767__py2.py3-none-any.whl → 10.2.1.dev34775__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/harvest/actions.py +3 -14
- udata/harvest/api.py +13 -9
- udata/harvest/models.py +5 -0
- udata/harvest/tests/test_actions.py +1 -54
- udata/harvest/tests/test_api.py +33 -1
- udata/static/chunks/{11.0f04e49a40a0a381bcce.js → 11.8a2f7828175824bcd74b.js} +3 -3
- udata/static/chunks/{11.0f04e49a40a0a381bcce.js.map → 11.8a2f7828175824bcd74b.js.map} +1 -1
- udata/static/chunks/{13.d9c1735d14038b94c17e.js → 13.39e106d56f794ebd06a0.js} +2 -2
- udata/static/chunks/{13.d9c1735d14038b94c17e.js.map → 13.39e106d56f794ebd06a0.js.map} +1 -1
- udata/static/chunks/{17.81c57c0dedf812e43013.js → 17.70cbb4a91b002338007e.js} +2 -2
- udata/static/chunks/{17.81c57c0dedf812e43013.js.map → 17.70cbb4a91b002338007e.js.map} +1 -1
- udata/static/chunks/{19.8da42e8359d72afc2618.js → 19.df16abde17a42033a7f8.js} +3 -3
- udata/static/chunks/{19.8da42e8359d72afc2618.js.map → 19.df16abde17a42033a7f8.js.map} +1 -1
- udata/static/chunks/{5.0fa1408dae4e76b87b2e.js → 5.5660483641193b7f8295.js} +3 -3
- udata/static/chunks/{5.0fa1408dae4e76b87b2e.js.map → 5.5660483641193b7f8295.js.map} +1 -1
- udata/static/chunks/{6.d663709d877baa44a71e.js → 6.30dce49d17db07600b06.js} +3 -3
- udata/static/chunks/{6.d663709d877baa44a71e.js.map → 6.30dce49d17db07600b06.js.map} +1 -1
- udata/static/chunks/{8.494b003a94383b142c18.js → 8.54e44b102164ae5e7a67.js} +2 -2
- udata/static/chunks/{8.494b003a94383b142c18.js.map → 8.54e44b102164ae5e7a67.js.map} +1 -1
- udata/static/common.js +1 -1
- udata/static/common.js.map +1 -1
- {udata-10.2.1.dev34767.dist-info → udata-10.2.1.dev34775.dist-info}/METADATA +2 -1
- {udata-10.2.1.dev34767.dist-info → udata-10.2.1.dev34775.dist-info}/RECORD +27 -27
- {udata-10.2.1.dev34767.dist-info → udata-10.2.1.dev34775.dist-info}/LICENSE +0 -0
- {udata-10.2.1.dev34767.dist-info → udata-10.2.1.dev34775.dist-info}/WHEEL +0 -0
- {udata-10.2.1.dev34767.dist-info → udata-10.2.1.dev34775.dist-info}/entry_points.txt +0 -0
- {udata-10.2.1.dev34767.dist-info → udata-10.2.1.dev34775.dist-info}/top_level.txt +0 -0
udata/harvest/actions.py
CHANGED
|
@@ -34,25 +34,14 @@ def list_backends():
|
|
|
34
34
|
return backends.get_all(current_app).values()
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
def
|
|
37
|
+
def list_sources(owner=None, deleted=False):
|
|
38
|
+
"""List all harvest sources"""
|
|
38
39
|
sources = HarvestSource.objects
|
|
39
40
|
if not deleted:
|
|
40
41
|
sources = sources.visible()
|
|
41
42
|
if owner:
|
|
42
43
|
sources = sources.owned_by(owner)
|
|
43
|
-
return sources
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def list_sources(owner=None, deleted=False):
|
|
47
|
-
"""List all harvest sources"""
|
|
48
|
-
return list(_sources_queryset(owner=owner, deleted=deleted))
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def paginate_sources(owner=None, page=1, page_size=DEFAULT_PAGE_SIZE, deleted=False):
|
|
52
|
-
"""Paginate harvest sources"""
|
|
53
|
-
sources = _sources_queryset(owner=owner, deleted=deleted)
|
|
54
|
-
page = max(page or 1, 1)
|
|
55
|
-
return sources.paginate(page, page_size)
|
|
44
|
+
return list(sources)
|
|
56
45
|
|
|
57
46
|
|
|
58
47
|
def get_source(ident):
|
udata/harvest/api.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
from bson import ObjectId
|
|
2
1
|
from flask import current_app, request
|
|
3
2
|
from werkzeug.exceptions import BadRequest
|
|
4
3
|
|
|
@@ -253,6 +252,7 @@ source_parser.add_argument(
|
|
|
253
252
|
source_parser.add_argument(
|
|
254
253
|
"deleted", type=bool, location="args", default=False, help="Include sources flaggued as deleted"
|
|
255
254
|
)
|
|
255
|
+
source_parser.add_argument("q", type=str, location="args", help="The search query")
|
|
256
256
|
|
|
257
257
|
|
|
258
258
|
@ns.route("/sources/", endpoint="harvest_sources")
|
|
@@ -264,15 +264,19 @@ class SourcesAPI(API):
|
|
|
264
264
|
"""List all harvest sources"""
|
|
265
265
|
args = source_parser.parse_args()
|
|
266
266
|
|
|
267
|
-
|
|
268
|
-
api.abort(400, "`owner` arg must be an identifier")
|
|
267
|
+
sources = HarvestSource.objects()
|
|
269
268
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
269
|
+
if not args["deleted"]:
|
|
270
|
+
sources = sources.visible()
|
|
271
|
+
|
|
272
|
+
if args["owner"]:
|
|
273
|
+
sources = sources.owned_by(args["owner"])
|
|
274
|
+
|
|
275
|
+
if args["q"]:
|
|
276
|
+
phrase_query = " ".join([f'"{elem}"' for elem in args["q"].split(" ")])
|
|
277
|
+
sources = sources.search_text(phrase_query)
|
|
278
|
+
|
|
279
|
+
return sources.paginate(args["page"], args["page_size"])
|
|
276
280
|
|
|
277
281
|
@api.secure
|
|
278
282
|
@api.doc("create_harvest_source")
|
udata/harvest/models.py
CHANGED
|
@@ -155,6 +155,11 @@ class HarvestSource(Owned, db.Document):
|
|
|
155
155
|
|
|
156
156
|
meta = {
|
|
157
157
|
"indexes": [
|
|
158
|
+
{
|
|
159
|
+
"fields": ["$name", "$url"],
|
|
160
|
+
"default_language": "french",
|
|
161
|
+
"weights": {"name": 10, "url": 5},
|
|
162
|
+
},
|
|
158
163
|
"-created_at",
|
|
159
164
|
"slug",
|
|
160
165
|
("deleted", "-created_at"),
|
|
@@ -14,7 +14,7 @@ from udata.core.organization.factories import OrganizationFactory
|
|
|
14
14
|
from udata.core.user.factories import UserFactory
|
|
15
15
|
from udata.models import Dataset, PeriodicTask
|
|
16
16
|
from udata.tests.helpers import assert_emit, assert_equal_dates
|
|
17
|
-
from udata.utils import
|
|
17
|
+
from udata.utils import faker
|
|
18
18
|
|
|
19
19
|
from .. import actions, signals
|
|
20
20
|
from ..backends import BaseBackend
|
|
@@ -113,59 +113,6 @@ class HarvestActionsTest:
|
|
|
113
113
|
for source in sources:
|
|
114
114
|
assert source in result
|
|
115
115
|
|
|
116
|
-
def test_paginate_sources(self):
|
|
117
|
-
result = actions.paginate_sources()
|
|
118
|
-
assert isinstance(result, Paginable)
|
|
119
|
-
assert result.page == 1
|
|
120
|
-
assert result.page_size == actions.DEFAULT_PAGE_SIZE
|
|
121
|
-
assert result.total == 0
|
|
122
|
-
assert len(result.objects) == 0
|
|
123
|
-
|
|
124
|
-
HarvestSourceFactory.create_batch(3)
|
|
125
|
-
|
|
126
|
-
result = actions.paginate_sources(page_size=2)
|
|
127
|
-
assert isinstance(result, Paginable)
|
|
128
|
-
assert result.page == 1
|
|
129
|
-
assert result.page_size == 2
|
|
130
|
-
assert result.total == 3
|
|
131
|
-
assert len(result.objects) == 2
|
|
132
|
-
|
|
133
|
-
result = actions.paginate_sources(page=2, page_size=2)
|
|
134
|
-
assert isinstance(result, Paginable)
|
|
135
|
-
assert result.page == 2
|
|
136
|
-
assert result.page_size == 2
|
|
137
|
-
assert result.total == 3
|
|
138
|
-
assert len(result.objects) == 1
|
|
139
|
-
|
|
140
|
-
def test_paginate_sources_exclude_deleted(self):
|
|
141
|
-
HarvestSourceFactory.create_batch(2)
|
|
142
|
-
HarvestSourceFactory(deleted=datetime.utcnow())
|
|
143
|
-
|
|
144
|
-
result = actions.paginate_sources(page_size=2)
|
|
145
|
-
assert isinstance(result, Paginable)
|
|
146
|
-
assert result.page == 1
|
|
147
|
-
assert result.page_size == 2
|
|
148
|
-
assert result.total == 2
|
|
149
|
-
assert len(result.objects) == 2
|
|
150
|
-
|
|
151
|
-
def test_paginate_sources_include_deleted(self):
|
|
152
|
-
HarvestSourceFactory.create_batch(2)
|
|
153
|
-
HarvestSourceFactory(deleted=datetime.utcnow())
|
|
154
|
-
|
|
155
|
-
result = actions.paginate_sources(page_size=2, deleted=True)
|
|
156
|
-
assert isinstance(result, Paginable)
|
|
157
|
-
assert result.page == 1
|
|
158
|
-
assert result.page_size == 2
|
|
159
|
-
assert result.total == 3
|
|
160
|
-
assert len(result.objects) == 2
|
|
161
|
-
|
|
162
|
-
result = actions.paginate_sources(page=2, page_size=2, deleted=True)
|
|
163
|
-
assert isinstance(result, Paginable)
|
|
164
|
-
assert result.page == 2
|
|
165
|
-
assert result.page_size == 2
|
|
166
|
-
assert result.total == 3
|
|
167
|
-
assert len(result.objects) == 1
|
|
168
|
-
|
|
169
116
|
def test_create_source(self):
|
|
170
117
|
source_url = faker.url()
|
|
171
118
|
|
udata/harvest/tests/test_api.py
CHANGED
|
@@ -8,7 +8,7 @@ from pytest_mock import MockerFixture
|
|
|
8
8
|
from udata.core.organization.factories import OrganizationFactory
|
|
9
9
|
from udata.core.user.factories import AdminFactory, UserFactory
|
|
10
10
|
from udata.models import Member, PeriodicTask
|
|
11
|
-
from udata.tests.helpers import assert200, assert201, assert204, assert400, assert403
|
|
11
|
+
from udata.tests.helpers import assert200, assert201, assert204, assert400, assert403, assert404
|
|
12
12
|
from udata.tests.plugin import ApiClient
|
|
13
13
|
from udata.utils import faker
|
|
14
14
|
|
|
@@ -85,6 +85,38 @@ class HarvestAPITest(MockBackendsMixin):
|
|
|
85
85
|
|
|
86
86
|
assert len(response.json["data"]) == len(sources)
|
|
87
87
|
|
|
88
|
+
def test_list_sources_search(self, api):
|
|
89
|
+
HarvestSourceFactory.create_batch(3)
|
|
90
|
+
source = HarvestSourceFactory(name="Moissonneur GeoNetwork de la ville de Rennes")
|
|
91
|
+
|
|
92
|
+
url = url_for("api.harvest_sources", q="geonetwork rennes")
|
|
93
|
+
response = api.get(url)
|
|
94
|
+
assert200(response)
|
|
95
|
+
|
|
96
|
+
assert len(response.json["data"]) == 1
|
|
97
|
+
assert response.json["data"][0]["id"] == str(source.id)
|
|
98
|
+
|
|
99
|
+
def test_list_sources_paginate(self, api):
|
|
100
|
+
total = 25
|
|
101
|
+
page_size = 20
|
|
102
|
+
HarvestSourceFactory.create_batch(total)
|
|
103
|
+
|
|
104
|
+
url = url_for("api.harvest_sources", page=1, page_size=page_size)
|
|
105
|
+
response = api.get(url)
|
|
106
|
+
assert200(response)
|
|
107
|
+
assert len(response.json["data"]) == page_size
|
|
108
|
+
assert response.json["total"] == total
|
|
109
|
+
|
|
110
|
+
url = url_for("api.harvest_sources", page=2, page_size=page_size)
|
|
111
|
+
response = api.get(url)
|
|
112
|
+
assert200(response)
|
|
113
|
+
assert len(response.json["data"]) == total - page_size
|
|
114
|
+
assert response.json["total"] == total
|
|
115
|
+
|
|
116
|
+
url = url_for("api.harvest_sources", page=3, page_size=page_size)
|
|
117
|
+
response = api.get(url)
|
|
118
|
+
assert404(response)
|
|
119
|
+
|
|
88
120
|
def test_create_source_with_owner(self, api):
|
|
89
121
|
"""It should create and attach a new source to an owner"""
|
|
90
122
|
user = api.login()
|