Skip to content
Snippets Groups Projects
Commit 7f99c55f authored by Daniel Hornung's avatar Daniel Hornung
Browse files

Merge branch 'f-get-parents-recursively' into 'dev'

Get parents recursively

See merge request !54
parents 6ed0398a 91d86775
No related branches found
No related tags found
1 merge request!54Get parents recursively
Pipeline #33992 passed
...@@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Test for [caosdb-server#136](https://gitlab.com/caosdb/caosdb-server/-/issues/136) * Test for [caosdb-server#136](https://gitlab.com/caosdb/caosdb-server/-/issues/136)
* Test for [caosdb-server#141](https://gitlab.com/caosdb/caosdb-server/-/issues/141) * Test for [caosdb-server#141](https://gitlab.com/caosdb/caosdb-server/-/issues/141)
* Test for [caosdb-server#145](https://gitlab.com/caosdb/caosdb-server/-/issues/145) * Test for [caosdb-server#145](https://gitlab.com/caosdb/caosdb-server/-/issues/145)
* Tests for [caosdb-pylib#90](https://gitlab.com/caosdb/caosdb-pylib/-/issues/90): `Entity.get_parents_recursively()` did not work for unretrieved
parents.
### Changed (for changes in existing functionality) ### Changed (for changes in existing functionality)
......
...@@ -18,7 +18,9 @@ CaosDB project. ...@@ -18,7 +18,9 @@ CaosDB project.
- Server-side scripting paths must be given, otherwise server-side scripting will be omitted. - Server-side scripting paths must be given, otherwise server-side scripting will be omitted.
- Run the tests with `pytest` or `pytest-3` (depending on your system). - Run the tests with `pytest` or `pytest-3` (depending on your system).
- If you want to run just a single test, you can also select a single test file: - If you want to run just a single test, you can also select a single test file:
`pytest-3 tests/test_issues.py` `pytest-3 tests/test_issues.py`
or a test matching a regular expression:
`pytest-3 tests/test_issues.py -k issue_123`
## Requirements ## ## Requirements ##
......
...@@ -48,7 +48,26 @@ def teardown_function(function): ...@@ -48,7 +48,26 @@ def teardown_function(function):
setup_module() setup_module()
@pytest.mark.xfail(reason="To be fixed in server and/or pylib") def test_get_parents_recursively():
"""Test for https://gitlab.com/caosdb/caosdb-pylib/-/issues/90
> Entity.get_parents_recursively() does not work unless the full ancestry has been retrieved from
> the server.
"""
# Setup
rt_A = db.RecordType(name="TestA")
rt_B = db.RecordType(name="TestB").add_parent(rt_A)
rt_C = db.RecordType(name="TestC").add_parent(rt_B)
db.Container().extend([rt_A, rt_B, rt_C]).insert()
# Retrieve only C
retrieved_C = db.RecordType(name="TestC").retrieve()
parents = retrieved_C.get_parents_recursively(retrieve=True)
assert len(parents) == 2
assert "TestB" in [p.name for p in parents]
assert "TestA" in [p.name for p in parents]
def test_recursive_parents(): def test_recursive_parents():
# inheritance structure: # inheritance structure:
# A # A
...@@ -66,29 +85,31 @@ def test_recursive_parents(): ...@@ -66,29 +85,31 @@ def test_recursive_parents():
parents = C.get_parents_recursively() parents = C.get_parents_recursively()
assert len(parents) == 3 assert len(parents) == 3
assert A in parents parent_identifiers = [(all_p.id, all_p.name) for all_p in parents]
assert B in parents assert (A.id, A.name) in parent_identifiers
assert B2 in parents assert (B.id, B.name) in parent_identifiers
assert (B2.id, B2.name) in parent_identifiers
parents = c.get_parents_recursively() parents = c.get_parents_recursively()
assert len(parents) == 4 assert len(parents) == 4
assert A in parents parent_identifiers = [(all_p.id, all_p.name) for all_p in parents]
assert B in parents assert (A.id, A.name) in parent_identifiers
assert B2 in parents assert (B.id, B.name) in parent_identifiers
assert C in parents assert (B2.id, B2.name) in parent_identifiers
assert (C.id, C.name) in parent_identifiers
# Now do a time travel and great-grand-parentize yourself... # Now do a time travel and great-grand-parentize yourself...
A.add_parent(C).update() A.add_parent(C).update()
parents = C.get_parents_recursively() parents = C.get_parents_recursively()
assert len(parents) == 4 assert len(parents) == 4
assert A in parents parent_identifiers = [(all_p.id, all_p.name) for all_p in parents]
assert B in parents assert (A.id, A.name) in parent_identifiers
assert B2 in parents assert (B.id, B.name) in parent_identifiers
assert C in parents assert (B2.id, B2.name) in parent_identifiers
assert (C.id, C.name) in parent_identifiers
@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
...@@ -137,8 +158,8 @@ def test_entity_has_parent(): ...@@ -137,8 +158,8 @@ def test_entity_has_parent():
assert not c.has_parent(fake_C_id, check_name=False, assert not c.has_parent(fake_C_id, check_name=False,
check_id=True) check_id=True)
fake_B_name_id = RecordType(name="TestTypeB", id=B.id) fake_B_name_id = db.RecordType(name="TestTypeB", id=B.id)
fake_C_name_id = RecordType(name="not C", id=C.id * 5) fake_C_name_id = db.RecordType(name="not C", id=C.id * 5)
assert c.has_parent(fake_B_name_id, check_name=True, assert c.has_parent(fake_B_name_id, 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