Skip to content

Commit

Permalink
Change merge_platforms calls with merge_generic
Browse files Browse the repository at this point in the history
  • Loading branch information
BarisSari committed Feb 17, 2021
1 parent 7491910 commit 8cdb3c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pepys_import/core/store/data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,7 @@ def merge_generic(self, table_name, id_list, master_id) -> bool:

table = table_name_to_class_name(table_name)
table_obj = getattr(self.db_classes, table)
if not isinstance(id_list[0], uuid.UUID):
if id_list and not isinstance(id_list[0], uuid.UUID):
id_list = [getattr(i, get_primary_key_for_table(table_obj)) for i in id_list]

if not isinstance(master_id, uuid.UUID):
Expand Down
14 changes: 7 additions & 7 deletions tests/test_data_store_merge_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def test_merge_platforms_with_same_sensor_names(self):
assert len(states_before_merge) == 0
assert len(contacts_before_merge) == 0

self.store.merge_platforms(
[platform_2.platform_id], platform.platform_id, self.change_id
self.store.merge_generic(
constants.PLATFORM, [platform_2.platform_id], platform.platform_id
)

# There should be still one sensor, but that sensor should have two States and two Contacts
Expand Down Expand Up @@ -218,8 +218,8 @@ def test_merge_platforms_with_different_sensor_names(self):
assert len(states_before_merge) == 0
assert len(contacts_before_merge) == 0

self.store.merge_platforms(
[platform_2.platform_id], platform.platform_id, self.change_id
self.store.merge_generic(
constants.PLATFORM, [platform_2.platform_id], platform.platform_id
)

# There should be two sensors now, and new sensor should have two States and two Contacts
Expand Down Expand Up @@ -313,10 +313,10 @@ def test_merge_platforms_with_only_comments(self):
)
assert len(comments_before_merge) == 1

self.store.merge_platforms(
self.store.merge_generic(
constants.PLATFORM,
[platform_2.platform_id, platform_3.platform_id],
platform.platform_id,
self.change_id,
)

# There should be two Comments in the target platform
Expand Down Expand Up @@ -350,7 +350,7 @@ def test_merge_platforms_with_only_comments(self):
def test_merge_platforms_invalid_master_platform(self):
uuid = UUID("12345678123456781234567812345678")
with self.store.session_scope(), pytest.raises(ValueError) as error:
self.store.merge_platforms([], uuid, uuid)
self.store.merge_generic(constants.PLATFORM, [], uuid)
assert f"No object found with the given master_id: '{uuid}'" in error.value.args[0]

def test_merge_platforms_with_platform_objects_given(self):
Expand Down

0 comments on commit 8cdb3c5

Please sign in to comment.