Skip to content
Snippets Groups Projects

Tests for obligatory properties

Merged Timm Fitschen requested to merge f-importance into dev
Files
2
+ 27
9
@@ -40,7 +40,7 @@ def test_obl_missing_error():
rt1.add_property(name="TestOblProperty", importance=db.OBLIGATORY)
rt1.insert()
# normal behaviour
# normal behaviour, should be identical to "error" level
rt2 = db.RecordType(name="TestRecordType2")
rt2.add_parent("TestRecordType1", inheritance=db.NONE)
rt2.add_property("TestDummyProperty")
@@ -64,7 +64,8 @@ def test_obl_missing_error():
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 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()]
@@ -75,8 +76,8 @@ def test_obl_missing_error():
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."
assert (rt2.get_warnings()[0].description
== "An obligatory property is missing.")
# insert silently
rt3 = db.RecordType(name="TestRecordType3")
@@ -99,18 +100,33 @@ def test_obl_missing_parent_in_same_container():
c = db.Container()
c.extend([rt1, rt2])
# with raises(db.TransactionError) as exc:
# c.insert()
# assert exc.value == "asdf"
with raises(db.TransactionError) as exc:
c.insert()
assert exc.value.errors[0].msg == "An obligatory property is missing."
def test_obl_missing_parent_in_same_container_override():
"""`force-missing-obligatory` flags of entities override flags of containing containers.
"""
p = db.Property(name="TestOblProperty", datatype=db.TEXT).insert()
rt1 = db.RecordType(name="TestRecordType1")
rt1.add_property(name="TestOblProperty", importance=db.OBLIGATORY)
# set container flag, override in rt2 (entity flag takes precedence here)
rt2 = db.RecordType(name="TestRecordType2")
rt2.add_parent("TestRecordType1", inheritance=db.NONE)
rt2.set_flag("force-missing-obligatory", "error")
c = db.Container()
c.extend([rt1, rt2])
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():
"""If p1 <|- p2, then p2 should work for an obligatory p1.
"""
p1 = db.Property(name="TestOblProperty1", datatype=db.TEXT).insert()
p2 = db.Property(name="TestOblProperty2", datatype=db.TEXT)
p2.add_parent("TestOblProperty1")
@@ -147,6 +163,7 @@ def test_sub_property_of_obl_in_same_container():
c.extend([rt2, p2])
c.insert() # everything ok!
def test_illegal_flag_value():
p = db.Property(name="TestOblProperty", datatype=db.TEXT).insert()
p_dummy = db.Property(name="TestDummyProperty", datatype=db.TEXT).insert()
@@ -163,4 +180,5 @@ def test_illegal_flag_value():
rt2.insert()
# default behavior + warning
assert exc.value.errors[0].msg == "An obligatory property is missing."
assert "Illegal value for flag 'force-missing-obligatory'." in [w.description for w in rt2.get_warnings()]
assert "Illegal value for flag 'force-missing-obligatory'." in [
w.description for w in rt2.get_warnings()]
Loading