diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index 81c57657..1b7cd724 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -72,6 +72,7 @@ class Sync: # We only want to perform Add/Remove to not new components actions = self.add_remove(db_device, not_new_components) db_device.components = db_components + self.change_parent_actions_components(db_device) return db_device, actions def execute_register_component(self, @@ -245,6 +246,13 @@ class Sync: actions.add(Remove(device=parent, components=set_components)) return actions + @staticmethod + def change_parent_actions_components(device: Computer): + # import pdb; pdb.set_trace() + for c in set(device.components): + for act in c.actions: + act.parent = device + class MismatchBetweenTags(ValidationError): def __init__(self, diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index df51eae2..775a3d5d 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -201,11 +201,13 @@ def test_snapshot_component_add_remove(user: UserClient): # PC1 assert tuple(c['serialNumber'] for c in pc1['components']) == ('p1c1s', 'p1c3s') assert all(c['parent'] == pc1_id for c in pc1['components']) - assert tuple(e['type'] for e in pc1['actions']) == ('BenchmarkProcessor', 'Snapshot', 'RateComputer', 'Remove') + assert tuple(e['type'] for e in pc1['actions']) == ('Snapshot', 'RateComputer', 'Remove') # PC2 assert tuple(c['serialNumber'] for c in pc2['components']) == ('p1c2s', 'p2c1s') assert all(c['parent'] == pc2_id for c in pc2['components']) - assert tuple(e['type'] for e in pc2['actions']) == ('Snapshot', 'RateComputer') + assert tuple(e['type'] for e in pc2['actions']) == ( + 'BenchmarkProcessor', 'Snapshot', 'RateComputer', 'Snapshot', 'Remove', 'RateComputer' + ) # p1c2s has two Snapshots, a Remove and an Add p1c2s, _ = user.get(res=m.Device, item=pc2['components'][0]['id']) assert tuple(e['type'] for e in p1c2s['actions']) == ( @@ -230,12 +232,16 @@ def test_snapshot_component_add_remove(user: UserClient): assert {c['serialNumber'] for c in pc1['components']} == {'p1c2s', 'p1c3s'} assert all(c['parent'] == pc1_id for c in pc1['components']) assert tuple(get_actions_info(pc1['actions'])) == ( - # id, type, components, snapshot - ('BenchmarkProcessor', []), # first BenchmarkProcessor - ('Snapshot', ['p1c1s', 'p1c2s', 'p1c3s']), # first Snapshot1 + ('BenchmarkProcessor', []), + ('Snapshot', ['p1c1s', 'p1c2s', 'p1c3s']), + ('Snapshot', ['p1c1s', 'p1c2s', 'p1c3s']), + ('RateComputer', ['p1c1s', 'p1c2s', 'p1c3s']), ('RateComputer', ['p1c1s', 'p1c2s', 'p1c3s']), - ('Remove', ['p1c2s']), # Remove Processor in Snapshot2 - ('Snapshot', ['p1c2s', 'p1c3s']), # This Snapshot3 + ('Snapshot', ['p1c2s', 'p2c1s']), + ('Remove', ['p1c2s']), ('Remove', ['p1c2s']), + ('RateComputer', ['p1c2s', 'p2c1s']), + ('Snapshot', ['p1c2s', 'p1c3s']), + ('Remove', ['p1c2s']), ('RateComputer', ['p1c2s', 'p1c3s']) ) # PC2 @@ -480,8 +486,9 @@ def test_test_data_storage(user: UserClient): assert incidence_test['severity'] == 'Error' +@pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) -def test_erase(user: UserClient): +def test_erase_changing_hdd_between_pcs(user: UserClient): """Tests when we erase one device and next change the disk in other device we want see in the second device the disks erase.""" s1 = file('erase-sectors-2-hdd.snapshot')