Skip to content
Snippets Groups Projects
Commit 8ecb2fe7 authored by florian's avatar florian
Browse files

TST: Use correct error

parent 442cf919
Branches
Tags
2 merge requests!93Release 0.11.0,!81F merge conflict error
......@@ -29,7 +29,8 @@ import pytest
import caosdb as db
import caosdb.apiutils
from caosdb.apiutils import (apply_to_ids, compare_entities, create_id_query,
empty_diff, resolve_reference, merge_entities)
empty_diff, EntityMergeConflictError,
resolve_reference, merge_entities)
from caosdb.common.models import SPECIAL_ATTRIBUTES
......@@ -306,7 +307,7 @@ def test_merge_bug_conflict():
r3 = db.Record()
r3.add_property(name="C", value=4, datatype="INTEGER")
with pytest.raises(RuntimeError) as excinfo:
with pytest.raises(EntityMergeConflictError):
merge_entities(r3, r2)
......@@ -401,15 +402,13 @@ def test_wrong_merge_conflict_reference():
rec_a.add_property(name=title_prop.name, value="Some dataset title")
# this does not compare referenced records, so it will fail
with pytest.raises(RuntimeError) as re:
with pytest.raises(EntityMergeConflictError):
merge_entities(rec_a, rec_b, merge_references_with_empty_diffs=False)
assert "Merge conflict" in str(re.value)
# ... as should this, of course
rec_b.get_property(license_rt.name).value.name = "Another license"
with pytest.raises(RuntimeError) as re:
with pytest.raises(EntityMergeConflictError) as re:
merge_entities(rec_a, rec_b)
assert "Merge conflict" in str(re.value)
def test_empty_diff():
......@@ -483,9 +482,8 @@ def test_force_merge():
recA = db.Record(name="A")
recB = db.Record(name="B")
with pytest.raises(RuntimeError) as re:
with pytest.raises(EntityMergeConflictError):
merge_entities(recA, recB)
assert "Merge conflict" in str(re.value)
merge_entities(recA, recB, force=True)
assert "B" == recA.name
......@@ -498,9 +496,8 @@ def test_force_merge():
recB = db.Record()
recB.description = "something else"
with pytest.raises(RuntimeError) as re:
with pytest.raises(EntityMergeConflictError):
merge_entities(recA, recB)
assert "Merge conflict" in str(re.value)
merge_entities(recA, recB, force=True)
assert recA.description == "something else"
......@@ -513,9 +510,8 @@ def test_force_merge():
recB = db.Record()
recB.add_property(name="propA", value="something else")
with pytest.raises(RuntimeError) as re:
with pytest.raises(EntityMergeConflictError):
merge_entities(recA, recB)
assert "Merge conflict" in str(re.value)
merge_entities(recA, recB, force=True)
assert recA.get_property("propA").value == "something else"
......@@ -539,9 +535,8 @@ def test_force_merge():
rtB = db.RecordType()
rtB.add_property(name="propA", datatype=db.TEXT)
with pytest.raises(RuntimeError) as re:
with pytest.raises(EntityMergeConflictError):
merge_entities(rtA, rtB)
assert "Merge conflict" in str(re.value)
merge_entities(rtA, rtB, force=True)
assert rtA.get_property("propA").datatype == db.TEXT
......@@ -554,9 +549,8 @@ def test_force_merge():
recB = db.Record()
recB.add_property(name="propA", value=5, unit="cm")
with pytest.raises(RuntimeError) as re:
with pytest.raises(EntityMergeConflictError):
merge_entities(recA, recB)
assert "Merge conflict" in str(re.value)
merge_entities(recA, recB, force=True)
assert recA.get_property("propA").unit == "cm"
# unchanged
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment