Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
b9ee004d
Verified
Commit
b9ee004d
authored
4 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
BUG: Entity.role behavior
parent
ea5763be
No related branches found
No related tags found
2 merge requests
!33
MAINT: change arguments of create_user
,
!15
F entity role
Pipeline
#9723
passed
4 years ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosdb/common/models.py
+22
-1
22 additions, 1 deletion
src/caosdb/common/models.py
unittests/test_entity.py
+17
-2
17 additions, 2 deletions
unittests/test_entity.py
with
39 additions
and
3 deletions
src/caosdb/common/models.py
+
22
−
1
View file @
b9ee004d
...
@@ -128,7 +128,24 @@ class Entity(object):
...
@@ -128,7 +128,24 @@ class Entity(object):
@property
@property
def
role
(
self
):
def
role
(
self
):
"""
Return the role of this entity.
Particularly, this means
1. return the explicitly set role, if present.
2. or, if this is a direct instance of the Entity class (and not of
any subclass of Entity) which hence has no
"
natural
"
role, return
None.
3. Otherwise, return the class name of this entity, because this the
natural role of this object.
Returns
-------
str
The entities role or `None`
"""
if
self
.
__role
:
return
self
.
__role
return
self
.
__role
if
type
(
self
)
is
not
Entity
:
return
type
(
self
).
__name__
@role.setter
@role.setter
def
role
(
self
,
role
):
def
role
(
self
,
role
):
...
@@ -832,6 +849,9 @@ class Entity(object):
...
@@ -832,6 +849,9 @@ class Entity(object):
if
xml
is
None
:
if
xml
is
None
:
xml
=
etree
.
Element
(
"
Entity
"
)
xml
=
etree
.
Element
(
"
Entity
"
)
# use role as xml tag name, fall-back to "Entity"
elem_tag
=
"
Entity
"
if
self
.
role
is
None
else
self
.
role
xml
=
etree
.
Element
(
elem_tag
)
assert
isinstance
(
xml
,
etree
.
_Element
)
assert
isinstance
(
xml
,
etree
.
_Element
)
# unwrap wrapped entity
# unwrap wrapped entity
...
@@ -2277,6 +2297,7 @@ class _Messages(dict):
...
@@ -2277,6 +2297,7 @@ class _Messages(dict):
def
_basic_sync
(
e_local
,
e_remote
):
def
_basic_sync
(
e_local
,
e_remote
):
if
e_local
is
None
or
e_remote
is
None
:
if
e_local
is
None
or
e_remote
is
None
:
return
None
return
None
e_local
.
role
=
e_remote
.
role
e_local
.
id
=
e_remote
.
id
e_local
.
id
=
e_remote
.
id
e_local
.
name
=
e_remote
.
name
e_local
.
name
=
e_remote
.
name
e_local
.
description
=
e_remote
.
description
e_local
.
description
=
e_remote
.
description
...
...
This diff is collapsed.
Click to expand it.
unittests/test_entity.py
+
17
−
2
View file @
b9ee004d
...
@@ -41,18 +41,33 @@ class TestEntity(unittest.TestCase):
...
@@ -41,18 +41,33 @@ class TestEntity(unittest.TestCase):
def
test_instance_variables
(
self
):
def
test_instance_variables
(
self
):
entity
=
Entity
()
entity
=
Entity
()
self
.
assertTrue
(
hasattr
(
entity
,
"
role
"
))
self
.
assertTrue
(
hasattr
(
entity
,
"
id
"
))
self
.
assertTrue
(
hasattr
(
entity
,
"
id
"
))
self
.
assertTrue
(
hasattr
(
entity
,
"
name
"
))
self
.
assertTrue
(
hasattr
(
entity
,
"
name
"
))
self
.
assertTrue
(
hasattr
(
entity
,
"
description
"
))
self
.
assertTrue
(
hasattr
(
entity
,
"
description
"
))
self
.
assertTrue
(
hasattr
(
entity
,
"
parents
"
))
self
.
assertTrue
(
hasattr
(
entity
,
"
parents
"
))
self
.
assertTrue
(
hasattr
(
entity
,
"
properties
"
))
self
.
assertTrue
(
hasattr
(
entity
,
"
properties
"
))
def
test_role
(
self
):
def
test_
entity_
role
_1
(
self
):
entity
=
Entity
(
role
=
"
TestRole
"
)
entity
=
Entity
(
role
=
"
TestRole
"
)
self
.
assertEqual
(
entity
.
role
,
"
TestRole
"
)
self
.
assertEqual
(
entity
.
role
,
"
TestRole
"
)
entity
.
role
=
"
TestRole2
"
entity
.
role
=
"
TestRole2
"
self
.
assertEqual
(
entity
.
role
,
"
TestRole2
"
)
self
.
assertEqual
(
entity
.
role
,
"
TestRole2
"
)
def
test_entity_role_2
(
self
):
entity
=
Entity
()
self
.
assertIsNone
(
entity
.
role
)
self
.
assertEqual
(
entity
.
to_xml
().
tag
,
"
Entity
"
)
entity
.
role
=
"
Record
"
self
.
assertEqual
(
entity
.
role
,
"
Record
"
)
self
.
assertEqual
(
entity
.
to_xml
().
tag
,
"
Record
"
)
def
test_recordtype_role
(
self
):
entity
=
RecordType
()
self
.
assertEqual
(
entity
.
role
,
"
RecordType
"
)
self
.
assertEqual
(
entity
.
to_xml
().
tag
,
"
RecordType
"
)
def
test_instanciation
(
self
):
def
test_instanciation
(
self
):
self
.
assertRaises
(
Exception
,
Entity
())
self
.
assertRaises
(
Exception
,
Entity
())
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