From bf8a9438831c248c1571c7a59252c62dd264fb2b Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Tue, 29 Jan 2019 19:01:20 +0100 Subject: [PATCH] Remove re-setting ordered_components hotfix; bump ereuse-utils --- ereuse_devicehub/resources/event/views.py | 6 ------ requirements.txt | 2 +- setup.py | 2 +- tests/test_snapshot.py | 12 ++++++++++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ereuse_devicehub/resources/event/views.py b/ereuse_devicehub/resources/event/views.py index 570a4062..a492fb79 100644 --- a/ereuse_devicehub/resources/event/views.py +++ b/ereuse_devicehub/resources/event/views.py @@ -85,12 +85,6 @@ class SnapshotView(View): db.session.add(snapshot) db.session.commit() - # todo we are setting snapshot dirty again with this components but - # we do not want to update it. - # The real solution is https://stackoverflow.com/questions/ - # 24480581/set-the-insert-order-of-a-many-to-many-sqlalchemy- - # flask-app-sqlite-db?noredirect=1&lq=1 - snapshot.components = ordered_components ret = self.schema.jsonify(snapshot) # transform it back ret.status_code = 201 return ret diff --git a/requirements.txt b/requirements.txt index 0bb9cb3d..222e1c41 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ click==6.7 click-spinner==0.1.8 colorama==0.3.9 colour==0.1.5 -ereuse-utils[naming, test, session, cli]==0.4.0b15 +ereuse-utils[naming, test, session, cli]==0.4.0b18 Flask==1.0.2 Flask-Cors==3.0.6 Flask-SQLAlchemy==2.3.2 diff --git a/setup.py b/setup.py index 1b17d7a9..6abe67a8 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ setup( 'teal>=0.2.0a35', # teal always first 'click', 'click-spinner', - 'ereuse-utils[naming, test, session, cli]>=0.4b15', + 'ereuse-utils[naming, test, session, cli]>=0.4b18', 'hashids', 'marshmallow_enum', 'psycopg2-binary', diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index ef0e5bc9..4fda076a 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -1,4 +1,5 @@ from datetime import datetime, timedelta, timezone +from operator import itemgetter from typing import List, Tuple from uuid import uuid4 @@ -79,13 +80,17 @@ def test_snapshot_post(user: UserClient): assert 'events' not in snapshot['device'] assert 'author' not in snapshot['device'] device, _ = user.get(res=m.Device, item=snapshot['device']['id']) + key = itemgetter('serialNumber') + snapshot['components'].sort(key=key) + device['components'].sort(key=key) assert snapshot['components'] == device['components'] - assert tuple(c['type'] for c in snapshot['components']) == (m.GraphicCard.t, m.RamModule.t, - m.Processor.t) + assert {c['type'] for c in snapshot['components']} == {m.GraphicCard.t, m.RamModule.t, + m.Processor.t} rate = next(e for e in snapshot['events'] if e['type'] == WorkbenchRate.t) rate, _ = user.get(res=Event, item=rate['id']) assert rate['device']['id'] == snapshot['device']['id'] + rate['components'].sort(key=key) assert rate['components'] == snapshot['components'] assert rate['snapshot']['id'] == snapshot['id'] @@ -390,6 +395,9 @@ def assert_similar_components(components1: List[dict], components2: List[dict]): similar than the components in components2. """ assert len(components1) == len(components2) + key = itemgetter('serialNumber') + components1.sort(key=key) + components2.sort(key=key) for c1, c2 in zip(components1, components2): assert_similar_device(c1, c2)