Merge pull request #90 from eReuse/bugfix/89-snapshots-in-hdd

Bugfix/89 snapshots in hdd
This commit is contained in:
cayop 2020-12-09 10:31:32 +01:00 committed by GitHub
commit f0c17ebd81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 8 deletions

View file

@ -1 +1 @@
__version__ = "1.0.1-beta"
__version__ = "1.0.2-beta"

View file

@ -101,16 +101,16 @@ class ActionView(View):
def post(self):
"""Posts an action."""
json = request.get_json(validate=False)
tmp_snapshots = app.config['TMP_SNAPSHOTS']
path_snapshot = save_json(json, tmp_snapshots, g.user.email)
json.pop('debug', None)
if not json or 'type' not in json:
raise ValidationError('Resource needs a type.')
# todo there should be a way to better get subclassess resource
# defs
resource_def = app.resources[json['type']]
a = resource_def.schema.load(json)
if json['type'] == Snapshot.t:
tmp_snapshots = app.config['TMP_SNAPSHOTS']
path_snapshot = save_json(json, tmp_snapshots, g.user.email)
json.pop('debug', None)
a = resource_def.schema.load(json)
response = self.snapshot(a, resource_def)
move_json(tmp_snapshots, path_snapshot, g.user.email)
return response
@ -118,8 +118,8 @@ class ActionView(View):
pass
# TODO JN add compute rate with new visual test and old components device
if json['type'] == InitTransfer.t:
move_json(tmp_snapshots, path_snapshot, g.user.email)
return self.transfer_ownership()
a = resource_def.schema.load(json)
Model = db.Model._decl_class_registry.data[json['type']]()
action = Model(**a)
db.session.add(action)
@ -127,7 +127,6 @@ class ActionView(View):
ret = self.schema.jsonify(action)
ret.status_code = 201
db.session.commit()
move_json(tmp_snapshots, path_snapshot, g.user.email)
return ret
def one(self, id: UUID):

View file

@ -18,7 +18,7 @@ from ereuse_devicehub.db import db
from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.resources.action.models import Action, BenchmarkDataStorage, \
BenchmarkProcessor, EraseSectors, RateComputer, Snapshot, SnapshotRequest, VisualTest, \
EreusePrice
EreusePrice, Ready
from ereuse_devicehub.resources.device import models as m
from ereuse_devicehub.resources.device.exceptions import NeedsId
from ereuse_devicehub.resources.device.models import SolidStateDrive
@ -541,6 +541,25 @@ def test_save_snapshot_in_file(app: Devicehub, user: UserClient):
assert snapshot['version'] == snapshot_no_hid['version']
assert snapshot['uuid'] == uuid
@pytest.mark.mvp
def test_action_no_snapshot_without_save_file(app: Devicehub, user: UserClient):
""" This test check if the function save_snapshot_in_file not work when we
send one other action different to snapshot
"""
s = file('laptop-hp_255_g3_notebook-hewlett-packard-cnd52270fw.snapshot')
snapshot, _ = user.post(res=Snapshot, data=s)
tmp_snapshots = app.config['TMP_SNAPSHOTS']
path_dir_base = os.path.join(tmp_snapshots, user.user['email'])
shutil.rmtree(tmp_snapshots)
action = {'type': Ready.t, 'devices': [snapshot['device']['id']]}
action, _ = user.post(action, res=Action)
assert os.path.exists(tmp_snapshots) == False
@pytest.mark.mvp
def test_save_snapshot_with_debug(app: Devicehub, user: UserClient):
""" This test check if works the function save_snapshot_in_file """