Skip to content
Snippets Groups Projects
Commit 88c72db6 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

FIX: copy attributes now working

parent 65fe289f
Branches
Tags
1 merge request!53Release 0.1
...@@ -38,7 +38,7 @@ from .converters import Converter, DirectoryConverter ...@@ -38,7 +38,7 @@ from .converters import Converter, DirectoryConverter
from .identifiable_adapters import IdentifiableAdapter, LocalStorageIdentifiableAdapter from .identifiable_adapters import IdentifiableAdapter, LocalStorageIdentifiableAdapter
from collections import defaultdict from collections import defaultdict
from typing import Union, Any, Optional from typing import Union, Any, Optional
from caosdb.apiutils import compare_entities from caosdb.apiutils import compare_entities, merge_entities
from copy import deepcopy from copy import deepcopy
from jsonschema import validate from jsonschema import validate
...@@ -337,12 +337,8 @@ class Crawler(object): ...@@ -337,12 +337,8 @@ class Crawler(object):
""" """
Copy all attributes from one entity to another entity. Copy all attributes from one entity to another entity.
""" """
# add missing parents:
for parent in fro.parents: merge_entities(to, fro)
if to.get_parent(parent.name) is None:
to.add_parent(parent)
# TODO: unfinished
raise NotImplementedError()
def split_into_inserts_and_updates(self, ent_list: list[db.Entity]): def split_into_inserts_and_updates(self, ent_list: list[db.Entity]):
if self.identifiableAdapter is None: if self.identifiableAdapter is None:
...@@ -377,8 +373,7 @@ class Crawler(object): ...@@ -377,8 +373,7 @@ class Crawler(object):
# information # information
# Update an (local) identified record that will be inserted # Update an (local) identified record that will be inserted
newrecord = self.get_identified_record_from_local_cache(record) newrecord = self.get_identified_record_from_local_cache(record)
# breakpoint() self.copy_attributes(fro=record, to=newrecord)
# self.copy_attributes(fro=record, to=newrecord)
# Bend references to the other object # Bend references to the other object
# TODO refactor this # TODO refactor this
for el in flat + to_be_inserted + to_be_updated: for el in flat + to_be_inserted + to_be_updated:
......
...@@ -173,7 +173,6 @@ def test_ambigious_records(crawler, ident): ...@@ -173,7 +173,6 @@ def test_ambigious_records(crawler, ident):
def test_crawler_update_list(crawler, ident): def test_crawler_update_list(crawler, ident):
crawler.copy_attributes = Mock()
# If the following assertions fail, that is a hint, that the test file records.xml has changed # If the following assertions fail, that is a hint, that the test file records.xml has changed
# and this needs to be updated: # and this needs to be updated:
assert len(ident.get_records()) == 18 assert len(ident.get_records()) == 18
...@@ -334,8 +333,6 @@ def mock_retrieve(crawler): ...@@ -334,8 +333,6 @@ def mock_retrieve(crawler):
else: else:
return None return None
crawler.copy_attributes = Mock()
# a record that is found remotely and should be added to the update list and one that is not # a record that is found remotely and should be added to the update list and one that is not
# found and should be added to the insert one # found and should be added to the insert one
remote_known = {"A": db.Record(id=1111, name="A")} remote_known = {"A": db.Record(id=1111, name="A")}
...@@ -432,7 +429,6 @@ def test_split_into_inserts_and_updates_with_complex(mock_retrieve): ...@@ -432,7 +429,6 @@ def test_split_into_inserts_and_updates_with_complex(mock_retrieve):
# TODO write test where the unresoled entity is not part of the identifiable # TODO write test where the unresoled entity is not part of the identifiable
@pytest.mark.xfail
def test_split_into_inserts_and_updates_with_copy_attr(mock_retrieve): def test_split_into_inserts_and_updates_with_copy_attr(mock_retrieve):
crawler = mock_retrieve crawler = mock_retrieve
# assume identifiable is only the name # assume identifiable is only the name
...@@ -443,7 +439,6 @@ def test_split_into_inserts_and_updates_with_copy_attr(mock_retrieve): ...@@ -443,7 +439,6 @@ def test_split_into_inserts_and_updates_with_copy_attr(mock_retrieve):
entlist = [a, b] entlist = [a, b]
insert, update = crawler.split_into_inserts_and_updates(entlist) insert, update = crawler.split_into_inserts_and_updates(entlist)
# expected TODO
assert update[0].get_property("bar").value == 2 assert update[0].get_property("bar").value == 2
assert update[0].get_property("foo").value == 1 assert update[0].get_property("foo").value == 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment