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
3819463a
Verified
Commit
3819463a
authored
3 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
Tests for obligatory properties
parent
3fe6a61f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!9
Tests for obligatory properties
Pipeline
#8891
passed
3 years ago
Stage: cert
Stage: style
Stage: test
Changes
1
Pipelines
6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_importance.py
+148
-0
148 additions, 0 deletions
tests/test_importance.py
with
148 additions
and
0 deletions
tests/test_importance.py
0 → 100644
+
148
−
0
View file @
3819463a
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
from
pytest
import
raises
import
caosdb
as
db
def
setup
():
teardown_module
()
def
teardown_module
():
clean
=
db
.
execute_query
(
"
FIND Test*
"
)
if
len
(
clean
)
>
0
:
clean
.
delete
()
def
test_obl_missing_error
():
p
=
db
.
Property
(
name
=
"
TestOblProperty
"
,
datatype
=
db
.
TEXT
).
insert
()
p_dummy
=
db
.
Property
(
name
=
"
TestDummyProperty
"
,
datatype
=
db
.
TEXT
).
insert
()
rt1
=
db
.
RecordType
(
name
=
"
TestRecordType1
"
)
rt1
.
add_property
(
name
=
"
TestOblProperty
"
,
importance
=
db
.
OBLIGATORY
)
rt1
.
insert
()
# normal behaviour
rt2
=
db
.
RecordType
(
name
=
"
TestRecordType2
"
)
rt2
.
add_parent
(
"
TestRecordType1
"
,
inheritance
=
db
.
NONE
)
rt2
.
add_property
(
"
TestDummyProperty
"
)
with
raises
(
db
.
TransactionError
)
as
exc
:
rt2
.
insert
()
assert
exc
.
value
.
errors
[
0
].
msg
==
"
An obligatory property is missing.
"
# force error
rt2
=
db
.
RecordType
(
name
=
"
TestRecordType2
"
)
rt2
.
add_parent
(
"
TestRecordType1
"
,
inheritance
=
db
.
NONE
)
rt2
.
add_property
(
"
TestDummyProperty
"
)
rt2
.
set_flag
(
"
force-missing-obligatory
"
,
"
error
"
)
with
raises
(
db
.
TransactionError
)
as
exc
:
rt2
.
insert
()
assert
exc
.
value
.
errors
[
0
].
msg
==
"
An obligatory property is missing.
"
# warning is treated as error because "strict" flag
rt2
=
db
.
RecordType
(
name
=
"
TestRecordType2
"
)
rt2
.
add_parent
(
"
TestRecordType1
"
,
inheritance
=
db
.
NONE
)
rt2
.
add_property
(
"
TestDummyProperty
"
)
rt2
.
set_flag
(
"
force-missing-obligatory
"
,
"
warn
"
)
with
raises
(
db
.
TransactionError
)
as
exc
:
rt2
.
insert
(
strict
=
True
)
assert
exc
.
value
.
errors
[
0
].
msg
==
"
A warning occured while processing an entity with the strict flag.
"
assert
"
An obligatory property is missing.
"
in
[
w
.
description
for
w
in
rt2
.
get_warnings
()]
# insert with warning
rt2
=
db
.
RecordType
(
name
=
"
TestRecordType2
"
)
rt2
.
add_parent
(
"
TestRecordType1
"
,
inheritance
=
db
.
NONE
)
rt2
.
add_property
(
"
TestDummyProperty
"
)
rt2
.
set_flag
(
"
force-missing-obligatory
"
,
"
warn
"
)
rt2
.
insert
()
assert
len
(
rt2
.
get_errors
())
==
0
assert
rt2
.
get_warnings
(
)[
0
].
description
==
"
An obligatory property is missing.
"
# insert silently
rt3
=
db
.
RecordType
(
name
=
"
TestRecordType3
"
)
rt3
.
add_parent
(
"
TestRecordType1
"
,
inheritance
=
db
.
NONE
)
rt3
.
add_property
(
"
TestDummyProperty
"
)
rt3
.
set_flag
(
"
force-missing-obligatory
"
,
"
ignore
"
)
rt3
.
insert
()
assert
len
(
rt3
.
get_errors
())
==
0
assert
len
(
rt3
.
get_warnings
())
==
0
def
test_obl_missing_parent_in_same_container
():
p
=
db
.
Property
(
name
=
"
TestOblProperty
"
,
datatype
=
db
.
TEXT
).
insert
()
rt1
=
db
.
RecordType
(
name
=
"
TestRecordType1
"
)
rt1
.
add_property
(
name
=
"
TestOblProperty
"
,
importance
=
db
.
OBLIGATORY
)
rt2
=
db
.
RecordType
(
name
=
"
TestRecordType2
"
)
rt2
.
add_parent
(
"
TestRecordType1
"
,
inheritance
=
db
.
NONE
)
c
=
db
.
Container
()
c
.
extend
([
rt1
,
rt2
])
# with raises(db.TransactionError) as exc:
# c.insert()
# assert exc.value == "asdf"
# set container flag, override in rt2 (entity flag takes precedence here)
rt2
.
set_flag
(
"
force-missing-obligatory
"
,
"
error
"
)
with
raises
(
db
.
TransactionError
)
as
exc
:
c
.
insert
(
flags
=
{
"
force-missing-obligatory
"
:
"
ignore
"
})
assert
exc
.
value
.
errors
[
0
].
msg
==
"
An obligatory property is missing.
"
def
test_sub_property_of_obl
():
p1
=
db
.
Property
(
name
=
"
TestOblProperty1
"
,
datatype
=
db
.
TEXT
).
insert
()
p2
=
db
.
Property
(
name
=
"
TestOblProperty2
"
,
datatype
=
db
.
TEXT
)
p2
.
add_parent
(
"
TestOblProperty1
"
)
p2
.
insert
()
rt1
=
db
.
RecordType
(
name
=
"
TestRecordType1
"
)
rt1
.
add_property
(
name
=
"
TestOblProperty1
"
,
importance
=
db
.
OBLIGATORY
)
rt1
.
insert
()
rt2
=
db
.
RecordType
(
name
=
"
TestRecordType2
"
)
rt2
.
add_parent
(
"
TestRecordType1
"
,
inheritance
=
db
.
NONE
)
# add subtype of TestOblProperty1
rt2
.
add_property
(
"
TestOblProperty2
"
)
rt2
.
insert
()
# everything ok!
def
test_sub_property_of_obl_in_same_container
():
p1
=
db
.
Property
(
name
=
"
TestOblProperty1
"
,
datatype
=
db
.
TEXT
).
insert
()
rt1
=
db
.
RecordType
(
name
=
"
TestRecordType1
"
)
rt1
.
add_property
(
name
=
"
TestOblProperty1
"
,
importance
=
db
.
OBLIGATORY
)
rt1
.
insert
()
p2
=
db
.
Property
(
name
=
"
TestOblProperty2
"
,
datatype
=
db
.
TEXT
)
p2
.
add_parent
(
"
TestOblProperty1
"
)
rt2
=
db
.
RecordType
(
name
=
"
TestRecordType2
"
)
rt2
.
add_parent
(
"
TestRecordType1
"
,
inheritance
=
db
.
NONE
)
rt2
.
add_property
(
"
TestOblProperty2
"
)
c
=
db
.
Container
()
c
.
extend
([
rt2
,
p2
])
c
.
insert
()
# everything ok!
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