Skip to content
Snippets Groups Projects
Verified Commit 07c58b45 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

TEST: Test miscellaneous *-too-long errors.

parent aaef8fda
Branches
Tags
1 merge request!70Miscellaneous URI-too-long tests
Pipeline #44468 failed
...@@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -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 * Tests for [caosdb-pylib#90](https://gitlab.com/caosdb/caosdb-pylib/-/issues/90): `Entity.get_parents_recursively()` did not work for unretrieved
parents. parents.
* Test for [caosdb-server#192](https://gitlab.com/caosdb/caosdb-server/-/issues/192) * 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) ### Changed (for changes in existing functionality)
......
...@@ -30,7 +30,7 @@ Created on 19.02.2015. ...@@ -30,7 +30,7 @@ Created on 19.02.2015.
@author: tf @author: tf
""" """
import caosdb as h import linkahead as db
from caosdb.exceptions import (AmbiguousEntityError, from caosdb.exceptions import (AmbiguousEntityError,
EntityDoesNotExistError, EntityError, EntityDoesNotExistError, EntityError,
EntityHasNoDatatypeError, EntityHasNoDatatypeError,
...@@ -42,7 +42,7 @@ import pytest ...@@ -42,7 +42,7 @@ import pytest
def setup_function(function): def setup_function(function):
try: try:
h.execute_query("FIND ENTITY").delete() db.execute_query("FIND ENTITY").delete()
except BaseException: except BaseException:
pass pass
...@@ -54,7 +54,7 @@ def teardown_function(function): ...@@ -54,7 +54,7 @@ def teardown_function(function):
def test_retrieval_no_exception_raised(): def test_retrieval_no_exception_raised():
"""Test whether retrieval fails but error is suppressed.""" """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) unique=True, raise_exception_on_error=False)
assert not p.is_valid() assert not p.is_valid()
assert (p.id is None or p.id < 0) assert (p.id is None or p.id < 0)
...@@ -67,7 +67,7 @@ def test_retrieval_exception_raised(): ...@@ -67,7 +67,7 @@ def test_retrieval_exception_raised():
""" """
propname = "TestNon-ExistentProperty" propname = "TestNon-ExistentProperty"
with pytest.raises(TransactionError) as te: with pytest.raises(TransactionError) as te:
h.Property(name="TestNon-ExistentProperty").retrieve(unique=True, db.Property(name="TestNon-ExistentProperty").retrieve(unique=True,
raise_exception_on_error=True) raise_exception_on_error=True)
assert len(te.value.errors) == 1 assert len(te.value.errors) == 1
ee = te.value.errors[0] ee = te.value.errors[0]
...@@ -89,19 +89,19 @@ def test_ambiguous_retrieval(): ...@@ -89,19 +89,19 @@ def test_ambiguous_retrieval():
raised correctly if there are two possible candidates. raised correctly if there are two possible candidates.
""" """
h.RecordType(name="TestType").insert() db.RecordType(name="TestType").insert()
h.Record(name="TestRec").add_parent(name="TestType").insert() db.Record(name="TestRec").add_parent(name="TestType").insert()
# Insert twice, so unique=False # 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: 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.has_error(AmbiguousEntityError)
assert te.value.errors[0].entity.name == "TestRec" assert te.value.errors[0].entity.name == "TestRec"
def test_insertion_no_exception_raised(): def test_insertion_no_exception_raised():
"""Test whether insertion fails but no error is 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) raise_exception_on_error=False)
assert not p.is_valid() assert not p.is_valid()
assert (p.id is None or p.id < 0) assert (p.id is None or p.id < 0)
...@@ -109,7 +109,7 @@ def test_insertion_no_exception_raised(): ...@@ -109,7 +109,7 @@ def test_insertion_no_exception_raised():
def test_insertion_exception_raised(): def test_insertion_exception_raised():
"""Test insertion of a property with missing datatype.""" """Test insertion of a property with missing datatype."""
p = h.Property(name="TestNoTypeProperty") p = db.Property(name="TestNoTypeProperty")
with pytest.raises(TransactionError) as te: with pytest.raises(TransactionError) as te:
p.insert(raise_exception_on_error=True) p.insert(raise_exception_on_error=True)
assert te.value.has_error(EntityHasNoDatatypeError) assert te.value.has_error(EntityHasNoDatatypeError)
...@@ -117,7 +117,7 @@ def test_insertion_exception_raised(): ...@@ -117,7 +117,7 @@ def test_insertion_exception_raised():
def test_insertion_with_invalid_parents(): def test_insertion_with_invalid_parents():
with pytest.raises(TransactionError) as te: with pytest.raises(TransactionError) as te:
p = h.Property( p = db.Property(
name="TestNoTypeProperty", name="TestNoTypeProperty",
datatype="Text").add_parent( datatype="Text").add_parent(
id=-1) id=-1)
...@@ -136,7 +136,7 @@ def test_insertion_with_invalid_parents(): ...@@ -136,7 +136,7 @@ def test_insertion_with_invalid_parents():
def test_insertion_with_invalid_properties(): def test_insertion_with_invalid_properties():
with pytest.raises(TransactionError) as te: with pytest.raises(TransactionError) as te:
p = h.Property( p = db.Property(
name="TestNoTypeProperty", name="TestNoTypeProperty",
datatype="Text").add_property( datatype="Text").add_property(
id=-1) id=-1)
...@@ -157,11 +157,11 @@ def test_entity_does_not_exist(): ...@@ -157,11 +157,11 @@ def test_entity_does_not_exist():
EntityDoesNotExistErrors. EntityDoesNotExistErrors.
""" """
p1 = h.Property(name="TestNon-ExistentProperty1").retrieve( p1 = db.Property(name="TestNon-ExistentProperty1").retrieve(
raise_exception_on_error=False) raise_exception_on_error=False)
p2 = h.Property(name="TestNon-ExistentProperty2").retrieve( p2 = db.Property(name="TestNon-ExistentProperty2").retrieve(
raise_exception_on_error=False) raise_exception_on_error=False)
p3 = h.Property(name="TestNon-ExistentProperty3").retrieve( p3 = db.Property(name="TestNon-ExistentProperty3").retrieve(
raise_exception_on_error=False) raise_exception_on_error=False)
# None of them should exist # None of them should exist
assert not p1.is_valid() assert not p1.is_valid()
...@@ -171,17 +171,17 @@ def test_entity_does_not_exist(): ...@@ -171,17 +171,17 @@ def test_entity_does_not_exist():
assert not p3.is_valid() assert not p3.is_valid()
assert (p3.id is None or p3.id < 0) 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"), name="TestNon-ExistentProperty1"),
h.Property( db.Property(
name="TestNon-ExistentProperty2"), name="TestNon-ExistentProperty2"),
h.Property( db.Property(
name="TestNon-ExistentProperty3"), name="TestNon-ExistentProperty3"),
h.Property( db.Property(
name="TestExistentProperty")]) name="TestExistentProperty")])
with pytest.raises(TransactionError) as te: with pytest.raises(TransactionError) as te:
...@@ -199,11 +199,11 @@ def test_insert_existent_entity(): ...@@ -199,11 +199,11 @@ def test_insert_existent_entity():
UniqueNamesError. UniqueNamesError.
""" """
p1 = h.Property(name="TestNon-ExistentProperty1").retrieve( p1 = db.Property(name="TestNon-ExistentProperty1").retrieve(
raise_exception_on_error=False) raise_exception_on_error=False)
p2 = h.Property(name="TestNon-ExistentProperty2").retrieve( p2 = db.Property(name="TestNon-ExistentProperty2").retrieve(
raise_exception_on_error=False) raise_exception_on_error=False)
p3 = h.Property(name="TestNon-ExistentProperty3").retrieve( p3 = db.Property(name="TestNon-ExistentProperty3").retrieve(
raise_exception_on_error=False) raise_exception_on_error=False)
# None of them should exist # None of them should exist
assert not p1.is_valid() assert not p1.is_valid()
...@@ -213,21 +213,21 @@ def test_insert_existent_entity(): ...@@ -213,21 +213,21 @@ def test_insert_existent_entity():
assert not p3.is_valid() assert not p3.is_valid()
assert (p3.id is None or p3.id < 0) 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() assert pe.is_valid()
c = h.Container().extend( c = db.Container().extend(
[ [
h.Property( db.Property(
name="TestNon-ExistentProperty1", name="TestNon-ExistentProperty1",
datatype="text"), datatype="text"),
h.Property( db.Property(
name="TestNon-ExistentProperty2", name="TestNon-ExistentProperty2",
datatype="text"), datatype="text"),
h.Property( db.Property(
name="TestNon-ExistentProperty3", name="TestNon-ExistentProperty3",
datatype="text"), datatype="text"),
h.Property( db.Property(
name="TestExistentProperty", name="TestExistentProperty",
datatype="text")]) datatype="text")])
...@@ -243,31 +243,31 @@ def test_insert_existent_entity(): ...@@ -243,31 +243,31 @@ def test_insert_existent_entity():
def test_double_insertion(): def test_double_insertion():
c1 = h.Container() c1 = db.Container()
c1.append( c1.append(
h.Property( db.Property(
name="TestSimpleTextProperty", name="TestSimpleTextProperty",
description="simple text property (from test_error_stuff.py)", description="simple text property (from test_error_stuff.py)",
datatype='text')) datatype='text'))
c1.append( c1.append(
h.Property( db.Property(
name="TestSimpleDoubleProperty", name="TestSimpleDoubleProperty",
description="simple double property (from test_error_stuff.py)", description="simple double property (from test_error_stuff.py)",
datatype='double')) datatype='double'))
c1.append( c1.append(
h.Property( db.Property(
name="TestSimpleIntegerProperty", name="TestSimpleIntegerProperty",
description="simple integer property (from test_error_stuff.py)", description="simple integer property (from test_error_stuff.py)",
datatype='integer')) datatype='integer'))
c1.append( c1.append(
h.Property( db.Property(
name="TestSimpleDatetimeProperty", name="TestSimpleDatetimeProperty",
description="simple datetime property (from test_error_stuff.py)", description="simple datetime property (from test_error_stuff.py)",
datatype='datetime')) datatype='datetime'))
c1.append( c1.append(
h.RecordType( db.RecordType(
name="TestSimpleRecordType", name="TestSimpleRecordType",
description="simple recordType (from test_error_stuff.py)").add_property( description="simple recordType (from test_error_stuff.py)").add_property(
name='TestSimpleTextProperty').add_property( name='TestSimpleTextProperty').add_property(
...@@ -277,30 +277,30 @@ def test_double_insertion(): ...@@ -277,30 +277,30 @@ def test_double_insertion():
c1.insert() c1.insert()
c2 = h.Container() c2 = db.Container()
c2.append( c2.append(
h.Property( db.Property(
name="TestSimpleTextProperty", name="TestSimpleTextProperty",
description="simple text property (from test_error_stuff.py)", description="simple text property (from test_error_stuff.py)",
datatype='text')) datatype='text'))
c2.append( c2.append(
h.Property( db.Property(
name="TestSimpleDoubleProperty", name="TestSimpleDoubleProperty",
description="simple double property (from test_error_stuff.py)", description="simple double property (from test_error_stuff.py)",
datatype='double')) datatype='double'))
c2.append( c2.append(
h.Property( db.Property(
name="TestSimpleIntegerProperty", name="TestSimpleIntegerProperty",
description="simple integer property (from test_error_stuff.py)", description="simple integer property (from test_error_stuff.py)",
datatype='integer')) datatype='integer'))
c2.append( c2.append(
h.Property( db.Property(
name="TestSimpleDatetimeProperty", name="TestSimpleDatetimeProperty",
description="simple datetime property (from test_error_stuff.py)", description="simple datetime property (from test_error_stuff.py)",
datatype='datetime')) datatype='datetime'))
c2.append( c2.append(
h.RecordType( db.RecordType(
name="TestSimpleRecordType", name="TestSimpleRecordType",
description="simple recordType (from test_error_stuff.py)").add_property( description="simple recordType (from test_error_stuff.py)").add_property(
name='TestSimpleTextProperty').add_property( name='TestSimpleTextProperty').add_property(
...@@ -322,7 +322,7 @@ def test_update_acl_errors(): ...@@ -322,7 +322,7 @@ def test_update_acl_errors():
`Entity.update_acl` `Entity.update_acl`
""" """
rec_ne = h.Record("TestRecordNonExisting") rec_ne = db.Record("TestRecordNonExisting")
with pytest.raises(TransactionError) as te: with pytest.raises(TransactionError) as te:
...@@ -331,12 +331,36 @@ def test_update_acl_errors(): ...@@ -331,12 +331,36 @@ def test_update_acl_errors():
assert te.value.has_error(EntityDoesNotExistError) assert te.value.has_error(EntityDoesNotExistError)
assert te.value.errors[0].entity.name == rec_ne.name assert te.value.errors[0].entity.name == rec_ne.name
rt = h.RecordType(name="TestType").insert() rt = db.RecordType(name="TestType").insert()
rec = h.Record(name="TestRecord").add_parent(rt).insert() rec = db.Record(name="TestRecord").add_parent(rt).insert()
h.Record(name=rec.name).add_parent(rt).insert(unique=False) db.Record(name=rec.name).add_parent(rt).insert(unique=False)
with pytest.raises(TransactionError) as te: 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) 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment