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.
- udata/commands/tests/test_fixtures.py +6 -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/forms/fields.py +3 -3
- udata/forms/widgets.py +2 -2
- 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 +5 -16
- 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/mongo/taglist_field.py +3 -3
- udata/settings.py +3 -0
- udata/tags.py +5 -5
- 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 +27 -49
- 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 -4
- 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/utils.py +1 -1
- {udata-12.0.2.dev16.dist-info → udata-12.0.2.dev18.dist-info}/METADATA +1 -1
- {udata-12.0.2.dev16.dist-info → udata-12.0.2.dev18.dist-info}/RECORD +114 -116
- udata/tests/frontend/__init__.py +0 -23
- udata/tests/metrics/conftest.py +0 -15
- {udata-12.0.2.dev16.dist-info → udata-12.0.2.dev18.dist-info}/WHEEL +0 -0
- {udata-12.0.2.dev16.dist-info → udata-12.0.2.dev18.dist-info}/entry_points.txt +0 -0
- {udata-12.0.2.dev16.dist-info → udata-12.0.2.dev18.dist-info}/licenses/LICENSE +0 -0
- {udata-12.0.2.dev16.dist-info → udata-12.0.2.dev18.dist-info}/top_level.txt +0 -0
udata/tests/test_model.py
CHANGED
|
@@ -12,10 +12,9 @@ from udata.i18n import _
|
|
|
12
12
|
from udata.models import Dataset
|
|
13
13
|
from udata.mongo import build_test_config, db, validate_config
|
|
14
14
|
from udata.settings import Defaults
|
|
15
|
+
from udata.tests.api import PytestOnlyDBTestCase
|
|
15
16
|
from udata.tests.helpers import assert_equal_dates, assert_json_equal
|
|
16
17
|
|
|
17
|
-
pytestmark = [pytest.mark.usefixtures("clean_db")]
|
|
18
|
-
|
|
19
18
|
|
|
20
19
|
class UUIDTester(db.Document):
|
|
21
20
|
uuid = db.AutoUUIDField()
|
|
@@ -70,7 +69,7 @@ class PrivateURLTester(db.Document):
|
|
|
70
69
|
url = db.URLField(private=True)
|
|
71
70
|
|
|
72
71
|
|
|
73
|
-
class AutoUUIDFieldTest:
|
|
72
|
+
class AutoUUIDFieldTest(PytestOnlyDBTestCase):
|
|
74
73
|
def test_auto_populate(self):
|
|
75
74
|
"""AutoUUIDField should populate itself if not set"""
|
|
76
75
|
obj = UUIDTester()
|
|
@@ -103,7 +102,7 @@ class AutoUUIDFieldTest:
|
|
|
103
102
|
assert isinstance(obj.uuid, UUID)
|
|
104
103
|
|
|
105
104
|
|
|
106
|
-
class SlugFieldTest:
|
|
105
|
+
class SlugFieldTest(PytestOnlyDBTestCase):
|
|
107
106
|
def test_populate_on_pre_save_signal_is_registered(self):
|
|
108
107
|
"""populate_on_pre_save signal should be registered"""
|
|
109
108
|
# It isn't registered on startup
|
|
@@ -278,7 +277,7 @@ class SlugFieldTest:
|
|
|
278
277
|
assert field.slugify("à-€-ü") == "a-eur-u"
|
|
279
278
|
|
|
280
279
|
|
|
281
|
-
class DateFieldTest:
|
|
280
|
+
class DateFieldTest(PytestOnlyDBTestCase):
|
|
282
281
|
def test_none_if_empty_and_not_required(self):
|
|
283
282
|
obj = DateTester()
|
|
284
283
|
assert obj.a_date is None
|
|
@@ -308,7 +307,7 @@ class DateFieldTest:
|
|
|
308
307
|
obj.save()
|
|
309
308
|
|
|
310
309
|
|
|
311
|
-
class DateRangeFieldTest:
|
|
310
|
+
class DateRangeFieldTest(PytestOnlyDBTestCase):
|
|
312
311
|
def test_none_if_empty_and_not_required(self):
|
|
313
312
|
obj = DateRangeTester()
|
|
314
313
|
assert obj.temporal is None
|
|
@@ -390,7 +389,7 @@ class DateRangeFieldTest:
|
|
|
390
389
|
assert obj.temporal.end == end
|
|
391
390
|
|
|
392
391
|
|
|
393
|
-
class URLFieldTest:
|
|
392
|
+
class URLFieldTest(PytestOnlyDBTestCase):
|
|
394
393
|
def test_none_if_empty_and_not_required(self):
|
|
395
394
|
obj = URLTester()
|
|
396
395
|
assert obj.url is None
|
|
@@ -422,7 +421,7 @@ class URLFieldTest:
|
|
|
422
421
|
URLTester(url=url).save()
|
|
423
422
|
|
|
424
423
|
|
|
425
|
-
class DatetimedTest:
|
|
424
|
+
class DatetimedTest(PytestOnlyDBTestCase):
|
|
426
425
|
def test_class(self):
|
|
427
426
|
assert isinstance(DatetimedTester.created_at, db.DateTimeField)
|
|
428
427
|
assert isinstance(DatetimedTester.last_modified, db.DateTimeField)
|
|
@@ -483,7 +482,7 @@ class DatetimedTest:
|
|
|
483
482
|
assert_equal_dates(datetimed.last_modified, manual)
|
|
484
483
|
|
|
485
484
|
|
|
486
|
-
class ExtrasFieldTest:
|
|
485
|
+
class ExtrasFieldTest(PytestOnlyDBTestCase):
|
|
487
486
|
def test_default_validate_primitive_type(self):
|
|
488
487
|
class Tester(db.Document):
|
|
489
488
|
extras = db.ExtrasField()
|
|
@@ -608,7 +607,7 @@ class ExtrasFieldTest:
|
|
|
608
607
|
)
|
|
609
608
|
|
|
610
609
|
|
|
611
|
-
class ModelResolutionTest:
|
|
610
|
+
class ModelResolutionTest(PytestOnlyDBTestCase):
|
|
612
611
|
def test_resolve_exact_match(self):
|
|
613
612
|
assert db.resolve_model("Dataset") == Dataset
|
|
614
613
|
|
|
@@ -632,7 +631,7 @@ class ModelResolutionTest:
|
|
|
632
631
|
db.resolve_model({"field": "value"})
|
|
633
632
|
|
|
634
633
|
|
|
635
|
-
class MongoConfigTest:
|
|
634
|
+
class MongoConfigTest(PytestOnlyDBTestCase):
|
|
636
635
|
def test_validate_default_value(self):
|
|
637
636
|
validate_config({"MONGODB_HOST": Defaults.MONGODB_HOST})
|
|
638
637
|
|
|
@@ -6,8 +6,7 @@ from flask import url_for
|
|
|
6
6
|
from udata.core.user.factories import UserFactory
|
|
7
7
|
from udata.features.notifications import actions
|
|
8
8
|
|
|
9
|
-
from . import
|
|
10
|
-
from .api import APITestCase
|
|
9
|
+
from .api import APITestCase, DBTestCase
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
class NotificationsMixin(object):
|
|
@@ -15,7 +14,7 @@ class NotificationsMixin(object):
|
|
|
15
14
|
actions._providers = {}
|
|
16
15
|
|
|
17
16
|
|
|
18
|
-
class NotificationsActionsTest(NotificationsMixin,
|
|
17
|
+
class NotificationsActionsTest(NotificationsMixin, DBTestCase):
|
|
19
18
|
def test_registered_provider_is_listed(self):
|
|
20
19
|
def fake_provider(user):
|
|
21
20
|
return []
|
udata/tests/test_owned.py
CHANGED
|
@@ -7,7 +7,7 @@ from udata.core.user.factories import AdminFactory, UserFactory
|
|
|
7
7
|
from udata.core.user.models import User
|
|
8
8
|
from udata.models import Member
|
|
9
9
|
from udata.mongo import db
|
|
10
|
-
from udata.tests import
|
|
10
|
+
from udata.tests.api import DBTestCase
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class CustomQuerySet(owned.OwnedQuerySet):
|
|
@@ -41,7 +41,7 @@ def compute_some_metrics(document, **kwargs):
|
|
|
41
41
|
document.save(signal_kwargs={"ignores": ["post_save"]})
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
class
|
|
44
|
+
class TestOwned(DBTestCase):
|
|
45
45
|
def test_fields(self):
|
|
46
46
|
self.assertIsInstance(Owned.owner, db.ReferenceField)
|
|
47
47
|
self.assertEqual(Owned.owner.document_type_obj, User)
|
|
@@ -136,7 +136,7 @@ class TestOwnedMixin(DBTestMixin, TestCase):
|
|
|
136
136
|
assert owned.organization is None
|
|
137
137
|
|
|
138
138
|
|
|
139
|
-
class OwnedQuerysetTest(
|
|
139
|
+
class OwnedQuerysetTest(DBTestCase):
|
|
140
140
|
def test_queryset_type(self):
|
|
141
141
|
self.assertIsInstance(Owned.objects, owned.OwnedQuerySet)
|
|
142
142
|
|
udata/tests/test_routing.py
CHANGED
|
@@ -9,10 +9,12 @@ from udata.core.spatial.factories import GeoZoneFactory
|
|
|
9
9
|
from udata.core.spatial.models import GeoZone
|
|
10
10
|
from udata.mongo import db
|
|
11
11
|
from udata.mongo.slug_fields import SlugFollow
|
|
12
|
+
from udata.tests import PytestOnlyTestCase
|
|
13
|
+
from udata.tests.api import PytestOnlyDBTestCase
|
|
12
14
|
from udata.tests.helpers import assert200, assert404, assert_redirects
|
|
13
15
|
|
|
14
16
|
|
|
15
|
-
class UUIDConverterTest:
|
|
17
|
+
class UUIDConverterTest(PytestOnlyTestCase):
|
|
16
18
|
@pytest.fixture(autouse=True)
|
|
17
19
|
def setup(self, app):
|
|
18
20
|
@app.route("/uuid/<uuid:uuid>")
|
|
@@ -67,8 +69,7 @@ class RedirectTesterConverter(routing.ModelConverter):
|
|
|
67
69
|
model = RedirectTester
|
|
68
70
|
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
class ModelConverterMixin:
|
|
72
|
+
class ModelConverterMixin(PytestOnlyDBTestCase):
|
|
72
73
|
@pytest.fixture(autouse=True)
|
|
73
74
|
def setup(self, app):
|
|
74
75
|
app.url_map.converters["tester"] = self.converter
|
|
@@ -295,9 +296,8 @@ class SlugAsSLugFieldWithFollowTest(AsSlugMixin):
|
|
|
295
296
|
assert SlugFollow.objects.count() == 0
|
|
296
297
|
|
|
297
298
|
|
|
298
|
-
@pytest.mark.usefixtures("clean_db")
|
|
299
299
|
@pytest.mark.options(TERRITORY_DEFAULT_PREFIX="fr") # Not implemented
|
|
300
|
-
class TerritoryConverterTest:
|
|
300
|
+
class TerritoryConverterTest(PytestOnlyDBTestCase):
|
|
301
301
|
@pytest.fixture(autouse=True)
|
|
302
302
|
def setup(self, app):
|
|
303
303
|
@app.route("/territory/<territory:territory>")
|
udata/tests/test_storages.py
CHANGED
|
@@ -12,12 +12,14 @@ from udata.core import storages
|
|
|
12
12
|
from udata.core.storages import utils
|
|
13
13
|
from udata.core.storages.api import META, chunk_filename
|
|
14
14
|
from udata.core.storages.tasks import purge_chunks
|
|
15
|
+
from udata.tests import PytestOnlyTestCase
|
|
16
|
+
from udata.tests.api import PytestOnlyDBTestCase
|
|
15
17
|
from udata.utils import faker
|
|
16
18
|
|
|
17
19
|
from .helpers import assert200, assert400
|
|
18
20
|
|
|
19
21
|
|
|
20
|
-
class StorageUtilsTest:
|
|
22
|
+
class StorageUtilsTest(PytestOnlyTestCase):
|
|
21
23
|
"""
|
|
22
24
|
Perform all tests on a file of size 2 * CHUNCK_SIZE = 2 * (2 ** 16).
|
|
23
25
|
Expected values are precomputed with shell `md5sum`, `sha1sum`...
|
|
@@ -88,8 +90,7 @@ class StorageUtilsTest:
|
|
|
88
90
|
assert utils.normalize("éàü@€.txt") == "eau-eur.txt"
|
|
89
91
|
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
class ConfigurableAllowedExtensionsTest:
|
|
93
|
+
class ConfigurableAllowedExtensionsTest(PytestOnlyTestCase):
|
|
93
94
|
def test_has_default(self):
|
|
94
95
|
assert "csv" in storages.CONFIGURABLE_AUTHORIZED_TYPES
|
|
95
96
|
assert "xml" in storages.CONFIGURABLE_AUTHORIZED_TYPES
|
|
@@ -107,7 +108,7 @@ class ConfigurableAllowedExtensionsTest:
|
|
|
107
108
|
|
|
108
109
|
|
|
109
110
|
@pytest.mark.usefixtures("instance_path")
|
|
110
|
-
class StorageUploadViewTest:
|
|
111
|
+
class StorageUploadViewTest(PytestOnlyDBTestCase):
|
|
111
112
|
def test_standard_upload(self, client):
|
|
112
113
|
client.login()
|
|
113
114
|
response = client.post(
|
|
@@ -221,7 +222,7 @@ class StorageUploadViewTest:
|
|
|
221
222
|
|
|
222
223
|
|
|
223
224
|
@pytest.mark.usefixtures("instance_path")
|
|
224
|
-
class ChunksRetentionTest:
|
|
225
|
+
class ChunksRetentionTest(PytestOnlyTestCase):
|
|
225
226
|
def create_chunks(self, uuid, nb=3, last=None):
|
|
226
227
|
for i in range(nb):
|
|
227
228
|
storages.chunks.write(chunk_filename(uuid, i), faker.word())
|
udata/tests/test_tags.py
CHANGED
|
@@ -10,14 +10,12 @@ from udata.core.reuse.factories import ReuseFactory
|
|
|
10
10
|
from udata.core.tags.models import Tag
|
|
11
11
|
from udata.core.tags.tasks import count_tags
|
|
12
12
|
from udata.tags import normalize, slug, tags_list
|
|
13
|
+
from udata.tests import PytestOnlyTestCase
|
|
13
14
|
from udata.tests.helpers import assert200
|
|
14
15
|
|
|
15
16
|
log = logging.getLogger(__name__)
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
MAX_TAG_LENGTH = 32
|
|
19
|
-
|
|
20
|
-
|
|
21
19
|
class TagsTests:
|
|
22
20
|
def test_csv(self, client):
|
|
23
21
|
Tag.objects.create(name="datasets-only", counts={"datasets": 15})
|
|
@@ -64,7 +62,7 @@ class TagsTests:
|
|
|
64
62
|
assert tag.counts["reuses"] == count
|
|
65
63
|
|
|
66
64
|
|
|
67
|
-
class TagsUtilsTest:
|
|
65
|
+
class TagsUtilsTest(PytestOnlyTestCase):
|
|
68
66
|
def test_tags_list(self):
|
|
69
67
|
assert tags_list("") == []
|
|
70
68
|
assert tags_list("a") == ["a"]
|
udata/tests/test_topics.py
CHANGED
|
@@ -17,6 +17,7 @@ from udata.core.topic.factories import (
|
|
|
17
17
|
)
|
|
18
18
|
from udata.core.topic.models import Topic, TopicElement
|
|
19
19
|
from udata.search import reindex
|
|
20
|
+
from udata.tests.api import PytestOnlyDBTestCase
|
|
20
21
|
from udata.tests.helpers import assert_emit
|
|
21
22
|
|
|
22
23
|
|
|
@@ -31,10 +32,7 @@ def job_reindex_undelayed(mocker):
|
|
|
31
32
|
return mocker.patch.object(reindex, "delay", side_effect=reindex)
|
|
32
33
|
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class TopicModelTest:
|
|
35
|
+
class TopicModelTest(PytestOnlyDBTestCase):
|
|
38
36
|
def test_pre_save(self, job_reindex):
|
|
39
37
|
topic = TopicFactory()
|
|
40
38
|
|
udata/tests/test_transfer.py
CHANGED
|
@@ -14,12 +14,11 @@ from udata.features.transfer.actions import accept_transfer, request_transfer
|
|
|
14
14
|
from udata.features.transfer.factories import TransferFactory
|
|
15
15
|
from udata.features.transfer.notifications import transfer_request_notifications
|
|
16
16
|
from udata.models import Member
|
|
17
|
+
from udata.tests.api import PytestOnlyDBTestCase
|
|
17
18
|
from udata.utils import faker
|
|
18
19
|
|
|
19
|
-
pytestmark = pytest.mark.usefixtures("clean_db")
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
class TransferStartTest:
|
|
21
|
+
class TransferStartTest(PytestOnlyDBTestCase):
|
|
23
22
|
def assert_transfer_started(self, subject, owner, recipient, comment):
|
|
24
23
|
transfer = request_transfer(subject, recipient, comment)
|
|
25
24
|
|
|
@@ -102,7 +101,7 @@ class TransferStartTest:
|
|
|
102
101
|
self.assert_transfer_started(dataset, org, org, comment)
|
|
103
102
|
|
|
104
103
|
|
|
105
|
-
class TransferAcceptTest:
|
|
104
|
+
class TransferAcceptTest(PytestOnlyDBTestCase):
|
|
106
105
|
def test_recipient_user_can_accept_transfer(self):
|
|
107
106
|
owner = UserFactory()
|
|
108
107
|
recipient = UserFactory()
|
|
@@ -175,7 +174,7 @@ class TransferAcceptTest:
|
|
|
175
174
|
accept_transfer(transfer)
|
|
176
175
|
|
|
177
176
|
|
|
178
|
-
class TransferNotificationsTest:
|
|
177
|
+
class TransferNotificationsTest(PytestOnlyDBTestCase):
|
|
179
178
|
def test_pending_transfer_request_for_user(self):
|
|
180
179
|
user = UserFactory()
|
|
181
180
|
datasets = DatasetFactory.create_batch(2, owner=user)
|
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
|
|
3
1
|
from udata.core.dataservices.tasks import purge_dataservices
|
|
4
2
|
from udata.core.dataset.tasks import purge_datasets
|
|
5
3
|
from udata.core.reuse.tasks import purge_reuses
|
|
6
4
|
from udata.core.topic.factories import TopicWithElementsFactory
|
|
7
5
|
from udata.core.topic.tasks import purge_topics_elements
|
|
8
|
-
|
|
9
|
-
pytestmark = pytest.mark.usefixtures("clean_db")
|
|
6
|
+
from udata.tests.api import PytestOnlyDBTestCase
|
|
10
7
|
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
element
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
element.element
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
9
|
+
class TopicTasksTest(PytestOnlyDBTestCase):
|
|
10
|
+
def test_purge_topics_elements(self):
|
|
11
|
+
topic = TopicWithElementsFactory()
|
|
12
|
+
assert len(topic.elements) > 0
|
|
13
|
+
for element in topic.elements:
|
|
14
|
+
element.title = None
|
|
15
|
+
element.save()
|
|
16
|
+
# Handle different deletion field names across models
|
|
17
|
+
if hasattr(element.element, "deleted_at"):
|
|
18
|
+
element.element.deleted_at = "2023-01-01"
|
|
19
|
+
else:
|
|
20
|
+
element.element.deleted = "2023-01-01"
|
|
21
|
+
element.element.save()
|
|
22
|
+
topic.save()
|
|
23
|
+
# remove the dataset elements marked as deleted
|
|
24
|
+
purge_datasets()
|
|
25
|
+
# remove the reuse elements marked as deleted
|
|
26
|
+
purge_reuses()
|
|
27
|
+
# remove the dataservices elements marked as deleted
|
|
28
|
+
purge_dataservices()
|
|
29
|
+
# remove the topic elements that have neither title nor element
|
|
30
|
+
purge_topics_elements()
|
|
31
|
+
topic.reload()
|
|
32
|
+
assert len(topic.elements) == 0
|
|
@@ -3,19 +3,13 @@ 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.user.factories import UserFactory
|
|
8
7
|
from udata.core.user.rdf import user_to_rdf
|
|
9
|
-
from udata.tests import
|
|
8
|
+
from udata.tests.api import APITestCase
|
|
10
9
|
from udata.utils import faker
|
|
11
10
|
|
|
12
11
|
|
|
13
|
-
class UserToRdfTest(
|
|
14
|
-
def create_app(self):
|
|
15
|
-
app = super(UserToRdfTest, self).create_app()
|
|
16
|
-
api.init_app(app)
|
|
17
|
-
return app
|
|
18
|
-
|
|
12
|
+
class UserToRdfTest(APITestCase):
|
|
19
13
|
def test_minimal(self):
|
|
20
14
|
user = UserFactory.build() # Does not have an URL
|
|
21
15
|
u = user_to_rdf(user)
|
|
@@ -5,6 +5,7 @@ import pytest
|
|
|
5
5
|
from udata.core.jobs.commands import job_label
|
|
6
6
|
from udata.core.jobs.models import PeriodicTask
|
|
7
7
|
from udata.tasks import job
|
|
8
|
+
from udata.tests.api import PytestOnlyDBTestCase
|
|
8
9
|
|
|
9
10
|
log = logging.getLogger(__name__)
|
|
10
11
|
|
|
@@ -26,8 +27,7 @@ def job_run(mocker):
|
|
|
26
27
|
return mocker.patch.object(do_nothing, "run")
|
|
27
28
|
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
class JobsCommandsTest:
|
|
30
|
+
class JobsCommandsTest(PytestOnlyDBTestCase):
|
|
31
31
|
def test_list_jobs(self, cli):
|
|
32
32
|
result = cli("job list")
|
|
33
33
|
assert JOB_NAME in result.output
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import pytest
|
|
2
2
|
|
|
3
3
|
from udata.tasks import celery, job, task
|
|
4
|
+
from udata.tests import PytestOnlyTestCase
|
|
4
5
|
from udata.utils import unique_string
|
|
5
6
|
|
|
6
7
|
TASKS = [
|
|
@@ -33,37 +34,36 @@ def fake_task(*args, **kwargs):
|
|
|
33
34
|
pass
|
|
34
35
|
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def
|
|
39
|
-
|
|
37
|
+
class TasksRoutingTest(PytestOnlyTestCase):
|
|
38
|
+
@pytest.fixture
|
|
39
|
+
def route_to(self, app, mocker):
|
|
40
|
+
def assertion(func, args, kwargs, queue, key=None):
|
|
41
|
+
__tracebackhide__ = True
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
decorator = func(*args, **kwargs) if args or kwargs else func
|
|
44
|
+
router = celery.amqp.router
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
# Celery instanciate only one task by name so we need unique names
|
|
47
|
+
suffix = unique_string().replace("-", "_")
|
|
48
|
+
fake_task.__name__ = "task_{0}".format(suffix)
|
|
49
|
+
t = decorator(fake_task)
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
options = t._get_exec_options()
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
route = router.route(options, t.name, task_type=t)
|
|
54
|
+
if queue:
|
|
55
|
+
assert route["queue"].name == queue, "queue mismatch"
|
|
56
|
+
if key:
|
|
57
|
+
key = key.format(name=t.name)
|
|
58
|
+
assert route["routing_key"] == key, "routing_key mismatch"
|
|
59
|
+
return route
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
return assertion
|
|
60
62
|
|
|
63
|
+
@pytest.mark.parametrize("kwargs,queue,key", TASKS, ids=idify(TASKS))
|
|
64
|
+
def test_tasks_routing(self, route_to, kwargs, queue, key):
|
|
65
|
+
route_to(task, [], kwargs, queue, key)
|
|
61
66
|
|
|
62
|
-
@pytest.mark.parametrize("kwargs,queue,key",
|
|
63
|
-
def
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
@pytest.mark.parametrize("kwargs,queue,key", JOBS, ids=idify(JOBS))
|
|
68
|
-
def test_job_routing(route_to, kwargs, queue, key):
|
|
69
|
-
route_to(job, [unique_string()], kwargs, queue, key)
|
|
67
|
+
@pytest.mark.parametrize("kwargs,queue,key", JOBS, ids=idify(JOBS))
|
|
68
|
+
def test_job_routing(self, route_to, kwargs, queue, key):
|
|
69
|
+
route_to(job, [unique_string()], kwargs, queue, key)
|
udata/utils.py
CHANGED