From 150c73779db1b8d4a82ba6ad3fa69aef4d89267f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 14 Oct 2020 11:40:33 +0200 Subject: [PATCH] adding new tests of snapshots --- .../failed.snapshot.422.missing-chassis.yaml | 36 +++++++ .../failed.snapshot.422.null-chassis.yaml | 36 +++++++ ...ed.snapshot.500.missing-cpu-benchmark.yaml | 22 +++++ ...ed.snapshot.500.missing-hdd-benchmark.yaml | 31 ++++++ tests/test_snapshot.py | 98 +++++++++++++++++++ 5 files changed, 223 insertions(+) create mode 100644 tests/files/failed.snapshot.422.missing-chassis.yaml create mode 100644 tests/files/failed.snapshot.422.null-chassis.yaml create mode 100644 tests/files/failed.snapshot.500.missing-cpu-benchmark.yaml create mode 100644 tests/files/failed.snapshot.500.missing-hdd-benchmark.yaml diff --git a/tests/files/failed.snapshot.422.missing-chassis.yaml b/tests/files/failed.snapshot.422.missing-chassis.yaml new file mode 100644 index 00000000..1d78da4a --- /dev/null +++ b/tests/files/failed.snapshot.422.missing-chassis.yaml @@ -0,0 +1,36 @@ +type: Snapshot +uuid: 62b3e393-0c25-42cf-a5fa-ab796fac76dd +version: 11.0 +software: Workbench +elapsed: 4 +device: + type: Laptop + chassis: Notebook + serialNumber: d6s + model: d6ml + manufacturer: d6mr +components: + - type: RamModule + serialNumber: rm6s + model: rm6ml + manufacturer: rm6mr + speed: 1333 + - type: Processor + serialNumber: p6s + model: p6ml + manufacturer: p6mr + speed: 1.6 + actions: + - type: BenchmarkProcessor + rate: 2410 + elapsed: 11 + - type: HardDrive + size: 160041.88569599998 + model: hdd4m + manufacturer: hdd4mr + serialNumber: hdd4s + actions: + - type: BenchmarkDataStorage + elapsed: 22 + writeSpeed: 17.3 + readSpeed: 41.6 diff --git a/tests/files/failed.snapshot.422.null-chassis.yaml b/tests/files/failed.snapshot.422.null-chassis.yaml new file mode 100644 index 00000000..0cf56bb7 --- /dev/null +++ b/tests/files/failed.snapshot.422.null-chassis.yaml @@ -0,0 +1,36 @@ +type: Snapshot +uuid: 81e1f340-5aac-4619-931b-d312e4866cb7 +version: 11.0 +software: Workbench +elapsed: 4 +device: + type: Laptop + chassis: null + serialNumber: d5s + model: d5ml + manufacturer: d5mr +components: + - type: RamModule + serialNumber: rm5s + model: rm5ml + manufacturer: rm5mr + speed: 1333 + type: Processor + serialNumber: p5s + model: p5ml + manufacturer: p5mr + speed: 1.6 + actions: + - type: BenchmarkProcessor + rate: 2410 + elapsed: 11 + size: 160041.88569599998 + model: hdd5m + type: HardDrive + manufacturer: hdd5mr + serialNumber: hdd5s + actions: + - type: BenchmarkDataStorage + elapsed: 22 + writeSpeed: 17.3 + readSpeed: 41.6 diff --git a/tests/files/failed.snapshot.500.missing-cpu-benchmark.yaml b/tests/files/failed.snapshot.500.missing-cpu-benchmark.yaml new file mode 100644 index 00000000..2a5496ae --- /dev/null +++ b/tests/files/failed.snapshot.500.missing-cpu-benchmark.yaml @@ -0,0 +1,22 @@ +type: Snapshot +uuid: 127fad1c-a3f2-4677-9dab-4a370071a882 +version: 11.0 +software: Workbench +elapsed: 4 +device: + type: Laptop + chassis: Microtower + serialNumber: d2s + model: d2ml + manufacturer: d2mr +components: + - type: RamModule + serialNumber: rm2s + model: rm2ml + manufacturer: rm2mr + speed: 1333 + - type: Processor + serialNumber: p2s + model: p2ml + manufacturer: p2mr + speed: 1.6 diff --git a/tests/files/failed.snapshot.500.missing-hdd-benchmark.yaml b/tests/files/failed.snapshot.500.missing-hdd-benchmark.yaml new file mode 100644 index 00000000..19269d33 --- /dev/null +++ b/tests/files/failed.snapshot.500.missing-hdd-benchmark.yaml @@ -0,0 +1,31 @@ +type: Snapshot +uuid: 2afa5413-9858-4577-8273-a027a647fed0 +version: 11.0 +software: Workbench +elapsed: 4 +device: + type: Desktop + chassis: Microtower + serialNumber: d3s + model: d3ml + manufacturer: d3mr +components: + - type: RamModule + serialNumber: rm3s + model: rm3ml + manufacturer: rm3mr + speed: 1333 + - type: Processor + serialNumber: p3s + model: p3ml + manufacturer: p3mr + speed: 1.6 + size: 160041.88569599998 + model: hdd3m + type: HardDrive + manufacturer: hdd3mr + serialNumber: hdd3s + actions: + - type: BenchmarkProcessor + rate: 2410 + elapsed: 11 diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 7b328d04..94f9f3e2 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -525,3 +525,101 @@ def test_backup_snapshot_with_errors(app: Devicehub, user: UserClient): assert snapshot['software'] == snapshot_no_hid['software'] assert snapshot['version'] == snapshot_no_hid['version'] assert snapshot['uuid'] == uuid + + +@pytest.mark.mvp +def test_snapshot_failed_missing_cpu_benchmark(app: Devicehub, user: UserClient): + """ This test check if the file snapshot is create when some snapshot is wrong """ + tmp_snapshots = app.config['TMP_SNAPSHOTS'] + snapshot_error = file('failed.snapshot.500.missing-cpu-benchmark') + uuid = snapshot_error['uuid'] + + snapshot = {'software': '', 'version': '', 'uuid': ''} + with pytest.raises(TypeError): + user.post(res=Snapshot, data=snapshot_error) + + files = [x for x in os.listdir(tmp_snapshots) if uuid in x] + if files: + path_snapshot = os.path.join(tmp_snapshots, files[0]) + with open(path_snapshot) as file_snapshot: + snapshot = json.loads(file_snapshot.read()) + + os.remove(path_snapshot) + + assert snapshot['software'] == snapshot_error['software'] + assert snapshot['version'] == snapshot_error['version'] + assert snapshot['uuid'] == uuid + + +@pytest.mark.mvp +def test_snapshot_failed_missing_hdd_benchmark(app: Devicehub, user: UserClient): + """ This test check if the file snapshot is create when some snapshot is wrong """ + tmp_snapshots = app.config['TMP_SNAPSHOTS'] + snapshot_error = file('failed.snapshot.500.missing-hdd-benchmark') + uuid = snapshot_error['uuid'] + + snapshot = {'software': '', 'version': '', 'uuid': ''} + with pytest.raises(TypeError): + user.post(res=Snapshot, data=snapshot_error) + + files = [x for x in os.listdir(tmp_snapshots) if uuid in x] + if files: + path_snapshot = os.path.join(tmp_snapshots, files[0]) + with open(path_snapshot) as file_snapshot: + snapshot = json.loads(file_snapshot.read()) + + os.remove(path_snapshot) + + assert snapshot['software'] == snapshot_error['software'] + assert snapshot['version'] == snapshot_error['version'] + assert snapshot['uuid'] == uuid + + +@pytest.mark.mvp +def test_snapshot_failed_null_chassis(app: Devicehub, user: UserClient): + """ This test check if the file snapshot is create when some snapshot is wrong """ + tmp_snapshots = app.config['TMP_SNAPSHOTS'] + snapshot_error = file('failed.snapshot.422.null-chassis') + uuid = snapshot_error['uuid'] + + snapshot = {'software': '', 'version': '', 'uuid': ''} + # import pdb; pdb.set_trace() + with pytest.raises(TypeError): + user.post(res=Snapshot, data=snapshot_error) + + files = [x for x in os.listdir(tmp_snapshots) if uuid in x] + if files: + path_snapshot = os.path.join(tmp_snapshots, files[0]) + with open(path_snapshot) as file_snapshot: + snapshot = json.loads(file_snapshot.read()) + + os.remove(path_snapshot) + + assert snapshot['software'] == snapshot_error['software'] + assert snapshot['version'] == snapshot_error['version'] + assert snapshot['uuid'] == uuid + + +@pytest.mark.mvp +def test_snapshot_failed_missing_chassis(app: Devicehub, user: UserClient): + """ This test check if the file snapshot is create when some snapshot is wrong """ + tmp_snapshots = app.config['TMP_SNAPSHOTS'] + snapshot_error = file('failed.snapshot.422.missing-chassis') + uuid = snapshot_error['uuid'] + + snapshot = {'software': '', 'version': '', 'uuid': ''} + with pytest.raises(TypeError): + user.post(res=Snapshot, data=snapshot_error) + + files = [x for x in os.listdir(tmp_snapshots) if uuid in x] + if files: + path_snapshot = os.path.join(tmp_snapshots, files[0]) + with open(path_snapshot) as file_snapshot: + snapshot = json.loads(file_snapshot.read()) + + os.remove(path_snapshot) + + assert snapshot['software'] == snapshot_error['software'] + assert snapshot['version'] == snapshot_error['version'] + assert snapshot['uuid'] == uuid +