From 9736ee323a71da4a8bad789df0b38c97b9bacbe7 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 12 Dec 2022 14:20:07 +0100 Subject: [PATCH] test settings version --- tests/test_snapshot.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 9e408f26..40614ce3 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -1413,3 +1413,36 @@ def test_bug_4028_components(user: UserClient): for c in m.Device.query.filter(): assert c.binding or c.placeholder + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_settings_version(user: UserClient): + """Tests when we have one computer and then we change the disk, then + the new disk need to have placeholder too.""" + s = yaml2json('real-eee-1001pxd.snapshot.12') + s['settings_version']= 'Basic Metadata (BM)' + snap1, _ = user.post(s, res=Snapshot) + dev1 = m.Device.query.filter_by(id=snap1['device']['id']).one() + assert m.Placeholder.query.count() * 2 == m.Device.query.count() + components1 = [c for c in dev1.components] + for c in s['components']: + if c['type'] == 'HardDrive': + c['serialNumber'] = 'E2024242CV86MF' + + s['uuid'] = str(uuid4()) + snap2, _ = user.post(s, res=Snapshot) + dev2 = m.Device.query.filter_by(id=snap2['device']['id']).one() + components2 = [c for c in dev2.components] + + assert '' not in [c.phid() for c in components1] + assert '' not in [c.phid() for c in components2] + assert len(components1) == len(components2) + assert m.Placeholder.query.count() == 16 + assert m.Placeholder.query.count() * 2 == m.Device.query.count() + for c in m.Placeholder.query.filter(): + assert c.binding + assert c.device + + for c in m.Device.query.filter(): + assert c.binding or c.placeholder