diff --git a/CHANGELOG.md b/CHANGELOG.md index c2e7c4e46dfc02627d48888f597543bfc6aab89f..75bdb4f9cf5c8d2950013a1eadfc74556e4bf56e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Tests for [caosdb-pylib#90](https://gitlab.com/caosdb/caosdb-pylib/-/issues/90): `Entity.get_parents_recursively()` did not work for unretrieved parents. * Test for [caosdb-server#192](https://gitlab.com/caosdb/caosdb-server/-/issues/192) +* Test for miscellaneous *-too-long errors. ### Changed (for changes in existing functionality) diff --git a/tests/test_error_stuff.py b/tests/test_error_stuff.py index b43b53ee194a9ec8c598118861786d8e5fde77af..8da132409dff26875a39fda343fa1663d3dac33e 100644 --- a/tests/test_error_stuff.py +++ b/tests/test_error_stuff.py @@ -30,7 +30,7 @@ Created on 19.02.2015. @author: tf """ -import caosdb as h +import linkahead as db from caosdb.exceptions import (AmbiguousEntityError, EntityDoesNotExistError, EntityError, EntityHasNoDatatypeError, @@ -42,7 +42,7 @@ import pytest def setup_function(function): try: - h.execute_query("FIND ENTITY").delete() + db.execute_query("FIND ENTITY").delete() except BaseException: pass @@ -54,7 +54,7 @@ def teardown_function(function): def test_retrieval_no_exception_raised(): """Test whether retrieval fails but error is suppressed.""" - p = h.Property(name="TestNon-ExsistentProperty").retrieve( + p = db.Property(name="TestNon-ExsistentProperty").retrieve( unique=True, raise_exception_on_error=False) assert not p.is_valid() assert (p.id is None or p.id < 0) @@ -67,8 +67,8 @@ def test_retrieval_exception_raised(): """ propname = "TestNon-ExistentProperty" with pytest.raises(TransactionError) as te: - h.Property(name="TestNon-ExistentProperty").retrieve(unique=True, - raise_exception_on_error=True) + db.Property(name="TestNon-ExistentProperty").retrieve(unique=True, + raise_exception_on_error=True) assert len(te.value.errors) == 1 ee = te.value.errors[0] # Check for type incl. inheritance @@ -89,19 +89,19 @@ def test_ambiguous_retrieval(): raised correctly if there are two possible candidates. """ - h.RecordType(name="TestType").insert() - h.Record(name="TestRec").add_parent(name="TestType").insert() + db.RecordType(name="TestType").insert() + db.Record(name="TestRec").add_parent(name="TestType").insert() # Insert twice, so unique=False - h.Record(name="TestRec").add_parent(name="TestType").insert(unique=False) + db.Record(name="TestRec").add_parent(name="TestType").insert(unique=False) with pytest.raises(TransactionError) as te: - h.Record(name="TestRec").retrieve() + db.Record(name="TestRec").retrieve() assert te.value.has_error(AmbiguousEntityError) assert te.value.errors[0].entity.name == "TestRec" def test_insertion_no_exception_raised(): """Test whether insertion fails but no error is raised.""" - p = h.Property(name="TestNoTypeProperty").insert( + p = db.Property(name="TestNoTypeProperty").insert( raise_exception_on_error=False) assert not p.is_valid() assert (p.id is None or p.id < 0) @@ -109,7 +109,7 @@ def test_insertion_no_exception_raised(): def test_insertion_exception_raised(): """Test insertion of a property with missing datatype.""" - p = h.Property(name="TestNoTypeProperty") + p = db.Property(name="TestNoTypeProperty") with pytest.raises(TransactionError) as te: p.insert(raise_exception_on_error=True) assert te.value.has_error(EntityHasNoDatatypeError) @@ -117,7 +117,7 @@ def test_insertion_exception_raised(): def test_insertion_with_invalid_parents(): with pytest.raises(TransactionError) as te: - p = h.Property( + p = db.Property( name="TestNoTypeProperty", datatype="Text").add_parent( id=-1) @@ -136,7 +136,7 @@ def test_insertion_with_invalid_parents(): def test_insertion_with_invalid_properties(): with pytest.raises(TransactionError) as te: - p = h.Property( + p = db.Property( name="TestNoTypeProperty", datatype="Text").add_property( id=-1) @@ -157,11 +157,11 @@ def test_entity_does_not_exist(): EntityDoesNotExistErrors. """ - p1 = h.Property(name="TestNon-ExistentProperty1").retrieve( + p1 = db.Property(name="TestNon-ExistentProperty1").retrieve( raise_exception_on_error=False) - p2 = h.Property(name="TestNon-ExistentProperty2").retrieve( + p2 = db.Property(name="TestNon-ExistentProperty2").retrieve( raise_exception_on_error=False) - p3 = h.Property(name="TestNon-ExistentProperty3").retrieve( + p3 = db.Property(name="TestNon-ExistentProperty3").retrieve( raise_exception_on_error=False) # None of them should exist assert not p1.is_valid() @@ -171,17 +171,17 @@ def test_entity_does_not_exist(): assert not p3.is_valid() assert (p3.id is None or p3.id < 0) - pe = h.Property(name="TestExistentProperty", datatype="text").insert() + pe = db.Property(name="TestExistentProperty", datatype="text").insert() - c = h.Container().extend( + c = db.Container().extend( [ - h.Property( + db.Property( name="TestNon-ExistentProperty1"), - h.Property( + db.Property( name="TestNon-ExistentProperty2"), - h.Property( + db.Property( name="TestNon-ExistentProperty3"), - h.Property( + db.Property( name="TestExistentProperty")]) with pytest.raises(TransactionError) as te: @@ -199,11 +199,11 @@ def test_insert_existent_entity(): UniqueNamesError. """ - p1 = h.Property(name="TestNon-ExistentProperty1").retrieve( + p1 = db.Property(name="TestNon-ExistentProperty1").retrieve( raise_exception_on_error=False) - p2 = h.Property(name="TestNon-ExistentProperty2").retrieve( + p2 = db.Property(name="TestNon-ExistentProperty2").retrieve( raise_exception_on_error=False) - p3 = h.Property(name="TestNon-ExistentProperty3").retrieve( + p3 = db.Property(name="TestNon-ExistentProperty3").retrieve( raise_exception_on_error=False) # None of them should exist assert not p1.is_valid() @@ -213,21 +213,21 @@ def test_insert_existent_entity(): assert not p3.is_valid() assert (p3.id is None or p3.id < 0) - pe = h.Property(name="TestExistentProperty", datatype="text").insert() + pe = db.Property(name="TestExistentProperty", datatype="text").insert() assert pe.is_valid() - c = h.Container().extend( + c = db.Container().extend( [ - h.Property( + db.Property( name="TestNon-ExistentProperty1", datatype="text"), - h.Property( + db.Property( name="TestNon-ExistentProperty2", datatype="text"), - h.Property( + db.Property( name="TestNon-ExistentProperty3", datatype="text"), - h.Property( + db.Property( name="TestExistentProperty", datatype="text")]) @@ -243,31 +243,31 @@ def test_insert_existent_entity(): def test_double_insertion(): - c1 = h.Container() + c1 = db.Container() c1.append( - h.Property( + db.Property( name="TestSimpleTextProperty", description="simple text property (from test_error_stuff.py)", datatype='text')) c1.append( - h.Property( + db.Property( name="TestSimpleDoubleProperty", description="simple double property (from test_error_stuff.py)", datatype='double')) c1.append( - h.Property( + db.Property( name="TestSimpleIntegerProperty", description="simple integer property (from test_error_stuff.py)", datatype='integer')) c1.append( - h.Property( + db.Property( name="TestSimpleDatetimeProperty", description="simple datetime property (from test_error_stuff.py)", datatype='datetime')) c1.append( - h.RecordType( + db.RecordType( name="TestSimpleRecordType", description="simple recordType (from test_error_stuff.py)").add_property( name='TestSimpleTextProperty').add_property( @@ -277,30 +277,30 @@ def test_double_insertion(): c1.insert() - c2 = h.Container() + c2 = db.Container() c2.append( - h.Property( + db.Property( name="TestSimpleTextProperty", description="simple text property (from test_error_stuff.py)", datatype='text')) c2.append( - h.Property( + db.Property( name="TestSimpleDoubleProperty", description="simple double property (from test_error_stuff.py)", datatype='double')) c2.append( - h.Property( + db.Property( name="TestSimpleIntegerProperty", description="simple integer property (from test_error_stuff.py)", datatype='integer')) c2.append( - h.Property( + db.Property( name="TestSimpleDatetimeProperty", description="simple datetime property (from test_error_stuff.py)", datatype='datetime')) c2.append( - h.RecordType( + db.RecordType( name="TestSimpleRecordType", description="simple recordType (from test_error_stuff.py)").add_property( name='TestSimpleTextProperty').add_property( @@ -322,7 +322,7 @@ def test_update_acl_errors(): `Entity.update_acl` """ - rec_ne = h.Record("TestRecordNonExisting") + rec_ne = db.Record("TestRecordNonExisting") with pytest.raises(TransactionError) as te: @@ -331,12 +331,36 @@ def test_update_acl_errors(): assert te.value.has_error(EntityDoesNotExistError) assert te.value.errors[0].entity.name == rec_ne.name - rt = h.RecordType(name="TestType").insert() - rec = h.Record(name="TestRecord").add_parent(rt).insert() - h.Record(name=rec.name).add_parent(rt).insert(unique=False) + rt = db.RecordType(name="TestType").insert() + rec = db.Record(name="TestRecord").add_parent(rt).insert() + db.Record(name=rec.name).add_parent(rt).insert(unique=False) with pytest.raises(TransactionError) as te: - h.Record(name=rec.name).update_acl() + db.Record(name=rec.name).update_acl() assert te.value.has_error(AmbiguousEntityError) + + +def test_URI_too_long(): + """Some tests for variours URI too long commands. + + See for example https://gitlab.indiscale.com/caosdb/src/caosdb-pylib/-/issues/180 + + """ + + short = 100 + uri_long = 819 + header_long = 815 + + with pytest.raises(db.TransactionError) as err: + db.execute_query("0123456789" * short) + assert "Parsing" in err.msg + + with pytest.raises(db.HTTPURITooLongError) as err: + db.execute_query("0123456789" * uri_long) + assert "414" in err.msg + + with pytest.raises(db.HTTPURITooLongError) as err: + db.execute_query("0123456789" * header_long) + assert "431" in err.msg