fixing test for new structure and adding debug test

This commit is contained in:
Cayo Puigdefabregas 2020-10-29 16:09:38 +01:00
parent 5f68803d9f
commit ed32f691f7
1 changed files with 35 additions and 24 deletions

View File

@ -1,5 +1,6 @@
import os import os
import json import json
import shutil
import pytest import pytest
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
@ -483,20 +484,22 @@ def test_pc_2(user: UserClient):
@pytest.mark.mvp @pytest.mark.mvp
def test_save_snapshot_in_file(app: Devicehub, user: UserClient): def test_save_snapshot_in_file(app: Devicehub, user: UserClient):
""" This test check if works the function save_snapshot_in_file """ """ This test check if works the function save_snapshot_in_file """
tmp_snapshots = app.config['TMP_SNAPSHOTS']
snapshot_no_hid = file('basic.snapshot.nohid') snapshot_no_hid = file('basic.snapshot.nohid')
tmp_snapshots = app.config['TMP_SNAPSHOTS']
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
save_json(snapshot_no_hid, tmp_snapshots, user.user['email']) save_json(snapshot_no_hid, tmp_snapshots, user.user['email'])
uuid = snapshot_no_hid['uuid'] uuid = snapshot_no_hid['uuid']
files = [x for x in os.listdir(tmp_snapshots) if uuid in x] files = [x for x in os.listdir(path_dir_base) if uuid in x]
snapshot = {'software': '', 'version': '', 'uuid': ''} snapshot = {'software': '', 'version': '', 'uuid': ''}
if files: if files:
path_snapshot = os.path.join(tmp_snapshots, files[0]) path_snapshot = os.path.join(path_dir_base, files[0])
with open(path_snapshot) as file_snapshot: with open(path_snapshot) as file_snapshot:
snapshot = json.loads(file_snapshot.read()) snapshot = json.loads(file_snapshot.read())
os.remove(path_snapshot) shutil.rmtree(tmp_snapshots)
assert snapshot['software'] == snapshot_no_hid['software'] assert snapshot['software'] == snapshot_no_hid['software']
assert snapshot['version'] == snapshot_no_hid['version'] assert snapshot['version'] == snapshot_no_hid['version']
@ -505,20 +508,23 @@ def test_save_snapshot_in_file(app: Devicehub, user: UserClient):
@pytest.mark.mvp @pytest.mark.mvp
def test_save_snapshot_with_debug(app: Devicehub, user: UserClient): def test_save_snapshot_with_debug(app: Devicehub, user: UserClient):
""" This test check if works the function save_snapshot_in_file """ """ This test check if works the function save_snapshot_in_file """
tmp_snapshots = app.config['TMP_SNAPSHOTS']
snapshot_file = file('basic.snapshot.with_debug') snapshot_file = file('basic.snapshot.with_debug')
debug = snapshot_file['debug'] debug = snapshot_file['debug']
user.post(res=Snapshot, data=snapshot_file) user.post(res=Snapshot, data=snapshot_file)
uuid = snapshot_file['uuid'] tmp_snapshots = app.config['TMP_SNAPSHOTS']
files = [x for x in os.listdir(tmp_snapshots) if uuid in x] path_dir_base = os.path.join(tmp_snapshots, user.user['email'])
uuid = snapshot_file['uuid']
files = [x for x in os.listdir(path_dir_base) if uuid in x]
snapshot = {'debug': ''}
if files: if files:
path_snapshot = os.path.join(tmp_snapshots, files[0]) path_snapshot = os.path.join(path_dir_base, files[0])
with open(path_snapshot) as file_snapshot: with open(path_snapshot) as file_snapshot:
snapshot = json.loads(file_snapshot.read()) snapshot = json.loads(file_snapshot.read())
os.remove(path_snapshot) shutil.rmtree(tmp_snapshots)
assert snapshot['debug'] == debug assert snapshot['debug'] == debug
@ -527,6 +533,7 @@ def test_save_snapshot_with_debug(app: Devicehub, user: UserClient):
def test_backup_snapshot_with_errors(app: Devicehub, user: UserClient): def test_backup_snapshot_with_errors(app: Devicehub, user: UserClient):
""" This test check if the file snapshot is create when some snapshot is wrong """ """ This test check if the file snapshot is create when some snapshot is wrong """
tmp_snapshots = app.config['TMP_SNAPSHOTS'] tmp_snapshots = app.config['TMP_SNAPSHOTS']
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
snapshot_no_hid = file('basic.snapshot.badly_formed') snapshot_no_hid = file('basic.snapshot.badly_formed')
uuid = snapshot_no_hid['uuid'] uuid = snapshot_no_hid['uuid']
@ -534,13 +541,13 @@ def test_backup_snapshot_with_errors(app: Devicehub, user: UserClient):
with pytest.raises(KeyError): with pytest.raises(KeyError):
response = user.post(res=Snapshot, data=snapshot_no_hid) response = user.post(res=Snapshot, data=snapshot_no_hid)
files = [x for x in os.listdir(tmp_snapshots) if uuid in x] files = [x for x in os.listdir(path_dir_base) if uuid in x]
if files: if files:
path_snapshot = os.path.join(tmp_snapshots, files[0]) path_snapshot = os.path.join(path_dir_base, files[0])
with open(path_snapshot) as file_snapshot: with open(path_snapshot) as file_snapshot:
snapshot = json.loads(file_snapshot.read()) snapshot = json.loads(file_snapshot.read())
os.remove(path_snapshot) shutil.rmtree(tmp_snapshots)
assert snapshot['software'] == snapshot_no_hid['software'] assert snapshot['software'] == snapshot_no_hid['software']
assert snapshot['version'] == snapshot_no_hid['version'] assert snapshot['version'] == snapshot_no_hid['version']
@ -551,6 +558,7 @@ def test_backup_snapshot_with_errors(app: Devicehub, user: UserClient):
def test_snapshot_failed_missing_cpu_benchmark(app: Devicehub, user: UserClient): 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 """ """ This test check if the file snapshot is create when some snapshot is wrong """
tmp_snapshots = app.config['TMP_SNAPSHOTS'] tmp_snapshots = app.config['TMP_SNAPSHOTS']
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
snapshot_error = file('failed.snapshot.500.missing-cpu-benchmark') snapshot_error = file('failed.snapshot.500.missing-cpu-benchmark')
uuid = snapshot_error['uuid'] uuid = snapshot_error['uuid']
@ -558,13 +566,13 @@ def test_snapshot_failed_missing_cpu_benchmark(app: Devicehub, user: UserClient)
with pytest.raises(TypeError): with pytest.raises(TypeError):
user.post(res=Snapshot, data=snapshot_error) user.post(res=Snapshot, data=snapshot_error)
files = [x for x in os.listdir(tmp_snapshots) if uuid in x] files = [x for x in os.listdir(path_dir_base) if uuid in x]
if files: if files:
path_snapshot = os.path.join(tmp_snapshots, files[0]) path_snapshot = os.path.join(path_dir_base, files[0])
with open(path_snapshot) as file_snapshot: with open(path_snapshot) as file_snapshot:
snapshot = json.loads(file_snapshot.read()) snapshot = json.loads(file_snapshot.read())
os.remove(path_snapshot) shutil.rmtree(tmp_snapshots)
assert snapshot['software'] == snapshot_error['software'] assert snapshot['software'] == snapshot_error['software']
assert snapshot['version'] == snapshot_error['version'] assert snapshot['version'] == snapshot_error['version']
@ -575,6 +583,7 @@ def test_snapshot_failed_missing_cpu_benchmark(app: Devicehub, user: UserClient)
def test_snapshot_failed_missing_hdd_benchmark(app: Devicehub, user: UserClient): 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 """ """ This test check if the file snapshot is create when some snapshot is wrong """
tmp_snapshots = app.config['TMP_SNAPSHOTS'] tmp_snapshots = app.config['TMP_SNAPSHOTS']
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
snapshot_error = file('failed.snapshot.500.missing-hdd-benchmark') snapshot_error = file('failed.snapshot.500.missing-hdd-benchmark')
uuid = snapshot_error['uuid'] uuid = snapshot_error['uuid']
@ -582,13 +591,13 @@ def test_snapshot_failed_missing_hdd_benchmark(app: Devicehub, user: UserClient)
with pytest.raises(TypeError): with pytest.raises(TypeError):
user.post(res=Snapshot, data=snapshot_error) user.post(res=Snapshot, data=snapshot_error)
files = [x for x in os.listdir(tmp_snapshots) if uuid in x] files = [x for x in os.listdir(path_dir_base) if uuid in x]
if files: if files:
path_snapshot = os.path.join(tmp_snapshots, files[0]) path_snapshot = os.path.join(path_dir_base, files[0])
with open(path_snapshot) as file_snapshot: with open(path_snapshot) as file_snapshot:
snapshot = json.loads(file_snapshot.read()) snapshot = json.loads(file_snapshot.read())
os.remove(path_snapshot) shutil.rmtree(tmp_snapshots)
assert snapshot['software'] == snapshot_error['software'] assert snapshot['software'] == snapshot_error['software']
assert snapshot['version'] == snapshot_error['version'] assert snapshot['version'] == snapshot_error['version']
@ -599,6 +608,7 @@ def test_snapshot_failed_missing_hdd_benchmark(app: Devicehub, user: UserClient)
def test_snapshot_failed_null_chassis(app: Devicehub, user: UserClient): def test_snapshot_failed_null_chassis(app: Devicehub, user: UserClient):
""" This test check if the file snapshot is create when some snapshot is wrong """ """ This test check if the file snapshot is create when some snapshot is wrong """
tmp_snapshots = app.config['TMP_SNAPSHOTS'] tmp_snapshots = app.config['TMP_SNAPSHOTS']
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
snapshot_error = file('failed.snapshot.422.null-chassis') snapshot_error = file('failed.snapshot.422.null-chassis')
uuid = snapshot_error['uuid'] uuid = snapshot_error['uuid']
@ -606,13 +616,13 @@ def test_snapshot_failed_null_chassis(app: Devicehub, user: UserClient):
with pytest.raises(TypeError): with pytest.raises(TypeError):
user.post(res=Snapshot, data=snapshot_error) user.post(res=Snapshot, data=snapshot_error)
files = [x for x in os.listdir(tmp_snapshots) if uuid in x] files = [x for x in os.listdir(path_dir_base) if uuid in x]
if files: if files:
path_snapshot = os.path.join(tmp_snapshots, files[0]) path_snapshot = os.path.join(path_dir_base, files[0])
with open(path_snapshot) as file_snapshot: with open(path_snapshot) as file_snapshot:
snapshot = json.loads(file_snapshot.read()) snapshot = json.loads(file_snapshot.read())
os.remove(path_snapshot) shutil.rmtree(tmp_snapshots)
assert snapshot['software'] == snapshot_error['software'] assert snapshot['software'] == snapshot_error['software']
assert snapshot['version'] == snapshot_error['version'] assert snapshot['version'] == snapshot_error['version']
@ -623,6 +633,7 @@ def test_snapshot_failed_null_chassis(app: Devicehub, user: UserClient):
def test_snapshot_failed_missing_chassis(app: Devicehub, user: UserClient): def test_snapshot_failed_missing_chassis(app: Devicehub, user: UserClient):
""" This test check if the file snapshot is create when some snapshot is wrong """ """ This test check if the file snapshot is create when some snapshot is wrong """
tmp_snapshots = app.config['TMP_SNAPSHOTS'] tmp_snapshots = app.config['TMP_SNAPSHOTS']
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
snapshot_error = file('failed.snapshot.422.missing-chassis') snapshot_error = file('failed.snapshot.422.missing-chassis')
uuid = snapshot_error['uuid'] uuid = snapshot_error['uuid']
@ -630,13 +641,13 @@ def test_snapshot_failed_missing_chassis(app: Devicehub, user: UserClient):
with pytest.raises(TypeError): with pytest.raises(TypeError):
user.post(res=Snapshot, data=snapshot_error) user.post(res=Snapshot, data=snapshot_error)
files = [x for x in os.listdir(tmp_snapshots) if uuid in x] files = [x for x in os.listdir(path_dir_base) if uuid in x]
if files: if files:
path_snapshot = os.path.join(tmp_snapshots, files[0]) path_snapshot = os.path.join(path_dir_base, files[0])
with open(path_snapshot) as file_snapshot: with open(path_snapshot) as file_snapshot:
snapshot = json.loads(file_snapshot.read()) snapshot = json.loads(file_snapshot.read())
os.remove(path_snapshot) shutil.rmtree(tmp_snapshots)
assert snapshot['software'] == snapshot_error['software'] assert snapshot['software'] == snapshot_error['software']
assert snapshot['version'] == snapshot_error['version'] assert snapshot['version'] == snapshot_error['version']