Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-model
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Dandrimont
swh-model
Commits
fca36585
Commit
fca36585
authored
4 years ago
by
David Douard
Browse files
Options
Downloads
Patches
Plain Diff
Fix MetadataAuthority.from_dict()
was modifying the dict given as argument.
parent
2185f930
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/model/model.py
+4
-1
4 additions, 1 deletion
swh/model/model.py
swh/model/tests/test_model.py
+12
-0
12 additions, 0 deletions
swh/model/tests/test_model.py
with
16 additions
and
1 deletion
swh/model/model.py
+
4
−
1
View file @
fca36585
...
...
@@ -848,7 +848,10 @@ class MetadataAuthority(BaseModel):
@classmethod
def
from_dict
(
cls
,
d
):
d
[
"
type
"
]
=
MetadataAuthorityType
(
d
[
"
type
"
])
d
=
{
**
d
,
"
type
"
:
MetadataAuthorityType
(
d
[
"
type
"
]),
}
return
super
().
from_dict
(
d
)
def
unique_key
(
self
)
->
KeyType
:
...
...
This diff is collapsed.
Click to expand it.
swh/model/tests/test_model.py
+
12
−
0
View file @
fca36585
...
...
@@ -45,6 +45,7 @@ from swh.model.model import (
Timestamp
,
TimestampWithTimezone
,
)
from
swh.model.tests.swh_model_data
import
TEST_OBJECTS
from
swh.model.tests.test_identifiers
import
(
content_example
,
directory_example
,
...
...
@@ -78,6 +79,17 @@ def test_todict_inverse_fromdict(objtype_and_obj):
assert
obj_as_dict
==
type
(
obj
).
from_dict
(
obj_as_dict
).
to_dict
()
@pytest.mark.parametrize
(
"
object_type, objects
"
,
TEST_OBJECTS
.
items
())
def
test_swh_model_todict_fromdict
(
object_type
,
objects
):
"""
checks model objects in swh_model_data are in correct shape
"""
assert
objects
for
obj
in
objects
:
# Check the composition of from_dict and to_dict is the identity
obj_as_dict
=
obj
.
to_dict
()
assert
obj
==
type
(
obj
).
from_dict
(
obj_as_dict
)
assert
obj_as_dict
==
type
(
obj
).
from_dict
(
obj_as_dict
).
to_dict
()
def
test_unique_key
():
url
=
"
http://example.org/
"
date
=
datetime
.
datetime
.
now
(
tz
=
datetime
.
timezone
.
utc
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment