udata 9.1.4.dev31182__py2.py3-none-any.whl → 9.1.4.dev31191__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/commands/fixtures.py +60 -42
- udata/commands/tests/test_fixtures.py +27 -8
- udata/static/chunks/{11.c4fec2b97bfd90327442.js → 11.18f1cc16362b76373c40.js} +3 -3
- udata/static/chunks/{11.c4fec2b97bfd90327442.js.map → 11.18f1cc16362b76373c40.js.map} +1 -1
- udata/static/chunks/{19.4554a08228342423184e.js → 19.2061dca8438f415029a3.js} +3 -3
- udata/static/chunks/{19.4554a08228342423184e.js.map → 19.2061dca8438f415029a3.js.map} +1 -1
- udata/static/chunks/{5.dbeb9a6f04a746965a39.js → 5.d17ff266ecc1ad0331fb.js} +3 -3
- udata/static/chunks/{5.dbeb9a6f04a746965a39.js.map → 5.d17ff266ecc1ad0331fb.js.map} +1 -1
- udata/static/chunks/{6.a6743fa06e1e94ef8dc0.js → 6.0db5d3ff22944de7edd5.js} +3 -3
- udata/static/chunks/{6.a6743fa06e1e94ef8dc0.js.map → 6.0db5d3ff22944de7edd5.js.map} +1 -1
- udata/static/chunks/{8.0b473c6a35cc483ec333.js → 8.292c6a157d71f0b21b6f.js} +2 -2
- udata/static/chunks/{8.0b473c6a35cc483ec333.js.map → 8.292c6a157d71f0b21b6f.js.map} +1 -1
- udata/static/common.js +1 -1
- udata/static/common.js.map +1 -1
- {udata-9.1.4.dev31182.dist-info → udata-9.1.4.dev31191.dist-info}/METADATA +2 -1
- {udata-9.1.4.dev31182.dist-info → udata-9.1.4.dev31191.dist-info}/RECORD +20 -20
- {udata-9.1.4.dev31182.dist-info → udata-9.1.4.dev31191.dist-info}/LICENSE +0 -0
- {udata-9.1.4.dev31182.dist-info → udata-9.1.4.dev31191.dist-info}/WHEEL +0 -0
- {udata-9.1.4.dev31182.dist-info → udata-9.1.4.dev31191.dist-info}/entry_points.txt +0 -0
- {udata-9.1.4.dev31182.dist-info → udata-9.1.4.dev31191.dist-info}/top_level.txt +0 -0
udata/commands/fixtures.py
CHANGED
|
@@ -26,6 +26,7 @@ from udata.core.organization.factories import OrganizationFactory
|
|
|
26
26
|
from udata.core.organization.models import Member, Organization
|
|
27
27
|
from udata.core.reuse.factories import ReuseFactory
|
|
28
28
|
from udata.core.user.factories import UserFactory
|
|
29
|
+
from udata.core.user.models import User
|
|
29
30
|
|
|
30
31
|
log = logging.getLogger(__name__)
|
|
31
32
|
|
|
@@ -55,22 +56,21 @@ UNWANTED_KEYS: dict[str, list[str]] = {
|
|
|
55
56
|
"quality",
|
|
56
57
|
],
|
|
57
58
|
"resource": ["latest", "preview_url", "last_modified"],
|
|
58
|
-
"organization": ["
|
|
59
|
-
"reuse": ["datasets", "image_thumbnail", "page", "uri", "
|
|
59
|
+
"organization": ["class", "page", "uri", "logo_thumbnail"],
|
|
60
|
+
"reuse": ["datasets", "image_thumbnail", "page", "uri", "owner"],
|
|
60
61
|
"community": [
|
|
61
62
|
"dataset",
|
|
62
|
-
"organization",
|
|
63
63
|
"owner",
|
|
64
64
|
"latest",
|
|
65
65
|
"last_modified",
|
|
66
66
|
"preview_url",
|
|
67
67
|
],
|
|
68
|
-
"discussion": ["subject", "
|
|
69
|
-
"
|
|
68
|
+
"discussion": ["subject", "url", "class"],
|
|
69
|
+
"user": ["uri", "page", "class", "avatar_thumbnail", "email"],
|
|
70
|
+
"posted_by": ["uri", "page", "class", "avatar_thumbnail", "email"],
|
|
70
71
|
"dataservice": [
|
|
71
72
|
"datasets",
|
|
72
73
|
"license",
|
|
73
|
-
"organization",
|
|
74
74
|
"owner",
|
|
75
75
|
"self_api_url",
|
|
76
76
|
"self_web_url",
|
|
@@ -80,6 +80,8 @@ UNWANTED_KEYS: dict[str, list[str]] = {
|
|
|
80
80
|
|
|
81
81
|
def remove_unwanted_keys(obj: dict, filter_type: str) -> dict:
|
|
82
82
|
"""Remove UNWANTED_KEYS from a dict."""
|
|
83
|
+
if filter_type not in UNWANTED_KEYS:
|
|
84
|
+
return obj
|
|
83
85
|
for unwanted_key in UNWANTED_KEYS[filter_type]:
|
|
84
86
|
if unwanted_key in obj:
|
|
85
87
|
del obj[unwanted_key]
|
|
@@ -150,6 +152,29 @@ def generate_fixtures_file(data_source: str, results_filename: str) -> None:
|
|
|
150
152
|
print(f"Fixtures saved to file {results_filename}")
|
|
151
153
|
|
|
152
154
|
|
|
155
|
+
def get_or_create(data, key, model, factory):
|
|
156
|
+
"""Try getting the object. If it doesn't exist yet, create it with the provided factory."""
|
|
157
|
+
if key not in data or data[key] is None:
|
|
158
|
+
return
|
|
159
|
+
data[key] = remove_unwanted_keys(data[key], key)
|
|
160
|
+
obj = model.objects(id=data[key]["id"]).first()
|
|
161
|
+
if not obj:
|
|
162
|
+
obj = factory(**data[key])
|
|
163
|
+
return obj
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def get_or_create_organization(data):
|
|
167
|
+
return get_or_create(data, "organization", Organization, OrganizationFactory)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def get_or_create_owner(data):
|
|
171
|
+
return get_or_create(data, "owner", User, UserFactory)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def get_or_create_user(data):
|
|
175
|
+
return get_or_create(data, "user", User, UserFactory)
|
|
176
|
+
|
|
177
|
+
|
|
153
178
|
@cli.command()
|
|
154
179
|
@click.argument("source", default=DEFAULT_FIXTURE_FILE)
|
|
155
180
|
def import_fixtures(source):
|
|
@@ -165,52 +190,45 @@ def import_fixtures(source):
|
|
|
165
190
|
user = UserFactory()
|
|
166
191
|
dataset = fixture["dataset"]
|
|
167
192
|
dataset = remove_unwanted_keys(dataset, "dataset")
|
|
168
|
-
if
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
193
|
+
if fixture["organization"]:
|
|
194
|
+
organization = fixture["organization"]
|
|
195
|
+
organization["members"] = [
|
|
196
|
+
Member(user=get_or_create_user(member), role=member["role"])
|
|
197
|
+
for member in organization["members"]
|
|
198
|
+
]
|
|
199
|
+
fixture["organization"] = organization
|
|
200
|
+
org = get_or_create_organization(fixture)
|
|
176
201
|
dataset = DatasetFactory(**dataset, organization=org)
|
|
202
|
+
else:
|
|
203
|
+
dataset = DatasetFactory(**dataset, owner=user)
|
|
177
204
|
for resource in fixture["resources"]:
|
|
178
205
|
resource = remove_unwanted_keys(resource, "resource")
|
|
179
206
|
res = ResourceFactory(**resource)
|
|
180
207
|
dataset.add_resource(res)
|
|
181
208
|
for reuse in fixture["reuses"]:
|
|
182
209
|
reuse = remove_unwanted_keys(reuse, "reuse")
|
|
183
|
-
|
|
210
|
+
reuse["owner"] = get_or_create_owner(reuse)
|
|
211
|
+
reuse["organization"] = get_or_create_organization(reuse)
|
|
212
|
+
ReuseFactory(**reuse, datasets=[dataset])
|
|
184
213
|
for community in fixture["community_resources"]:
|
|
185
214
|
community = remove_unwanted_keys(community, "community")
|
|
186
|
-
|
|
215
|
+
community["owner"] = get_or_create_owner(community)
|
|
216
|
+
community["organization"] = get_or_create_organization(community)
|
|
217
|
+
CommunityResourceFactory(**community, dataset=dataset)
|
|
187
218
|
for discussion in fixture["discussions"]:
|
|
188
219
|
discussion = remove_unwanted_keys(discussion, "discussion")
|
|
189
|
-
|
|
190
|
-
for message in
|
|
191
|
-
message =
|
|
192
|
-
|
|
193
|
-
**discussion
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
MessageDiscussionFactory(**message, posted_by=user) for message in messages
|
|
198
|
-
],
|
|
199
|
-
)
|
|
220
|
+
discussion["closed_by"] = get_or_create(discussion, "closed_by", User, UserFactory)
|
|
221
|
+
for message in discussion["discussion"]:
|
|
222
|
+
message["posted_by"] = get_or_create(message, "posted_by", User, UserFactory)
|
|
223
|
+
discussion["discussion"] = [
|
|
224
|
+
MessageDiscussionFactory(**message) for message in discussion["discussion"]
|
|
225
|
+
]
|
|
226
|
+
discussion["user"] = get_or_create_user(discussion)
|
|
227
|
+
DiscussionFactory(**discussion, subject=dataset)
|
|
200
228
|
for dataservice in fixture["dataservices"]:
|
|
201
229
|
dataservice = remove_unwanted_keys(dataservice, "dataservice")
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
).first()
|
|
208
|
-
if not contact_point:
|
|
209
|
-
contact_point = ContactPointFactory(**dataservice["contact_point"])
|
|
210
|
-
dataservice.pop("contact_point")
|
|
211
|
-
DataserviceFactory(
|
|
212
|
-
**dataservice,
|
|
213
|
-
datasets=[dataset],
|
|
214
|
-
organization=org,
|
|
215
|
-
contact_point=contact_point,
|
|
216
|
-
)
|
|
230
|
+
dataservice["contact_point"] = get_or_create(
|
|
231
|
+
dataservice, "contact_point", ContactPoint, ContactPointFactory
|
|
232
|
+
)
|
|
233
|
+
dataservice["organization"] = get_or_create_organization(dataservice)
|
|
234
|
+
DataserviceFactory(**dataservice, datasets=[dataset])
|
|
@@ -27,21 +27,28 @@ class FixturesTest:
|
|
|
27
27
|
"""Test generating fixtures from the current env, then importing them back."""
|
|
28
28
|
assert models.Dataset.objects.count() == 0 # Start with a clean slate.
|
|
29
29
|
user = UserFactory()
|
|
30
|
-
|
|
30
|
+
admin = UserFactory()
|
|
31
|
+
org = OrganizationFactory(
|
|
32
|
+
members=[Member(user=user, role="editor"), Member(user=admin, role="admin")]
|
|
33
|
+
)
|
|
31
34
|
# Set the same slug we're 'exporting' from the FIXTURE_DATASET_SLUG config, see the
|
|
32
35
|
# @pytest.mark.options above.
|
|
33
|
-
dataset = DatasetFactory(
|
|
34
|
-
res = ResourceFactory(
|
|
36
|
+
dataset = DatasetFactory(slug="some-test-dataset-slug", organization=org)
|
|
37
|
+
res = ResourceFactory()
|
|
35
38
|
dataset.add_resource(res)
|
|
36
|
-
ReuseFactory(
|
|
37
|
-
CommunityResourceFactory(
|
|
39
|
+
ReuseFactory(datasets=[dataset], owner=user)
|
|
40
|
+
CommunityResourceFactory(dataset=dataset, owner=user)
|
|
38
41
|
DiscussionFactory(
|
|
39
42
|
**{},
|
|
40
43
|
subject=dataset,
|
|
41
44
|
user=user,
|
|
42
|
-
discussion=[
|
|
45
|
+
discussion=[
|
|
46
|
+
MessageDiscussionFactory(posted_by=user),
|
|
47
|
+
MessageDiscussionFactory(posted_by=admin),
|
|
48
|
+
],
|
|
49
|
+
closed_by=admin,
|
|
43
50
|
)
|
|
44
|
-
DataserviceFactory(
|
|
51
|
+
DataserviceFactory(datasets=[dataset], organization=org)
|
|
45
52
|
|
|
46
53
|
with NamedTemporaryFile(mode="w+", delete=True) as fixtures_fd:
|
|
47
54
|
# Get the fixtures from the local instance.
|
|
@@ -69,13 +76,25 @@ class FixturesTest:
|
|
|
69
76
|
# Then load them in the database to make sure they're correct.
|
|
70
77
|
result = cli("import-fixtures", fixtures_fd.name)
|
|
71
78
|
assert models.Organization.objects(slug=org.slug).count() > 0
|
|
79
|
+
result_org = models.Organization.objects.get(slug=org.slug)
|
|
80
|
+
assert result_org.members[0].user.id == user.id
|
|
81
|
+
assert result_org.members[0].role == "editor"
|
|
82
|
+
assert result_org.members[1].user.id == admin.id
|
|
83
|
+
assert result_org.members[1].role == "admin"
|
|
72
84
|
assert models.Dataset.objects.count() > 0
|
|
73
85
|
assert models.Discussion.objects.count() > 0
|
|
86
|
+
result_discussion = models.Discussion.objects.first()
|
|
87
|
+
assert result_discussion.user.id == user.id
|
|
88
|
+
assert result_discussion.closed_by.id == admin.id
|
|
89
|
+
assert len(result_discussion.discussion) == 2
|
|
90
|
+
assert result_discussion.discussion[0].posted_by.id == user.id
|
|
91
|
+
assert result_discussion.discussion[1].posted_by.id == admin.id
|
|
74
92
|
assert models.CommunityResource.objects.count() > 0
|
|
75
93
|
assert models.User.objects.count() > 0
|
|
76
94
|
assert models.Dataservice.objects.count() > 0
|
|
77
95
|
# Make sure we also import the dataservice organization
|
|
78
|
-
|
|
96
|
+
result_dataservice = models.Dataservice.objects.first()
|
|
97
|
+
assert result_dataservice.organization == org
|
|
79
98
|
|
|
80
99
|
def test_import_fixtures_from_default_file(self, cli):
|
|
81
100
|
"""Test importing fixtures from udata.commands.fixture.DEFAULT_FIXTURE_FILE."""
|