Skip to content
Snippets Groups Projects
Commit 90c4195b authored by florian's avatar florian
Browse files

TST: Update remaining errors

parent 2929c1a5
Branches
Tags
No related merge requests found
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
""" """
import caosdb as db import caosdb as db
# @UnresolvedImport # @UnresolvedImport
from nose.tools import nottest, assert_raises, with_setup, assert_true, assert_equal from nose.tools import nottest, with_setup, assert_true, assert_equal
from pytest import raises
def setup(): def setup():
...@@ -50,15 +51,15 @@ def test_override_with_non_existing_ref(): ...@@ -50,15 +51,15 @@ def test_override_with_non_existing_ref():
rt2 = db.RecordType("TestRecordType2").insert() rt2 = db.RecordType("TestRecordType2").insert()
db.Property("TestProperty", datatype=db.TEXT).insert() db.Property("TestProperty", datatype=db.TEXT).insert()
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
db.Record( db.Record(
name="TestRecord").add_property( name="TestRecord").add_property(
name="TestProperty", name="TestProperty",
datatype=rt2, datatype=rt2,
value="Non-Existing").add_parent(rt1).insert() value="Non-Existing").add_parent(rt1).insert()
assert_equal( assert cm.value.has_error(db.UnqualifiedPropertiesError)
cm.exception.get_errors()[0].msg, assert (cm.value.get_errors()[0].get_errors()[0].msg ==
"Referenced entity does not exist.") "Referenced entity does not exist.")
@with_setup(setup, teardown) @with_setup(setup, teardown)
...@@ -143,37 +144,33 @@ def test_generic_reference_failure(): ...@@ -143,37 +144,33 @@ def test_generic_reference_failure():
name="TestRT2").add_property( name="TestRT2").add_property(
name="TestP1", name="TestP1",
value="asdf") value="asdf")
assert_raises(db.TransactionError, rec2.insert) with raises(db.TransactionError):
rec2.insert()
@with_setup(setup, teardown) @with_setup(setup, teardown)
def test_unknown_datatype1(): def test_unknown_datatype1():
p = db.Property(name="TestP", datatype="Non-Existing") p = db.Property(name="TestP", datatype="Non-Existing")
try: with raises(db.TransactionError) as te:
p.insert() p.insert()
assert_true(False) assert_true(False)
except db.TransactionError as e: assert te.value.get_errors()[0].msg == "Unknown datatype."
assert_equal(e.msg, "Unknown datatype.")
@with_setup(setup, teardown) @with_setup(setup, teardown)
def test_unknown_datatype2(): def test_unknown_datatype2():
p = db.Property(name="TestP", datatype="12345687654334567") p = db.Property(name="TestP", datatype="12345687654334567")
try: with raises(db.TransactionError) as te:
p.insert() p.insert()
assert_true(False) assert te.value.get_errors()[0].msg == "Unknown datatype."
except db.TransactionError as e:
assert_equal(e.msg, "Unknown datatype.")
@with_setup(setup, teardown) @with_setup(setup, teardown)
def test_unknown_datatype3(): def test_unknown_datatype3():
p = db.Property(name="TestP", datatype="-134") p = db.Property(name="TestP", datatype="-134")
try: with raises(db.TransactionError) as te:
p.insert() p.insert()
assert_true(False) assert te.value.get_errors()[0].msg == "Unknown datatype."
except db.TransactionError as e:
assert_equal(e.msg, "Unknown datatype.")
@with_setup(setup, teardown) @with_setup(setup, teardown)
...@@ -182,10 +179,10 @@ def test_wrong_refid(): ...@@ -182,10 +179,10 @@ def test_wrong_refid():
rt2 = db.RecordType(name="TestRT2").insert() rt2 = db.RecordType(name="TestRT2").insert()
rt3 = db.RecordType(name="TestRT3").insert() rt3 = db.RecordType(name="TestRT3").insert()
p = db.Property(name="TestP1", datatype=rt1.id).insert() p = db.Property(name="TestP1", datatype=rt1.id).insert()
assert_true(p.is_valid()) assert p.is_valid()
assert_true(rt1.is_valid()) assert rt1.is_valid()
assert_true(rt2.is_valid()) assert rt2.is_valid()
assert_true(rt3.is_valid()) assert rt3.is_valid()
rec1 = db.Record().add_parent(name="TestRT1").insert() rec1 = db.Record().add_parent(name="TestRT1").insert()
rec2 = db.Record().add_parent(name="TestRT2").insert() rec2 = db.Record().add_parent(name="TestRT2").insert()
...@@ -193,16 +190,13 @@ def test_wrong_refid(): ...@@ -193,16 +190,13 @@ def test_wrong_refid():
name="TestRT3").add_property( name="TestRT3").add_property(
name="TestP1", name="TestP1",
value=rec2.id) value=rec2.id)
try: with raises(db.TransactionError):
rec3.insert() rec3.insert()
assert_true(False) assert (rec3.get_property("TestP1").get_errors()[0].description ==
except db.TransactionError:
assert_equal(
rec3.get_property("TestP1").get_errors()[0].description,
'Reference not qualified. The value of this Reference Property is to be a child of its data type.') 'Reference not qualified. The value of this Reference Property is to be a child of its data type.')
rec4 = db.Record().add_parent( rec4 = db.Record().add_parent(
name="TestRT3").add_property( name="TestRT3").add_property(
name="TestP1", name="TestP1",
value=rec1.id).insert() value=rec1.id).insert()
assert_true(rec4.is_valid()) assert rec4.is_valid()
...@@ -27,12 +27,13 @@ ...@@ -27,12 +27,13 @@
@author: tf @author: tf
""" """
from nose.tools import (assert_equal, assert_is_not_none, # @UnresolvedImport from nose.tools import (assert_equal, assert_is_not_none, # @UnresolvedImport
assert_not_equal, assert_raises, assert_true, nottest, assert_not_equal, assert_true, nottest,
with_setup) with_setup)
import caosdb as db import caosdb as db
from caosdb import (Container, Info, Property, Record, RecordType, from caosdb import (Container, Info, Property, Record, RecordType,
execute_query) execute_query)
from pytest import raises
def setup(): def setup():
...@@ -142,16 +143,18 @@ def test_error_no_such_role(): ...@@ -142,16 +143,18 @@ def test_error_no_such_role():
xml = "<Insert><Entity name='test'/></Insert>" xml = "<Insert><Entity name='test'/></Insert>"
r = db.get_connection().insert(entity_uri_segment=["Entity"], body=xml) r = db.get_connection().insert(entity_uri_segment=["Entity"], body=xml)
c = Container._response_to_entities(r) c = Container._response_to_entities(r)
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
db.raise_errors(c) db.raise_errors(c)
assert_equal(cm.exception.msg, "There is no such role 'Entity'.") assert (cm.value.get_errors()[0].msg ==
"There is no such role 'Entity'.")
xml = "<Insert><ASDF name='test'/></Insert>" xml = "<Insert><ASDF name='test'/></Insert>"
r = db.get_connection().insert(entity_uri_segment=["Entity"], body=xml) r = db.get_connection().insert(entity_uri_segment=["Entity"], body=xml)
c = Container._response_to_entities(r) c = Container._response_to_entities(r)
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
db.raise_errors(c) db.raise_errors(c)
assert_equal(cm.exception.msg, "There is no such role 'ASDF'.") assert (cm.value.get_errors()[0].msg ==
"There is no such role 'ASDF'.")
@with_setup(setup, setup) @with_setup(setup, setup)
...@@ -181,22 +184,21 @@ def test_parent_duplicate_2(): ...@@ -181,22 +184,21 @@ def test_parent_duplicate_2():
inheritance=db.ALL).add_parent( inheritance=db.ALL).add_parent(
name="TestRT1", name="TestRT1",
inheritance=db.NONE) inheritance=db.NONE)
assert_equal(len(rt2.get_parents()), 2) assert len(rt2.get_parents()) == 2
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
rt2.insert() rt2.insert()
assert_equal( assert (cm.value.get_errors()[0].msg ==
cm.exception.msg, "This entity had parent duplicates. Parent duplicates are meaningless and would be ignored (and inserted only once). But these parents had diverging inheritance instructions which cannot be processed.")
"This entity had parent duplicates. Parent duplicates are meaningless and would be ignored (and inserted only once). But these parents had diverging inheritance instructions which cannot be processed.")
def test_server_error(): def test_server_error():
con = db.get_connection() con = db.get_connection()
con._login() con._login()
with assert_raises(db.ServerErrorException) as cm: with raises(db.ServerErrorException) as cm:
con._http_request( con._http_request(
method="GET", method="GET",
path="Entity?debug=throwNullPointerException") path="Entity?debug=throwNullPointerException")
assert_true("SRID = " in cm.exception.msg) assert_true("SRID = " in cm.value.msg)
def test_annotation(): def test_annotation():
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
""" """
import caosdb as db import caosdb as db
from nose.tools import with_setup, assert_true, assert_is_none, assert_equal, assert_is_not_none, nottest, assert_raises # @UnresolvedImport from nose.tools import with_setup, assert_true, assert_is_none, assert_equal, assert_is_not_none, nottest, assert_raises # @UnresolvedImport
from pytest import raises
def setup_module(): def setup_module():
...@@ -107,12 +108,11 @@ def test_insertion_failure_syntax(): ...@@ -107,12 +108,11 @@ def test_insertion_failure_syntax():
name="TestQueryTemplate", name="TestQueryTemplate",
description="Find some interesting things with via a simple name.", description="Find some interesting things with via a simple name.",
query="SDASDUASIUF") query="SDASDUASIUF")
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
q.insert() q.insert()
print(cm.exception) print(cm.value)
assert_equal( assert (cm.value.get_errors()[0].msg ==
cm.exception.msg, "An error occured during the parsing of this query. Maybe you use a wrong syntax?")
"An error occured during the parsing of this query. Maybe you use a wrong syntax?")
@with_setup(setup, teardown) @with_setup(setup, teardown)
...@@ -121,11 +121,10 @@ def test_insertion_failure_count_query_not_allowed(): ...@@ -121,11 +121,10 @@ def test_insertion_failure_count_query_not_allowed():
name="TestQueryTemplate", name="TestQueryTemplate",
description="Find some interesting things with via a simple name.", description="Find some interesting things with via a simple name.",
query="COUNT something") query="COUNT something")
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
q.insert() q.insert()
assert_equal( assert (cm.value.get_errors()[0].msg ==
cm.exception.msg, "QueryTemplates may not be defined by 'COUNT...' queries for consistency reasons.")
"QueryTemplates may not be defined by 'COUNT...' queries for consistency reasons.")
@with_setup(setup, teardown) @with_setup(setup, teardown)
...@@ -135,11 +134,10 @@ def test_insertion_failure_select_query_not_allowed(): ...@@ -135,11 +134,10 @@ def test_insertion_failure_select_query_not_allowed():
name="TestQueryTemplate", name="TestQueryTemplate",
description="Find some interesting things with via a simple name.", description="Find some interesting things with via a simple name.",
query=query_def) query=query_def)
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
q.insert() q.insert()
assert_equal( assert (cm.value.get_errors()[0].msg ==
cm.exception.msg, "QueryTemplates may not be defined by 'SELECT... FROM...' queries for consistency reasons.")
"QueryTemplates may not be defined by 'SELECT... FROM...' queries for consistency reasons.")
@with_setup(setup, teardown) @with_setup(setup, teardown)
...@@ -152,9 +150,9 @@ def test_deletion_success(): ...@@ -152,9 +150,9 @@ def test_deletion_success():
@with_setup(setup, teardown) @with_setup(setup, teardown)
def test_deletion_failure_non_existing(): def test_deletion_failure_non_existing():
q = db.QueryTemplate(id="12342") q = db.QueryTemplate(id="12342")
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
q.delete() q.delete()
assert_equal(cm.exception.msg, "Entity does not exist.") assert cm.value.has_error(db.EntityDoesNotExistError)
@with_setup(setup, teardown) @with_setup(setup, teardown)
...@@ -169,9 +167,9 @@ def test_retrieve_success(): ...@@ -169,9 +167,9 @@ def test_retrieve_success():
@with_setup(setup, teardown) @with_setup(setup, teardown)
def test_retrieve_failure_non_existing(): def test_retrieve_failure_non_existing():
q = db.QueryTemplate(id="12342") q = db.QueryTemplate(id="12342")
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
q.retrieve() q.retrieve()
assert_equal(cm.exception.msg, "Entity does not exist.") assert cm.value.has_error(db.EntityDoesNotExistError)
@with_setup(setup, teardown) @with_setup(setup, teardown)
...@@ -185,42 +183,39 @@ def test_update_success(): ...@@ -185,42 +183,39 @@ def test_update_success():
def test_update_failure_syntax(): def test_update_failure_syntax():
q = test_insertion_success() q = test_insertion_success()
q.query = "ashdjfkasjdf" q.query = "ashdjfkasjdf"
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
q.update() q.update()
assert_equal( assert(cm.value.get_errors()[0].msg ==
cm.exception.msg, "An error occured during the parsing of this query. Maybe you use a wrong syntax?")
"An error occured during the parsing of this query. Maybe you use a wrong syntax?")
@with_setup(setup, teardown) @with_setup(setup, teardown)
def test_update_failure_count_query_not_allowed(): def test_update_failure_count_query_not_allowed():
q = test_insertion_success() q = test_insertion_success()
q.query = "COUNT somethingNew" q.query = "COUNT somethingNew"
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
q.update() q.update()
assert_equal( assert (cm.value.get_errors()[0].msg ==
cm.exception.msg, "QueryTemplates may not be defined by 'COUNT...' queries for consistency reasons.")
"QueryTemplates may not be defined by 'COUNT...' queries for consistency reasons.")
@with_setup(setup, teardown) @with_setup(setup, teardown)
def test_update_failure_select_query_not_allowed(): def test_update_failure_select_query_not_allowed():
q = test_insertion_success() q = test_insertion_success()
q.query = "SELECT TestAnimal FROM TestExperiment WHICH HAS A TestAnimal = Pig" q.query = "SELECT TestAnimal FROM TestExperiment WHICH HAS A TestAnimal = Pig"
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
q.update() q.update()
assert_equal( assert (cm.value.get_errors()[0].msg ==
cm.exception.msg, "QueryTemplates may not be defined by 'SELECT... FROM...' queries for consistency reasons.")
"QueryTemplates may not be defined by 'SELECT... FROM...' queries for consistency reasons.")
@with_setup(setup, teardown) @with_setup(setup, teardown)
def test_update_failure_non_existing(): def test_update_failure_non_existing():
q = db.QueryTemplate(id="12342") q = db.QueryTemplate(id="12342")
q.query = "FIND NewStuff" q.query = "FIND NewStuff"
with assert_raises(db.TransactionError) as cm: with raises(db.TransactionError) as cm:
q.update() q.update()
assert_equal(cm.exception.msg, "Entity does not exist.") assert cm.value.has_error(db.EntityDoesNotExistError)
@with_setup(setup, teardown) @with_setup(setup, teardown)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment