Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CaosDB Python Integration Tests
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Python Integration Tests
Commits
e20c9f49
Commit
e20c9f49
authored
4 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Add tests for inheritance bug
parent
49b49e1d
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
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
tests/test_inheritance.py
+125
-117
125 additions, 117 deletions
tests/test_inheritance.py
with
126 additions
and
117 deletions
CHANGELOG.md
+
1
−
0
View file @
e20c9f49
...
...
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added (for new features)
*
Tests for inheritance bug (caosdb/caosdb-server!54)
*
Tests for versioning
*
Tests for deeply nested SELECT queries
*
Tests for
[
#62
](
https://gitlab.com/caosdb/caosdb-server/-/issues/62
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_inheritance.py
+
125
−
117
View file @
e20c9f49
...
...
@@ -27,30 +27,39 @@
"""
import
caosdb
as
h
from
nose.tools
import
assert_equal
,
assert_true
,
assert_is_not_none
,
with_setup
import
caosdb
as
db
def
setup
():
teardown
()
def
teardown
():
d
=
db
.
execute_query
(
"
FIND ENTITY WITH ID > 99
"
)
if
len
(
d
)
>
0
:
d
.
delete
()
def
test_inheritance_fix_properties
():
try
:
"""
FIX PROPERTIES.
"""
'''
insert simple property with unit
'''
p1
=
h
.
Property
(
name
=
'
UnitTestProperty
'
,
datatype
=
'
double
'
,
unit
=
'
m
'
)
p1
=
db
.
Property
(
name
=
'
UnitTestProperty
'
,
datatype
=
'
double
'
,
unit
=
'
m
'
)
p1
.
insert
()
p1c
=
h
.
Property
(
id
=
p1
.
id
).
retrieve
()
assert
_true
(
p1c
.
is_valid
()
)
assert
_equal
(
'
m
'
,
p1c
.
unit
)
p1c
=
db
.
Property
(
id
=
p1
.
id
).
retrieve
()
assert
p1c
.
is_valid
()
assert
'
m
'
==
p1c
.
unit
'''
subtyping with unit inheritance
'''
p2
=
h
.
Property
(
p2
=
db
.
Property
(
name
=
'
SubTypeOfUnitTestProperty
'
).
add_parent
(
id
=
p1
.
id
,
inheritance
=
"
FIX
"
)
print
(
p2
)
p2
.
insert
()
print
(
p2
)
assert
_true
(
p2
.
is_valid
()
)
assert
_equal
(
'
m
'
,
p2
.
unit
)
assert
p2
.
is_valid
()
assert
'
m
'
==
p2
.
unit
finally
:
try
:
p2
.
delete
()
...
...
@@ -65,54 +74,52 @@ def test_inheritance_fix_properties():
def
test_inheritance_obl_properties
():
try
:
"""
OBLIGATORY PROPERTIES.
"""
c
=
h
.
Container
()
c
=
db
.
Container
()
c
.
append
(
h
.
Property
(
db
.
Property
(
name
=
"
SimpleTextProperty
"
,
description
=
"
simple text property (from test_inheritance.py)
"
,
datatype
=
'
text
'
))
c
.
append
(
h
.
Property
(
db
.
Property
(
name
=
"
SimpleDoubleProperty
"
,
description
=
"
simple double property (from test_inheritance.py)
"
,
datatype
=
'
double
'
))
c
.
append
(
h
.
Property
(
db
.
Property
(
name
=
"
SimpleIntegerProperty
"
,
description
=
"
simple integer property (from test_inheritance.py)
"
,
datatype
=
'
integer
'
))
c
.
append
(
h
.
Property
(
db
.
Property
(
name
=
"
SimpleDatetimeProperty
"
,
description
=
"
simple datetime property (from test_inheritance.py)
"
,
datatype
=
'
datetime
'
))
c
.
append
(
h
.
Property
(
db
.
Property
(
name
=
"
SimpleFileProperty
"
,
description
=
"
simple file property (from test_inheritance.py)
"
,
datatype
=
'
file
'
))
c
.
append
(
h
.
RecordType
(
name
=
"
SimpleRecordType
"
,
description
=
"
simple recordType (from test_inheritance.py)
"
)
.
add_property
(
name
=
'
SimpleTextProperty
'
,
importance
=
"
obligatory
"
)
.
add_property
(
name
=
'
SimpleDoubleProperty
'
,
importance
=
"
obligatory
"
)
.
add_property
(
name
=
'
SimpleIntegerProperty
'
,
importance
=
"
obligatory
"
)
.
add_property
(
name
=
'
SimpleDatetimeProperty
'
)
.
add_property
(
name
=
'
SimpleFileProperty
'
))
rt
=
db
.
RecordType
(
name
=
"
SimpleRecordType
"
,
description
=
"
simple recordType (from test_inheritance.py)
"
)
rt
.
add_property
(
name
=
'
SimpleTextProperty
'
,
importance
=
"
obligatory
"
)
rt
.
add_property
(
name
=
'
SimpleDoubleProperty
'
,
importance
=
"
obligatory
"
)
rt
.
add_property
(
name
=
'
SimpleIntegerProperty
'
,
importance
=
"
obligatory
"
)
rt
.
add_property
(
name
=
'
SimpleDatetimeProperty
'
)
rt
.
add_property
(
name
=
'
SimpleFileProperty
'
)
c
.
append
(
rt
)
c
.
insert
()
rt
=
h
.
RecordType
(
rt
=
db
.
RecordType
(
name
=
"
SubTypeOfSimpleRecordType
"
,
description
=
"
recordtype with inheritance (from test_inheritance.py)
"
).
add_parent
(
name
=
"
SimpleRecordType
"
,
inheritance
=
"
obligatory
"
)
rt
.
insert
()
assert_equal
(
3
,
len
(
rt
.
get_properties
()))
# only three properties are obligatory
assert
3
==
len
(
rt
.
get_properties
())
finally
:
try
:
rt
.
delete
()
...
...
@@ -125,69 +132,59 @@ def test_inheritance_obl_properties():
def
test_inheritance_all_properties
():
try
:
"""
ALL PROPERTIES.
"""
c
=
h
.
Container
()
c
.
append
(
h
.
Property
(
name
=
"
SimpleTextProperty
"
,
description
=
"
simple text property (from test_inheritance.py)
"
,
datatype
=
'
text
'
))
c
.
append
(
h
.
Property
(
name
=
"
SimpleDoubleProperty
"
,
description
=
"
simple double property (from test_inheritance.py)
"
,
datatype
=
'
double
'
))
c
.
append
(
h
.
Property
(
name
=
"
SimpleIntegerProperty
"
,
description
=
"
simple integer property (from test_inheritance.py)
"
,
datatype
=
'
integer
'
))
c
.
append
(
h
.
Property
(
name
=
"
SimpleDatetimeProperty
"
,
description
=
"
simple datetime property (from test_inheritance.py)
"
,
datatype
=
'
datetime
'
))
c
.
append
(
h
.
Property
(
name
=
"
SimpleFileProperty
"
,
description
=
"
simple file property (from test_inheritance.py)
"
,
datatype
=
'
file
'
))
c
.
append
(
h
.
RecordType
(
name
=
"
SimpleRecordType
"
,
description
=
"
simple recordType (from test_inheritance.py)
"
)
.
add_property
(
name
=
'
SimpleTextProperty
'
,
importance
=
"
obligatory
"
)
.
add_property
(
name
=
'
SimpleDoubleProperty
'
,
importance
=
"
obligatory
"
)
.
add_property
(
name
=
'
SimpleIntegerProperty
'
,
importance
=
"
obligatory
"
)
.
add_property
(
name
=
'
SimpleDatetimeProperty
'
)
.
add_property
(
name
=
'
SimpleFileProperty
'
))
c
.
insert
()
rt
=
h
.
RecordType
(
name
=
"
SubTypeOfSimpleRecordType
"
,
description
=
"
recordtype with inheritance (from test_inheritance.py)
"
).
add_parent
(
"""
ALL PROPERTIES.
"""
c
=
db
.
Container
()
c
.
append
(
db
.
Property
(
name
=
"
SimpleTextProperty
"
,
description
=
"
simple text property (from test_inheritance.py)
"
,
datatype
=
'
text
'
))
c
.
append
(
db
.
Property
(
name
=
"
SimpleDoubleProperty
"
,
description
=
"
simple double property (from test_inheritance.py)
"
,
datatype
=
'
double
'
))
c
.
append
(
db
.
Property
(
name
=
"
SimpleIntegerProperty
"
,
description
=
"
simple integer property (from test_inheritance.py)
"
,
datatype
=
'
integer
'
))
c
.
append
(
db
.
Property
(
name
=
"
SimpleDatetimeProperty
"
,
description
=
"
simple datetime property (from test_inheritance.py)
"
,
datatype
=
'
datetime
'
))
c
.
append
(
db
.
Property
(
name
=
"
SimpleFileProperty
"
,
description
=
"
simple file property (from test_inheritance.py)
"
,
datatype
=
'
file
'
))
c
.
append
(
db
.
RecordType
(
name
=
"
SimpleRecordType
"
,
inheritance
=
"
obligatory
"
)
rt
.
insert
()
assert_equal
(
3
,
len
(
rt
.
get_properties
()))
finally
:
try
:
rt
.
delete
()
except
BaseException
:
pass
try
:
c
.
delete
()
except
BaseException
:
pass
description
=
"
simple recordType (from test_inheritance.py)
"
)
.
add_property
(
name
=
'
SimpleTextProperty
'
,
importance
=
"
obligatory
"
)
.
add_property
(
name
=
'
SimpleDoubleProperty
'
,
importance
=
"
obligatory
"
)
.
add_property
(
name
=
'
SimpleIntegerProperty
'
,
importance
=
"
obligatory
"
)
.
add_property
(
name
=
'
SimpleDatetimeProperty
'
)
.
add_property
(
name
=
'
SimpleFileProperty
'
))
c
.
insert
()
rt
=
db
.
RecordType
(
name
=
"
SubTypeOfSimpleRecordType
"
,
description
=
"
recordtype with inheritance (from test_inheritance.py)
"
).
add_parent
(
name
=
"
SimpleRecordType
"
,
inheritance
=
"
obligatory
"
)
rt
.
insert
()
assert
3
==
len
(
rt
.
get_properties
())
def
test_inheritance_unit
():
p
=
h
.
Property
(
p
=
db
.
Property
(
name
=
"
SimpleIntProperty
"
,
datatype
=
"
INTEGER
"
,
unit
=
"
m
"
)
...
...
@@ -195,7 +192,7 @@ def test_inheritance_unit():
assert
p
.
is_valid
()
assert
p
.
unit
==
"
m
"
rt
=
h
.
RecordType
(
rt
=
db
.
RecordType
(
name
=
"
SimpleRecordType
"
)
rt
.
add_property
(
p
,
unit
=
"
km
"
)
rt
.
insert
()
...
...
@@ -203,11 +200,11 @@ def test_inheritance_unit():
assert
rt
.
is_valid
()
assert
rt
.
get_property
(
"
SimpleIntProperty
"
).
unit
==
"
km
"
rt2
=
h
.
execute_query
(
"
FIND SimpleRecordType
"
,
True
)
rt2
=
db
.
execute_query
(
"
FIND SimpleRecordType
"
,
True
)
assert
rt2
.
id
==
rt
.
id
assert
rt2
.
get_property
(
"
SimpleIntProperty
"
).
unit
==
"
km
"
rt3
=
h
.
RecordType
(
rt3
=
db
.
RecordType
(
name
=
"
SimpleRecordType2
"
)
rt3
.
add_parent
(
rt
,
inheritance
=
"
ALL
"
)
rt3
.
insert
()
...
...
@@ -215,12 +212,12 @@ def test_inheritance_unit():
assert
rt3
.
get_property
(
"
SimpleIntProperty
"
)
is
not
None
assert
rt3
.
get_property
(
"
SimpleIntProperty
"
).
unit
==
"
km
"
rt4
=
h
.
execute_query
(
"
FIND SimpleRecordType2
"
,
True
)
rt4
=
db
.
execute_query
(
"
FIND SimpleRecordType2
"
,
True
)
assert
rt4
.
is_valid
()
assert
rt4
.
id
==
rt3
.
id
assert
rt4
.
get_property
(
"
SimpleIntProperty
"
).
unit
==
"
km
"
rec
=
h
.
Record
(
rec
=
db
.
Record
(
name
=
"
SimpleRecord
"
)
rec
.
add_parent
(
rt3
)
rec
.
add_property
(
name
=
"
SimpleIntProperty
"
,
value
=
1
)
...
...
@@ -231,43 +228,54 @@ def test_inheritance_unit():
_ENTITIES
=
[
h
.
RecordType
(
name
=
"
Simulation
"
).
add_property
(
name
=
"
SimulationModel
"
),
db
.
RecordType
(
name
=
"
Simulation
"
).
add_property
(
name
=
"
SimulationModel
"
),
h
.
RecordType
(
name
=
"
PublicationReference
"
).
add_property
(
name
=
"
date
"
),
h
.
RecordType
(
db
.
RecordType
(
name
=
"
PublicationReference
"
).
add_property
(
name
=
"
date
"
),
db
.
RecordType
(
name
=
"
SimulationModel
"
).
add_property
(
name
=
"
PublicationReference
"
),
h
.
Property
(
name
=
"
date
"
,
datatype
=
h
.
TEXT
),
h
.
Property
(
name
=
"
blub
"
,
datatype
=
h
.
TEXT
),
db
.
Property
(
name
=
"
date
"
,
datatype
=
db
.
TEXT
),
db
.
Property
(
name
=
"
blub
"
,
datatype
=
db
.
TEXT
),
]
def
setup_subproperties
():
con
=
h
.
Container
().
extend
(
_ENTITIES
)
con
.
insert
()
def
setup_module
():
old
=
h
.
execute_query
(
"
FIND ENTITY WITH ID > 100
"
)
if
old
:
old
.
delete
()
def
teardown_module
():
setup_module
()
@with_setup
(
setup_subproperties
)
def
test_inherit_subproperties
():
valid
=
h
.
Container
().
extend
(
_ENTITIES
).
retrieve
()
container
=
h
.
Container
().
extend
(
_ENTITIES
)
con
=
db
.
Container
().
extend
(
_ENTITIES
)
con
.
insert
()
valid
=
db
.
Container
().
extend
(
_ENTITIES
).
retrieve
()
container
=
db
.
Container
().
extend
(
_ENTITIES
)
container
.
get_entity_by_name
(
"
Simulation
"
).
add_property
(
name
=
"
blub
"
)
for
valid_e
in
valid
:
for
entity
in
container
:
for
prop
in
entity
.
get_properties
():
if
valid_e
.
name
==
prop
.
name
:
prop
.
id
=
valid_e
.
id
entity
.
get_properties
().
_inheritance
[
prop
]
=
h
.
ALL
entity
.
get_properties
().
_inheritance
[
prop
]
=
db
.
ALL
container
.
get_entity_by_name
(
"
SimulationModel
"
).
update
()
container
.
get_entity_by_name
(
"
Simulation
"
).
update
()
def
test_inheritance_in_same_container
():
"""
This test covers three cases:
1. inheritance=db.SUGGESTED
2. inheritance=db.RECOMMENDED
3. inheritance=db.OBLIGATORY
"""
p
=
db
.
Property
(
"
TestProperty1
"
,
datatype
=
db
.
TEXT
)
rt1
=
db
.
RecordType
(
"
TestRT1
"
).
add_property
(
p
,
importance
=
db
.
RECOMMENDED
)
rt2
=
db
.
RecordType
(
"
TestRT2
"
).
add_parent
(
"
TestRT1
"
,
inheritance
=
db
.
SUGGESTED
)
rt3
=
db
.
RecordType
(
"
TestRT3
"
).
add_parent
(
"
TestRT1
"
,
inheritance
=
db
.
RECOMMENDED
)
rt4
=
db
.
RecordType
(
"
TestRT4
"
).
add_parent
(
"
TestRT1
"
,
inheritance
=
db
.
OBLIGATORY
)
c
=
db
.
Container
().
extend
([
p
,
rt1
,
rt2
,
rt3
,
rt4
])
c
.
insert
()
assert
len
(
rt1
.
get_properties
())
==
1
assert
len
(
rt2
.
get_properties
())
==
1
assert
len
(
rt3
.
get_properties
())
==
1
assert
len
(
rt4
.
get_properties
())
==
0
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