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

Merge branch 'dev' into f-exception-handling

parents 773ab364 e099aa98
Branches
Tags
No related merge requests found
...@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added (for new features) ### Added (for new features)
* Tests for deeply nested SELECT queries * Tests for deeply nested SELECT queries
- Tests for [#62](https://gitlab.com/caosdb/caosdb-server/-/issues/62) * Tests for [#62](https://gitlab.com/caosdb/caosdb-server/-/issues/62)
* Tests for One-time Authentication Tokens * Tests for One-time Authentication Tokens
* Test for [caosdb-pylib#31](https://gitlab.com/caosdb/caosdb-pylib/-/issues/31) * Test for [caosdb-pylib#31](https://gitlab.com/caosdb/caosdb-pylib/-/issues/31)
* Tests for [caosdb-server#62](https://gitlab.com/caosdb/caosdb-server/-/issues/62) * Tests for [caosdb-server#62](https://gitlab.com/caosdb/caosdb-server/-/issues/62)
...@@ -18,9 +18,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -18,9 +18,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed (for changes in existing functionality) ### Changed (for changes in existing functionality)
- Tests comply with the new entity error handling (see * Tests comply with the new entity error handling (see
[#32](https://gitlab.com/caosdb/caosdb-pylib/-/issues/32) in [#32](https://gitlab.com/caosdb/caosdb-pylib/-/issues/32) in
caosdb-pylib). caosdb-pylib).
* `test_recursive_parents.py` now tests inserted entities; set to
xfail until
[caosdb-pylib#34](https://gitlab.com/caosdb/caosdb-pylib/-/issues/34)
is fixed.
### Deprecated (for soon-to-be removed features) ### Deprecated (for soon-to-be removed features)
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2020 IndiScale GmbH <info@inidscale.com>
# Copyright (C) 2020 Florian Spreckelsen <f.spreckelsen@indiscale.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -22,11 +24,31 @@ ...@@ -22,11 +24,31 @@
# ** end header # ** end header
# #
"""Created on 2016-01-14. """Created on 2016-01-14.
Test if recursive parents are found correctly.
""" """
from nose.tools import (ok_, eq_) import caosdb as db
from caosdb.common.models import (Record, RecordType) import pytest
def setup_module():
"""Delete all test entities"""
db.execute_query("FIND Test*").delete(
raise_exception_on_error=False)
def setup():
"""No further setup required"""
setup_module()
def teardown():
"""Delete again"""
setup_module()
@pytest.mark.xfail(reason="To be fixed in server and/or pylib")
def test_recursive_parents(): def test_recursive_parents():
# inheritance structure: # inheritance structure:
# A # A
...@@ -36,36 +58,37 @@ def test_recursive_parents(): ...@@ -36,36 +58,37 @@ def test_recursive_parents():
# C # C
# | # |
# c # c
A = RecordType(name="A") A = db.RecordType(name="TestTypeA").insert()
B = RecordType(name="B").add_parent(A) B = db.RecordType(name="TestTypeB").add_parent(A).insert()
B2 = RecordType(name="B2").add_parent(A) B2 = db.RecordType(name="TestTypeB2").add_parent(A).insert()
C = RecordType(name="C").add_parent(B).add_parent(B2) C = db.RecordType(name="TestTypeC").add_parent(B).add_parent(B2).insert()
c = Record(name="c").add_parent(C) c = db.Record(name="TestRecord").add_parent(C).insert()
parents = C.get_parents_recursively() parents = C.get_parents_recursively()
eq_(len(parents), 3) assert len(parents) == 3
ok_(A in parents) assert A in parents
ok_(B in parents) assert B in parents
ok_(B2 in parents) assert B2 in parents
parents = c.get_parents_recursively() parents = c.get_parents_recursively()
eq_(len(parents), 4) assert len(parents) == 4
ok_(A in parents) assert A in parents
ok_(B in parents) assert B in parents
ok_(B2 in parents) assert B2 in parents
ok_(C in parents) assert C in parents
# Now do a time travel and great-grand-parentize yourself... # Now do a time travel and great-grand-parentize yourself...
A.add_parent(C) A.add_parent(C).update()
parents = C.get_parents_recursively() parents = C.get_parents_recursively()
eq_(len(parents), 4) assert len(parents) == 4
ok_(A in parents) assert A in parents
ok_(B in parents) assert B in parents
ok_(B2 in parents) assert B2 in parents
ok_(C in parents) assert C in parents
@pytest.mark.xfail(reason="To be fixed in server and/or pylib")
def test_entity_has_parent(): def test_entity_has_parent():
# inheritance structure: # inheritance structure:
# A # A
...@@ -75,48 +98,49 @@ def test_entity_has_parent(): ...@@ -75,48 +98,49 @@ def test_entity_has_parent():
# C # C
# | # |
# c # c
A = RecordType(name="A") A = db.RecordType(name="TestTypeA").insert()
B = RecordType(name="B").add_parent(A) B = db.RecordType(name="TestTypeB").add_parent(A).insert()
B2 = RecordType(name="B2", id=42).add_parent(A) B2 = db.RecordType(name="TestTypeB2").add_parent(A).insert()
C = RecordType(name="C").add_parent(B).add_parent(B2) C = db.RecordType(name="TestTypeC").add_parent(B).add_parent(B2).insert()
c = Record(name="c").add_parent(C) c = db.Record(name="TestRecord").add_parent(C).insert()
ok_(C.has_parent(B)) assert C.has_parent(B)
ok_(c.has_parent(B)) assert c.has_parent(B)
ok_(c.has_parent(A)) assert c.has_parent(A)
ok_(not C.has_parent(C)) assert not C.has_parent(C)
ok_(not A.has_parent(C)) assert not A.has_parent(C)
ok_(not B.has_parent(C)) assert not B.has_parent(C)
# Now do a time travel and great-grand-parentize yourself... # Now do a time travel and great-grand-parentize yourself...
A.add_parent(C) A.add_parent(C).update()
ok_(C.has_parent(C)) assert C.has_parent(C)
# Non-recursive tests # Non-recursive tests
ok_(C.has_parent(B, recursive=False)) assert C.has_parent(B, recursive=False)
ok_(not c.has_parent(B, recursive=False)) assert not c.has_parent(B, recursive=False)
ok_(not c.has_parent(A, recursive=False)) assert not c.has_parent(A, recursive=False)
ok_(not C.has_parent(C, recursive=False)) assert not C.has_parent(C, recursive=False)
# Works by name or ID # Works by name or ID
fake_B_name = RecordType(name="B") fake_B_name = db.RecordType(name="TestTypeB")
fake_C_name = RecordType(name="not C") fake_C_name = db.RecordType(name="not C")
ok_(c.has_parent(fake_B_name, check_name=True)) assert c.has_parent(fake_B_name, check_name=True)
ok_(not c.has_parent(fake_C_name, check_name=True)) assert not c.has_parent(fake_C_name, check_name=True)
fake_B_id = RecordType(id=42) fake_B_id = db.RecordType(id=B.id)
fake_C_id = RecordType(id=23) fake_C_id = db.RecordType(id=C.id*5)
ok_(c.has_parent(fake_B_id, check_name=False, check_id=True)) assert c.has_parent(fake_B_id, check_name=False, check_id=True)
ok_(not c.has_parent(fake_C_id, check_name=False, check_id=True)) assert not c.has_parent(fake_C_id, check_name=False,
check_id=True)
fake_B_name_id = RecordType(name="B", id=42) fake_B_name_id = RecordType(name="TestTypeB", id=B.id)
fake_C_name_id = RecordType(name="not C", id=23) fake_C_name_id = RecordType(name="not C", id=C.id*5)
ok_(c.has_parent(fake_B_name_id, assert c.has_parent(fake_B_name_id, check_name=True,
check_name=True, check_id=True)) check_id=True)
ok_(not c.has_parent(fake_C_name_id, assert not c.has_parent(fake_C_name_id, check_name=True,
check_name=True, check_id=True)) check_id=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment