diff --git a/tests/test_tickets.py b/tests/test_tickets.py index 8c370cba33624e93220a171a22845f4b2eddfb3e..e7735ffb20e324d31c2f535e116615d7f61b7940 100644 --- a/tests/test_tickets.py +++ b/tests/test_tickets.py @@ -35,7 +35,7 @@ from nose import with_setup from nose.tools import (assert_equal, assert_false, assert_is_none, assert_is_not_none, assert_raises, assert_true, nottest) - +import pytest from tests import test_misc @@ -62,75 +62,74 @@ def test_ticket_103a(): # insert w/o strict flag haswarnings = False rt.insert(strict=False) - assert_true(rt.is_valid()) + assert rt.is_valid() for w in rt.get_warnings(): haswarnings = True break - assert_true(haswarnings) + assert haswarnings # update w/o strict flag haswarnings = False rt.name = "TestRecordTypeUpdate" rt.update(strict=False) - assert_true(rt.is_valid()) + assert rt.is_valid() for w in rt.get_warnings(): haswarnings = True break - assert_true(haswarnings) + assert haswarnings # update w/ strict flag rt.name = "TestRecordTypeUpdate2" - try: + with pytest.raises(TransactionError) as e: rt.update(strict=True) - assert_true(False, "This should have raised an 128-Error (strict)") - except TransactionError as exc: - print(exc) - assert_equal(128, int(exc.get_code())) - rt = exc.get_entities()[0] - assert_false(rt.is_valid()) + exc = e.value + print(exc) + assert 128 == exc.get_errors()[0].get_code() + rt = exc.get_entities()[0] + assert not rt.is_valid() for w in rt.get_warnings(): haswarnings = True break - assert_true(haswarnings) + assert haswarnings for w in rt.get_errors(): if w.get_code() == 128: hasstricterror = True break - assert_true(hasstricterror) + assert hasstricterror finally: try: rt.delete() except BaseException: pass - # insert w/ strict flag + # insert w/ strict flag without raising an exception haswarnings = False hasstricterror = False rt = db.RecordType(name="TestRecordType") try: rt.insert(strict=True, raise_exception_on_error=False) - assert_false(rt.is_valid()) + assert not rt.is_valid() for w in rt.get_warnings(): haswarnings = True break - assert_true(haswarnings) + assert haswarnings for w in rt.get_errors(): if w.get_code() == 128: hasstricterror = True break - assert_true(hasstricterror) + assert hasstricterror finally: try: rt.delete() @@ -158,19 +157,17 @@ def test_ticket_103b(): # unique flag try: - rt1 = db.RecordType(name="NameDuplicatesEntity") - rt2 = db.RecordType(name="NameDuplicatesEntity") + rt1 = db.RecordType(name="TestNameDuplicatesEntity") + rt2 = db.RecordType(name="TestNameDuplicatesEntity") rt1.insert( unique=True, strict=False) - assert_true(rt1.is_valid()) - try: + assert rt1.is_valid() + with pytest.raises(TransactionError) as te: rt2.insert(unique=True) - assert_true(False) - except UniqueNamesError: - pass - - assert_false(rt2.is_valid()) + assert te.value.has_error(UniqueNamesError) + + assert not rt2.is_valid() finally: try: @@ -183,24 +180,6 @@ def test_ticket_103b(): pass -def test_ticket_102(): - """EntityDoesNotExistException.""" - - try: - p = db.Property(name="Non-ExistentProperty") - p.retrieve( - unique=True, raise_exception_on_error=True) - assert_true(False) - except CaosDBException as e: - assert_true(isinstance(e, EntityDoesNotExistError)) - assert_is_not_none(e.get_entity()) - assert_equal(e.get_entity().name, p.name) - assert_true(e.get_entity().has_errors()) - assert_false(p.has_errors()) - assert_false(p.is_valid()) - assert_false(e.get_entity().is_valid()) - - def test_ticket_101(): """RecordType and Property constructor work differently?"""