From 2fd0c61cc3870b439623cc8164f2e783789f195b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Sat, 28 Nov 2020 18:35:53 +0100 Subject: [PATCH 1/4] adding test for reproduce the bug --- tests/test_snapshot.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 0c4bbf1d..c722cd1b 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -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,26 @@ 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) + + files = [x for x in os.listdir(path_dir_base) if '.json' in x] + assert len(files) == 0 + @pytest.mark.mvp def test_save_snapshot_with_debug(app: Devicehub, user: UserClient): """ This test check if works the function save_snapshot_in_file """ From a9f6e9ccaaed42fd4116556a2c3eec04f53896b7 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Sat, 28 Nov 2020 18:47:35 +0100 Subject: [PATCH 2/4] fixing bug --- ereuse_devicehub/resources/action/views.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ereuse_devicehub/resources/action/views.py b/ereuse_devicehub/resources/action/views.py index 2d71b4fd..4797a5b2 100644 --- a/ereuse_devicehub/resources/action/views.py +++ b/ereuse_devicehub/resources/action/views.py @@ -65,16 +65,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 @@ -82,8 +82,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) @@ -91,7 +91,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): From 517007ef50790933755e192ef98ecee39599a414 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Sat, 28 Nov 2020 19:04:54 +0100 Subject: [PATCH 3/4] fixing test --- tests/test_snapshot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index c722cd1b..274e4451 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -558,8 +558,7 @@ def test_action_no_snapshot_without_save_file(app: Devicehub, user: UserClient): action = {'type': Ready.t, 'devices': [snapshot['device']['id']]} action, _ = user.post(action, res=Action) - files = [x for x in os.listdir(path_dir_base) if '.json' in x] - assert len(files) == 0 + assert os.path.exists(tmp_snapshots) == False @pytest.mark.mvp def test_save_snapshot_with_debug(app: Devicehub, user: UserClient): From 2daee4ddd85a8b0955dfc23b73fbb97bed20032a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 9 Dec 2020 10:23:58 +0100 Subject: [PATCH 4/4] update version --- ereuse_devicehub/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/__init__.py b/ereuse_devicehub/__init__.py index 944f81a7..feee2d99 100644 --- a/ereuse_devicehub/__init__.py +++ b/ereuse_devicehub/__init__.py @@ -1 +1 @@ -__version__ = "1.0.1-beta" +__version__ = "1.0.2-beta"