Merge pull request #90 from eReuse/bugfix/89-snapshots-in-hdd
Bugfix/89 snapshots in hdd
This commit is contained in:
commit
f0c17ebd81
|
@ -1 +1 @@
|
||||||
__version__ = "1.0.1-beta"
|
__version__ = "1.0.2-beta"
|
||||||
|
|
|
@ -101,16 +101,16 @@ class ActionView(View):
|
||||||
def post(self):
|
def post(self):
|
||||||
"""Posts an action."""
|
"""Posts an action."""
|
||||||
json = request.get_json(validate=False)
|
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:
|
if not json or 'type' not in json:
|
||||||
raise ValidationError('Resource needs a type.')
|
raise ValidationError('Resource needs a type.')
|
||||||
# todo there should be a way to better get subclassess resource
|
# todo there should be a way to better get subclassess resource
|
||||||
# defs
|
# defs
|
||||||
resource_def = app.resources[json['type']]
|
resource_def = app.resources[json['type']]
|
||||||
a = resource_def.schema.load(json)
|
|
||||||
if json['type'] == Snapshot.t:
|
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)
|
response = self.snapshot(a, resource_def)
|
||||||
move_json(tmp_snapshots, path_snapshot, g.user.email)
|
move_json(tmp_snapshots, path_snapshot, g.user.email)
|
||||||
return response
|
return response
|
||||||
|
@ -118,8 +118,8 @@ class ActionView(View):
|
||||||
pass
|
pass
|
||||||
# TODO JN add compute rate with new visual test and old components device
|
# TODO JN add compute rate with new visual test and old components device
|
||||||
if json['type'] == InitTransfer.t:
|
if json['type'] == InitTransfer.t:
|
||||||
move_json(tmp_snapshots, path_snapshot, g.user.email)
|
|
||||||
return self.transfer_ownership()
|
return self.transfer_ownership()
|
||||||
|
a = resource_def.schema.load(json)
|
||||||
Model = db.Model._decl_class_registry.data[json['type']]()
|
Model = db.Model._decl_class_registry.data[json['type']]()
|
||||||
action = Model(**a)
|
action = Model(**a)
|
||||||
db.session.add(action)
|
db.session.add(action)
|
||||||
|
@ -127,7 +127,6 @@ class ActionView(View):
|
||||||
ret = self.schema.jsonify(action)
|
ret = self.schema.jsonify(action)
|
||||||
ret.status_code = 201
|
ret.status_code = 201
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
move_json(tmp_snapshots, path_snapshot, g.user.email)
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def one(self, id: UUID):
|
def one(self, id: UUID):
|
||||||
|
|
|
@ -18,7 +18,7 @@ from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.devicehub import Devicehub
|
from ereuse_devicehub.devicehub import Devicehub
|
||||||
from ereuse_devicehub.resources.action.models import Action, BenchmarkDataStorage, \
|
from ereuse_devicehub.resources.action.models import Action, BenchmarkDataStorage, \
|
||||||
BenchmarkProcessor, EraseSectors, RateComputer, Snapshot, SnapshotRequest, VisualTest, \
|
BenchmarkProcessor, EraseSectors, RateComputer, Snapshot, SnapshotRequest, VisualTest, \
|
||||||
EreusePrice
|
EreusePrice, Ready
|
||||||
from ereuse_devicehub.resources.device import models as m
|
from ereuse_devicehub.resources.device import models as m
|
||||||
from ereuse_devicehub.resources.device.exceptions import NeedsId
|
from ereuse_devicehub.resources.device.exceptions import NeedsId
|
||||||
from ereuse_devicehub.resources.device.models import SolidStateDrive
|
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['version'] == snapshot_no_hid['version']
|
||||||
assert snapshot['uuid'] == uuid
|
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
|
@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 """
|
||||||
|
|
Reference in New Issue