From adb9a8e25a58932987a2a43a79f08d247397c300 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 1 Mar 2021 19:21:57 +0100 Subject: [PATCH 01/27] basic endpoint for wbconf --- ereuse_devicehub/resources/documents/documents.py | 10 ++++++++++ tests/test_documents.py | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 692e6992..3a2f9b6a 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -291,6 +291,10 @@ class InternalStatsView(DeviceView): output.headers['Content-type'] = 'text/csv' return output +class WbConfDocumentView(DeviceView): + def get(self, wbtype: str): + return jsonify('') + class DocumentDef(Resource): __type__ = 'Document' @@ -358,3 +362,9 @@ class DocumentDef(Resource): auth=app.auth) actions_view = app.auth.requires_auth(actions_view) self.add_url_rule('/actions/', defaults=d, view_func=actions_view, methods=get) + + wbconf_view = ActionsDocumentView.as_view('WbConfDocumentView', + definition=self, + auth=app.auth) + wbconf_view = app.auth.requires_auth(wbconf_view) + self.add_url_rule('/wbconf/', defaults=d, view_func=wbconf_view, methods=get) diff --git a/tests/test_documents.py b/tests/test_documents.py index 5ac747b5..9639688a 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -465,7 +465,7 @@ def test_get_document_lots(user: UserClient, user2: UserClient): @pytest.mark.mvp def test_get_document_internal_stats(user: UserClient, user2: UserClient): - """Tests for get teh internal stats.""" + """Tests for get the internal stats.""" # csv_str, _ = user.get(res=documents.DocumentDef.t, # item='internalstats/') @@ -490,3 +490,10 @@ def test_get_document_internal_stats(user: UserClient, user2: UserClient): export_csv = list(obj_csv) assert csv_str.strip() == '""' + +@pytest.mark.mvp +def test_get_wbconf(user: UserClient): + """Tests for get env file for usb wb.""" + + csv_str, _ = user.get(res=documents.DocumentDef.t, + item='wbconf/') From 0d0005b31532f4d976c3524f16878ba5f3d536a1 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 2 Mar 2021 11:42:07 +0100 Subject: [PATCH 02/27] adding file env for download --- .../resources/documents/documents.py | 27 ++++++++++++++----- .../documents/templates/documents/env | 14 ++++++++++ tests/test_documents.py | 7 +++-- 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 ereuse_devicehub/resources/documents/templates/documents/env diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 3a2f9b6a..8aa345e4 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -1,7 +1,8 @@ import csv -import datetime import enum import uuid +import datetime +import pathlib from collections import OrderedDict from io import StringIO from typing import Callable, Iterable, Tuple @@ -251,7 +252,7 @@ class StampsView(View): url = urlutils.URL(request.url) url.normalize() url.path_parts = url.path_parts[:-2] + ['check', ''] - url_path = url.to_text() + url_path = url.to_text() return flask.render_template('documents/stamp.html', rq_url=url_path) @@ -291,9 +292,23 @@ class InternalStatsView(DeviceView): output.headers['Content-type'] = 'text/csv' return output -class WbConfDocumentView(DeviceView): + +class WbConfDocumentView(View): def get(self, wbtype: str): - return jsonify('') + if not wbtype.lower() in ['usodyrate', 'usodywipe']: + return jsonify('') + + data = {'token': '111', + 'host': 'localhost', + 'inventory': 'dbtest' + } + data['erase'] = False if wbtype == 'usodyrate' else True + + env = flask.render_template('documents/env', **data) + output = make_response(env) + output.headers['Content-Disposition'] = 'attachment; filename=.env' + output.headers['Content-type'] = 'text/plain' + return output class DocumentDef(Resource): @@ -363,8 +378,8 @@ class DocumentDef(Resource): actions_view = app.auth.requires_auth(actions_view) self.add_url_rule('/actions/', defaults=d, view_func=actions_view, methods=get) - wbconf_view = ActionsDocumentView.as_view('WbConfDocumentView', + wbconf_view = WbConfDocumentView.as_view('WbConfDocumentView', definition=self, auth=app.auth) wbconf_view = app.auth.requires_auth(wbconf_view) - self.add_url_rule('/wbconf/', defaults=d, view_func=wbconf_view, methods=get) + self.add_url_rule('/wbconf/', view_func=wbconf_view, methods=get) diff --git a/ereuse_devicehub/resources/documents/templates/documents/env b/ereuse_devicehub/resources/documents/templates/documents/env new file mode 100644 index 00000000..d7b43547 --- /dev/null +++ b/ereuse_devicehub/resources/documents/templates/documents/env @@ -0,0 +1,14 @@ +DH_TOKEN='{{token}}' +DH_HOST='{{host}}' +DH_INVENTORY='{{inventory}}' +DEVICEHUB_URL=https://${DB_HOST}/${DB_INVENTORY}/ + +WB_BENCHMARK = True +WB_STRESS_TEST = 0 +WB_SMART_TEST = 'short' + +WB_ERASE = {{erase}} +WB_ERASE_STEPS = 1 +WB_ERASE_LEADING_ZEROS = False + +WB_DEBUG = True diff --git a/tests/test_documents.py b/tests/test_documents.py index 9639688a..fc5df617 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -495,5 +495,8 @@ def test_get_document_internal_stats(user: UserClient, user2: UserClient): def test_get_wbconf(user: UserClient): """Tests for get env file for usb wb.""" - csv_str, _ = user.get(res=documents.DocumentDef.t, - item='wbconf/') + env, _ = user.get(res=documents.DocumentDef.t, item='wbconf/usodyrate', accept=ANY) + assert 'WB_ERASE = False' in env + + env, _ = user.get(res=documents.DocumentDef.t, item='wbconf/usodywipe', accept=ANY) + assert 'WB_ERASE = True' in env From f9ef2407496c29c6eb73dd62da42b867da7b17dd Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 2 Mar 2021 11:46:13 +0100 Subject: [PATCH 03/27] adding endpoint to test_basic --- tests/test_basic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_basic.py b/tests/test_basic.py index 11ffbb80..29d65f3e 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -40,6 +40,7 @@ def test_api_docs(client: Client): '/documents/erasures/', '/documents/devices/', '/documents/stamps/', + '/documents/wbconf/{wbtype}', '/documents/internalstats/', '/documents/stock/', '/documents/check/', From 8f3c9c33cba41439082a1581c1ce09d171883a4c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 2 Mar 2021 17:11:34 +0100 Subject: [PATCH 04/27] adding the correct vars to env --- ereuse_devicehub/config.py | 1 + ereuse_devicehub/resources/documents/documents.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/config.py b/ereuse_devicehub/config.py index beef8b25..5a37ace0 100644 --- a/ereuse_devicehub/config.py +++ b/ereuse_devicehub/config.py @@ -37,6 +37,7 @@ class DevicehubConfig(Config): DB_PASSWORD = config('DB_PASSWORD', 'ereuse') DB_HOST = config('DB_HOST', 'localhost') DB_DATABASE = config('DB_DATABASE', 'devicehub') + DB_SCHEMA = config('DB_SCHEMA', 'dbtest') SQLALCHEMY_DATABASE_URI = 'postgresql://{user}:{pw}@{host}/{db}'.format( user=DB_USER, pw=DB_PASSWORD, diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 8aa345e4..947ac85e 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -293,14 +293,14 @@ class InternalStatsView(DeviceView): return output -class WbConfDocumentView(View): +class WbConfDocumentView(DeviceView): def get(self, wbtype: str): if not wbtype.lower() in ['usodyrate', 'usodywipe']: return jsonify('') - data = {'token': '111', - 'host': 'localhost', - 'inventory': 'dbtest' + data = {'token': g.user.token, + 'host': app.config['DB_HOST'], + 'inventory': app.config['DB_SCHEMA'] } data['erase'] = False if wbtype == 'usodyrate' else True From 7e541f13a1398c1cff7ab41794656d91b0587be3 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 2 Mar 2021 21:27:14 +0100 Subject: [PATCH 05/27] change env file name --- ereuse_devicehub/resources/documents/documents.py | 4 ++-- .../templates/documents/{env => wbConfiguration.ini} | 0 ereuse_devicehub/resources/user/__init__.py | 4 +++- ereuse_devicehub/resources/user/views.py | 12 +++++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) rename ereuse_devicehub/resources/documents/templates/documents/{env => wbConfiguration.ini} (100%) diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 947ac85e..46e1cbf3 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -304,9 +304,9 @@ class WbConfDocumentView(DeviceView): } data['erase'] = False if wbtype == 'usodyrate' else True - env = flask.render_template('documents/env', **data) + env = flask.render_template('documents/wbConfiguration.ini', **data) output = make_response(env) - output.headers['Content-Disposition'] = 'attachment; filename=.env' + output.headers['Content-Disposition'] = 'attachment; filename=Configuration.ini' output.headers['Content-type'] = 'text/plain' return output diff --git a/ereuse_devicehub/resources/documents/templates/documents/env b/ereuse_devicehub/resources/documents/templates/documents/wbConfiguration.ini similarity index 100% rename from ereuse_devicehub/resources/documents/templates/documents/env rename to ereuse_devicehub/resources/documents/templates/documents/wbConfiguration.ini diff --git a/ereuse_devicehub/resources/user/__init__.py b/ereuse_devicehub/resources/user/__init__.py index ec9eed78..d4bf8354 100644 --- a/ereuse_devicehub/resources/user/__init__.py +++ b/ereuse_devicehub/resources/user/__init__.py @@ -7,7 +7,7 @@ from teal.resource import Converters, Resource from ereuse_devicehub.db import db from ereuse_devicehub.resources.user import schemas from ereuse_devicehub.resources.user.models import User -from ereuse_devicehub.resources.user.views import UserView, login +from ereuse_devicehub.resources.user.views import UserView, login, logout class UserDef(Resource): @@ -23,6 +23,8 @@ class UserDef(Resource): super().__init__(app, import_name, static_folder, static_url_path, template_folder, url_prefix, subdomain, url_defaults, root_path, cli_commands) self.add_url_rule('/login/', view_func=login, methods={'POST'}) + logout1 = app.auth.requires_auth(logout) + self.add_url_rule('/logout/', view_func=logout1, methods={'GET'}) @argument('email') @option('-i', '--inventory', diff --git a/ereuse_devicehub/resources/user/views.py b/ereuse_devicehub/resources/user/views.py index 7053eea7..e6376f3c 100644 --- a/ereuse_devicehub/resources/user/views.py +++ b/ereuse_devicehub/resources/user/views.py @@ -1,8 +1,10 @@ -from uuid import UUID +from uuid import UUID, uuid4 from flask import g, request +from flask.json import jsonify from teal.resource import View +from ereuse_devicehub.db import db from ereuse_devicehub.resources.user.exceptions import WrongCredentials from ereuse_devicehub.resources.user.models import User from ereuse_devicehub.resources.user.schemas import User as UserS @@ -24,3 +26,11 @@ def login(): return schema_with_token.jsonify(user) else: raise WrongCredentials() + + +def logout(): + # We use custom schema as we only want to parse a subset of user + g.user.token = uuid4() + db.session.add(g.user) + db.session.commit() + return jsonify('Ok') From 7dc88369a49fc52e0bf69341bb05557ae992c9b9 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 2 Mar 2021 21:53:15 +0100 Subject: [PATCH 06/27] adding logout in test_base --- tests/test_basic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_basic.py b/tests/test_basic.py index 29d65f3e..7de68b1a 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -56,7 +56,8 @@ def test_api_docs(client: Client): '/tags/', '/tags/{tag_id}/device/{device_id}', '/users/', - '/users/login/' + '/users/login/', + '/users/logout/', # '/devices/{dev1_id}/merge/{dev2_id}', # '/batteries/{dev1_id}/merge/{dev2_id}', # '/bikes/{dev1_id}/merge/{dev2_id}', From 5af22b6ec61fd1894200884347c5b840b0df1268 Mon Sep 17 00:00:00 2001 From: cayop <42643859+cayop@users.noreply.github.com> Date: Mon, 12 Apr 2021 11:47:18 +0200 Subject: [PATCH 07/27] Update ereuse_devicehub/resources/documents/documents.py Co-authored-by: Jordi Nadeu --- ereuse_devicehub/resources/documents/documents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 1691f0ab..5fc51743 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -329,7 +329,7 @@ class WbConfDocumentView(DeviceView): } data['erase'] = False if wbtype == 'usodyrate' else True - env = flask.render_template('documents/wbConfiguration.ini', **data) + env = flask.render_template('documents/wbSettings.ini', **data) output = make_response(env) output.headers['Content-Disposition'] = 'attachment; filename=Configuration.ini' output.headers['Content-type'] = 'text/plain' From e40b297f3becdb8dcfbd0876dec22563515060b2 Mon Sep 17 00:00:00 2001 From: cayop <42643859+cayop@users.noreply.github.com> Date: Mon, 12 Apr 2021 11:47:26 +0200 Subject: [PATCH 08/27] Update ereuse_devicehub/resources/documents/documents.py Co-authored-by: Jordi Nadeu --- ereuse_devicehub/resources/documents/documents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 5fc51743..b687dd82 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -331,7 +331,7 @@ class WbConfDocumentView(DeviceView): env = flask.render_template('documents/wbSettings.ini', **data) output = make_response(env) - output.headers['Content-Disposition'] = 'attachment; filename=Configuration.ini' + output.headers['Content-Disposition'] = 'attachment; filename=settings.ini' output.headers['Content-type'] = 'text/plain' return output From aa09413011d207b5df3e59f62fcac808c5e4ff4c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 12 Apr 2021 12:05:52 +0200 Subject: [PATCH 09/27] fixing review comments --- .../resources/documents/documents.py | 7 ++++--- .../templates/documents/wbConfiguration.ini | 14 -------------- .../templates/documents/wbSettings.ini | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 17 deletions(-) delete mode 100644 ereuse_devicehub/resources/documents/templates/documents/wbConfiguration.ini create mode 100644 ereuse_devicehub/resources/documents/templates/documents/wbSettings.ini diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 1691f0ab..3eadfb4d 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -327,11 +327,12 @@ class WbConfDocumentView(DeviceView): 'host': app.config['DB_HOST'], 'inventory': app.config['DB_SCHEMA'] } - data['erase'] = False if wbtype == 'usodyrate' else True + data['erase'] = False + # data['erase'] = False if wbtype == 'usodyrate' else True - env = flask.render_template('documents/wbConfiguration.ini', **data) + env = flask.render_template('documents/wbSettings.ini', **data) output = make_response(env) - output.headers['Content-Disposition'] = 'attachment; filename=Configuration.ini' + output.headers['Content-Disposition'] = 'attachment; filename=settings.ini' output.headers['Content-type'] = 'text/plain' return output diff --git a/ereuse_devicehub/resources/documents/templates/documents/wbConfiguration.ini b/ereuse_devicehub/resources/documents/templates/documents/wbConfiguration.ini deleted file mode 100644 index d7b43547..00000000 --- a/ereuse_devicehub/resources/documents/templates/documents/wbConfiguration.ini +++ /dev/null @@ -1,14 +0,0 @@ -DH_TOKEN='{{token}}' -DH_HOST='{{host}}' -DH_INVENTORY='{{inventory}}' -DEVICEHUB_URL=https://${DB_HOST}/${DB_INVENTORY}/ - -WB_BENCHMARK = True -WB_STRESS_TEST = 0 -WB_SMART_TEST = 'short' - -WB_ERASE = {{erase}} -WB_ERASE_STEPS = 1 -WB_ERASE_LEADING_ZEROS = False - -WB_DEBUG = True diff --git a/ereuse_devicehub/resources/documents/templates/documents/wbSettings.ini b/ereuse_devicehub/resources/documents/templates/documents/wbSettings.ini new file mode 100644 index 00000000..c7156a65 --- /dev/null +++ b/ereuse_devicehub/resources/documents/templates/documents/wbSettings.ini @@ -0,0 +1,17 @@ +[settings] + +DH_TOKEN="{{token}}" + +DH_HOST="{{host}}" +DH_DATABASE="{{inventory}}" +DEVICEHUB_URL=https://${DB_HOST}/${DB_DATABASE}/ + +WB_BENCHMARK = False +WB_STRESS_TEST = 0 +WB_SMART_TEST = "" + +WB_ERASE = {{erase}} +WB_ERASE_STEPS = 1 +WB_ERASE_LEADING_ZEROS = False + +WB_DEBUG = True From 3be867832812edd6163f8bf8a2d7cc1ea23f7eb2 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 12 Apr 2021 12:10:57 +0200 Subject: [PATCH 10/27] resolve bad name of var logout1 --- ereuse_devicehub/resources/user/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/resources/user/__init__.py b/ereuse_devicehub/resources/user/__init__.py index d4bf8354..1bbe508b 100644 --- a/ereuse_devicehub/resources/user/__init__.py +++ b/ereuse_devicehub/resources/user/__init__.py @@ -23,8 +23,8 @@ class UserDef(Resource): super().__init__(app, import_name, static_folder, static_url_path, template_folder, url_prefix, subdomain, url_defaults, root_path, cli_commands) self.add_url_rule('/login/', view_func=login, methods={'POST'}) - logout1 = app.auth.requires_auth(logout) - self.add_url_rule('/logout/', view_func=logout1, methods={'GET'}) + logout_view = app.auth.requires_auth(logout) + self.add_url_rule('/logout/', view_func=logout_view, methods={'GET'}) @argument('email') @option('-i', '--inventory', From 1620591deb31ee774f5b9754bc5721816bbe1814 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 12 Apr 2021 12:31:07 +0200 Subject: [PATCH 11/27] fixing test_get_wbconf --- tests/test_documents.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_documents.py b/tests/test_documents.py index 92eb1ded..527f6a63 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -654,4 +654,5 @@ def test_get_wbconf(user: UserClient): assert 'WB_ERASE = False' in env env, _ = user.get(res=documents.DocumentDef.t, item='wbconf/usodywipe', accept=ANY) - assert 'WB_ERASE = True' in env + assert 'WB_ERASE = False' in env + # assert 'WB_ERASE = True' in env From 4704045da81b36540550a5b8925718b437f7c2d9 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 12 Apr 2021 19:34:33 +0200 Subject: [PATCH 12/27] more easy to read --- ereuse_devicehub/resources/documents/documents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 3eadfb4d..75210340 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -328,7 +328,7 @@ class WbConfDocumentView(DeviceView): 'inventory': app.config['DB_SCHEMA'] } data['erase'] = False - # data['erase'] = False if wbtype == 'usodyrate' else True + # data['erase'] = True if wbtype == 'usodywipe' else False env = flask.render_template('documents/wbSettings.ini', **data) output = make_response(env) From bfa9746de1ceb8a04dfefd637958991e3a669f4e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 13 Apr 2021 18:33:15 +0200 Subject: [PATCH 13/27] session table and model --- .../versions/21afd375a654_session_table.py | 53 +++++++++++++++++++ ereuse_devicehub/resources/enums.py | 21 ++++++++ ereuse_devicehub/resources/user/models.py | 12 ++++- 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 ereuse_devicehub/migrations/versions/21afd375a654_session_table.py diff --git a/ereuse_devicehub/migrations/versions/21afd375a654_session_table.py b/ereuse_devicehub/migrations/versions/21afd375a654_session_table.py new file mode 100644 index 00000000..da370152 --- /dev/null +++ b/ereuse_devicehub/migrations/versions/21afd375a654_session_table.py @@ -0,0 +1,53 @@ +"""session_table + +Revision ID: 21afd375a654 +Revises: 6a2a939d5668 +Create Date: 2021-04-13 11:18:27.720567 + +""" +from alembic import context +from alembic import op +from sqlalchemy.dialects import postgresql +import sqlalchemy as sa +import sqlalchemy_utils +import citext +import teal + +from ereuse_devicehub.resources.enums import SessionType + + +# revision identifiers, used by Alembic. +revision = '21afd375a654' +down_revision = '6a2a939d5668' +branch_labels = None +depends_on = None + + +def get_inv(): + INV = context.get_x_argument(as_dictionary=True).get('inventory') + if not INV: + raise ValueError("Inventory value is not specified") + return INV + +def upgrade(): + op.create_table('session', + sa.Column('updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='The last time Devicehub recorded a change for \n this thing.\n '), + sa.Column('created', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='When Devicehub created this.'), + sa.Column('id', sa.BigInteger(), nullable=False), + sa.Column('expired', sa.BigInteger(), nullable=True), + sa.Column('token', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('type', teal.db.IntEnum(SessionType), nullable=False), + sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['common.user.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('token'), + schema='common' + ) + op.create_index(op.f('ix_session_created'), 'session', ['created'], unique=False, schema='common') + op.create_index(op.f('ix_session_updated'), 'session', ['updated'], unique=False, schema='common') + + +def downgrade(): + op.drop_table('trade', schema=f'{get_inv()}') + op.drop_index(op.f('ix_session_created'), table_name='session', schema='common') + op.drop_index(op.f('ix_session_updated'), table_name='session', schema='common') diff --git a/ereuse_devicehub/resources/enums.py b/ereuse_devicehub/resources/enums.py index a07385d7..cff77056 100644 --- a/ereuse_devicehub/resources/enums.py +++ b/ereuse_devicehub/resources/enums.py @@ -393,3 +393,24 @@ class TransferState(IntEnum): def __str__(self): return self.name + + +@unique +class SessionType(IntEnum): + """ + Enumaration of types of sessions: + + * Internal: permanent Session for internal user. This is used in usb of WorkBench. + * External: permanent Session for external users. This is used in usb of WorkBench. + * Session: This is used for keep more than one session in the app frontend. + + Devicehub specially raises user awareness when an action + has a Severity of ``Warning`` or greater. + """ + + Internal = 0 + External = 1 + Session = 2 + + def __str__(self): + return self.name diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index 0ab670c8..324ee851 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -2,13 +2,15 @@ from uuid import uuid4 from citext import CIText from flask import current_app as app -from sqlalchemy import Column +from sqlalchemy import Column, BigInteger, Sequence from sqlalchemy.dialects.postgresql import UUID from sqlalchemy_utils import EmailType, PasswordType +from teal.db import IntEnum from ereuse_devicehub.db import db from ereuse_devicehub.resources.inventory.model import Inventory from ereuse_devicehub.resources.models import STR_SIZE, Thing +from ereuse_devicehub.resources.enums import SessionType class User(Thing): @@ -57,3 +59,11 @@ class UserInventory(db.Model): __table_args__ = {'schema': 'common'} user_id = db.Column(db.UUID(as_uuid=True), db.ForeignKey(User.id), primary_key=True) inventory_id = db.Column(db.Unicode(), db.ForeignKey(Inventory.id), primary_key=True) + + +class Session(Thing): + id = Column(BigInteger, Sequence('device_seq'), primary_key=True) + expired = Column(BigInteger, default=0) + token = Column(UUID(as_uuid=True), default=uuid4, unique=True, nullable=False) + type = Column(IntEnum(SessionType), default=SessionType.Internal, nullable=False) + user_id = db.Column(db.UUID(as_uuid=True), db.ForeignKey(User.id)) From 21f019dc141d64e72b9d90c8ca3e94168b7c9472 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 13 Apr 2021 18:33:49 +0200 Subject: [PATCH 14/27] useing session table in wbconf --- .../resources/documents/documents.py | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 75210340..7175ab06 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -20,6 +20,8 @@ from teal.cache import cache from teal.resource import Resource, View from ereuse_devicehub.db import db +from ereuse_devicehub.resources.user.models import Session +from ereuse_devicehub.resources.enums import SessionType from ereuse_devicehub.resources.action import models as evs from ereuse_devicehub.resources.device import models as devs from ereuse_devicehub.resources.deliverynote.models import Deliverynote @@ -323,7 +325,7 @@ class WbConfDocumentView(DeviceView): if not wbtype.lower() in ['usodyrate', 'usodywipe']: return jsonify('') - data = {'token': g.user.token, + data = {'token': self.get_token(), 'host': app.config['DB_HOST'], 'inventory': app.config['DB_SCHEMA'] } @@ -336,6 +338,28 @@ class WbConfDocumentView(DeviceView): output.headers['Content-type'] = 'text/plain' return output + def get_token(self): + internal_session = Session.query.filter_by(user_id=g.user.id, + type=SessionType.Internal).first() + if not internal_session: + internal_session = Session(user_id=g.user.id, type=SessionType.Internal) + db.session.add(internal_session) + + db.session.commit() + return internal_session.token + + # TODO @cayop for when in others iterations we need implement external token + # external_session = Session.query.filter_by(user_id=g.user.id, + # type=SessionType.Internal).first() + # if not external_session: + # external_session = Session(user_id=g.user.id, type=SessionType.External) + # external_session = Session(user_id=g.user.id, type=SessionType.External) + # db.session.add(external_session) + + # db.session.commit() + + # return external_session.token + class DocumentDef(Resource): __type__ = 'Document' From ca85a1f221d3863f3a29daf55d5e7149693ca9d9 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 13 Apr 2021 18:34:18 +0200 Subject: [PATCH 15/27] check the token in a test --- tests/test_documents.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tests/test_documents.py b/tests/test_documents.py index a1a7b6d9..33f614a3 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -12,12 +12,14 @@ from ereuse_utils.test import ANY from ereuse_devicehub.client import Client, UserClient from ereuse_devicehub.devicehub import Devicehub +from ereuse_devicehub.resources.user.models import Session from ereuse_devicehub.resources.action.models import Snapshot, Allocate, Live from ereuse_devicehub.resources.documents import documents from ereuse_devicehub.resources.device import models as d from ereuse_devicehub.resources.lot.models import Lot from ereuse_devicehub.resources.tag.model import Tag from ereuse_devicehub.resources.hash_reports import ReportHash +from ereuse_devicehub.resources.enums import SessionType from ereuse_devicehub.db import db from tests import conftest from tests.conftest import file @@ -200,7 +202,7 @@ def test_live_example2(user: UserClient, client: Client, app: Devicehub): assert str(action_live[0].snapshot_uuid) == acer['uuid'] -@pytest.mark.mvp +@pytest.mark.mvp def test_export_basic_snapshot(user: UserClient): """Test export device information in a csv file.""" snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) @@ -464,7 +466,7 @@ def test_get_document_lots(user: UserClient, user2: UserClient): assert export2_csv[1][3] == 'comments,lot3,testcomment-lot3,' -@pytest.mark.mvp +@pytest.mark.mvp def test_verify_stamp(user: UserClient, client: Client): """Test verify stamp of one export device information in a csv file.""" snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) @@ -472,12 +474,12 @@ def test_verify_stamp(user: UserClient, client: Client): item='devices/', accept='text/csv', query=[('filter', {'type': ['Computer']})]) - + response, _ = client.post(res=documents.DocumentDef.t, item='stamps/', content_type='multipart/form-data', accept='text/html', - data={'docUpload': [(BytesIO(bytes(csv_str, 'utf-8')), 'example.csv')]}, + data={'docUpload': [(BytesIO(bytes(csv_str, 'utf-8')), 'example.csv')]}, status=200) assert "alert alert-info" in response assert not "alert alert-danger" in response @@ -501,10 +503,10 @@ def test_verify_stamp(user: UserClient, client: Client): assert not "alert alert-danger" in response -@pytest.mark.mvp +@pytest.mark.mvp def test_verify_stamp_log_info(user: UserClient, client: Client): """Test verify stamp of one export lots-info in a csv file.""" - + l, _ = user.post({'name': 'Lot1', 'description': 'comments,lot1,testcomment-lot1,'}, res=Lot) l, _ = user.post({'name': 'Lot2', 'description': 'comments,lot2,testcomment-lot2,'}, res=Lot) @@ -516,8 +518,8 @@ def test_verify_stamp_log_info(user: UserClient, client: Client): item='stamps/', content_type='multipart/form-data', accept='text/html', - data={'docUpload': [(BytesIO(bytes(csv_str, 'utf-8')), - 'example.csv')]}, + data={'docUpload': [(BytesIO(bytes(csv_str, 'utf-8')), + 'example.csv')]}, status=200) assert "alert alert-info" in response @@ -538,7 +540,7 @@ def test_verify_stamp_devices_stock(user: UserClient, client: Client): content_type='multipart/form-data', accept='text/html', data={'docUpload': [(BytesIO(bytes(csv_str, 'utf-8')), - 'example.csv')]}, + 'example.csv')]}, status=200) assert "alert alert-info" in response @@ -573,8 +575,8 @@ def test_verify_stamp_csv_actions(user: UserClient, client: Client): item='stamps/', content_type='multipart/form-data', accept='text/html', - data={'docUpload': [(BytesIO(bytes(csv_str, 'utf-8')), - 'example.csv')]}, + data={'docUpload': [(BytesIO(bytes(csv_str, 'utf-8')), + 'example.csv')]}, status=200) assert "alert alert-info" in response @@ -594,8 +596,8 @@ def test_verify_stamp_erasure_certificate(user: UserClient, client: Client): item='stamps/', content_type='multipart/form-data', accept='text/html', - data={'docUpload': [(BytesIO(bytes(doc, 'utf-8')), - 'example.csv')]}, + data={'docUpload': [(BytesIO(bytes(doc, 'utf-8')), + 'example.csv')]}, status=200) assert "alert alert-danger" in response @@ -611,8 +613,8 @@ def test_verify_stamp_erasure_certificate(user: UserClient, client: Client): item='stamps/', content_type='multipart/form-data', accept='text/html', - data={'docUpload': [(BytesIO(doc), - 'example.csv')]}, + data={'docUpload': [(BytesIO(doc), + 'example.csv')]}, status=200) assert "alert alert-info" in response @@ -646,6 +648,7 @@ def test_get_document_internal_stats(user: UserClient, user2: UserClient): assert csv_str.strip() == '""' @pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) def test_get_wbconf(user: UserClient): """Tests for get env file for usb wb.""" @@ -655,3 +658,7 @@ def test_get_wbconf(user: UserClient): env, _ = user.get(res=documents.DocumentDef.t, item='wbconf/usodywipe', accept=ANY) assert 'WB_ERASE = False' in env # assert 'WB_ERASE = True' in env + + session = Session.query.filter_by(user_id=user.user['id'], + type=SessionType.Internal).first() + assert str(session.token) in env From 7ea3041aa064b26b6ca589558fc54bc1d4734367 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 14 Apr 2021 13:21:46 +0200 Subject: [PATCH 16/27] authorized up snapshots with new token --- tests/test_documents.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_documents.py b/tests/test_documents.py index 33f614a3..d3ad21a0 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -662,3 +662,5 @@ def test_get_wbconf(user: UserClient): session = Session.query.filter_by(user_id=user.user['id'], type=SessionType.Internal).first() assert str(session.token) in env + user.user['token'] = str(session.token) + snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) From 5cc64d2d28b3d3cadb29ec7073a27478200a8426 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 15 Apr 2021 21:16:04 +0200 Subject: [PATCH 17/27] fixing test --- tests/test_documents.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_documents.py b/tests/test_documents.py index d3ad21a0..7699b468 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -10,6 +10,7 @@ from werkzeug.exceptions import Unauthorized import teal.marshmallow from ereuse_utils.test import ANY +from ereuse_devicehub import auth from ereuse_devicehub.client import Client, UserClient from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.resources.user.models import Session @@ -647,6 +648,7 @@ def test_get_document_internal_stats(user: UserClient, user2: UserClient): assert csv_str.strip() == '""' + @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) def test_get_wbconf(user: UserClient): @@ -661,6 +663,8 @@ def test_get_wbconf(user: UserClient): session = Session.query.filter_by(user_id=user.user['id'], type=SessionType.Internal).first() - assert str(session.token) in env - user.user['token'] = str(session.token) + token = session.token + token = auth.Auth.encode(session.token) + assert token in env + user.user['token'] = token snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) From 9c489c75641d9a5e0fda273d51542338dfe42e68 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 15 Apr 2021 21:16:32 +0200 Subject: [PATCH 18/27] fixing create new users --- ereuse_devicehub/dummy/dummy.py | 6 ++++++ tests/conftest.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/ereuse_devicehub/dummy/dummy.py b/ereuse_devicehub/dummy/dummy.py index e83a3577..bcd0a595 100644 --- a/ereuse_devicehub/dummy/dummy.py +++ b/ereuse_devicehub/dummy/dummy.py @@ -17,6 +17,8 @@ from ereuse_devicehub.resources.device.models import Device from ereuse_devicehub.resources.lot.models import Lot from ereuse_devicehub.resources.tag.model import Tag from ereuse_devicehub.resources.user import User +from ereuse_devicehub.resources.user.models import Session +from ereuse_devicehub.resources.enums import SessionType class Dummy: @@ -193,6 +195,10 @@ class Dummy: user.individuals.add(Person(name=name)) db.session.add(user) + session_external = Session(user=user, type=SessionType.External) + session_internal = Session(user=user, type=SessionType.Internal) + db.session.add(session_internal) + db.session.add(session_external) db.session.commit() client = UserClient(self.app, user.email, password, diff --git a/tests/conftest.py b/tests/conftest.py index d0a0bdd2..4c45dc06 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,6 +17,8 @@ from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.resources.agent.models import Person from ereuse_devicehub.resources.tag import Tag from ereuse_devicehub.resources.user.models import User +from ereuse_devicehub.resources.user.models import Session +from ereuse_devicehub.resources.enums import SessionType STARTT = datetime(year=2000, month=1, day=1, hour=1) """A dummy starting time to use in tests.""" @@ -111,7 +113,11 @@ def user2(app: Devicehub) -> UserClient: def create_user(email='foo@foo.com', password='foo') -> User: user = User(email=email, password=password) user.individuals.add(Person(name='Timmy')) + session_external = Session(user=user, type=SessionType.External) + session_internal = Session(user=user, type=SessionType.Internal) db.session.add(user) + db.session.add(session_internal) + db.session.add(session_external) db.session.commit() return user From bae5a1d2b1910ffa6ebd569beb1721520efa7c17 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 15 Apr 2021 21:17:24 +0200 Subject: [PATCH 19/27] add session schema --- ereuse_devicehub/resources/user/schemas.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ereuse_devicehub/resources/user/schemas.py b/ereuse_devicehub/resources/user/schemas.py index e8d0d768..220e193b 100644 --- a/ereuse_devicehub/resources/user/schemas.py +++ b/ereuse_devicehub/resources/user/schemas.py @@ -9,6 +9,10 @@ from ereuse_devicehub.resources.inventory.schema import Inventory from ereuse_devicehub.resources.schemas import Thing +class Session(Thing): + token = String(dump_only=True) + + class User(Thing): id = UUID(dump_only=True) email = Email(required=True) From b3d77ba212d9f4d8da0009a4cc09ede9d70100c7 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 15 Apr 2021 21:18:15 +0200 Subject: [PATCH 20/27] fixing model and migration --- .../versions/21afd375a654_session_table.py | 13 +++++++++++-- ereuse_devicehub/resources/user/models.py | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/migrations/versions/21afd375a654_session_table.py b/ereuse_devicehub/migrations/versions/21afd375a654_session_table.py index da370152..4e121731 100644 --- a/ereuse_devicehub/migrations/versions/21afd375a654_session_table.py +++ b/ereuse_devicehub/migrations/versions/21afd375a654_session_table.py @@ -21,6 +21,7 @@ revision = '21afd375a654' down_revision = '6a2a939d5668' branch_labels = None depends_on = None +comment_update = 'The last time Devicehub recorded a change for this thing.\n' def get_inv(): @@ -29,10 +30,16 @@ def get_inv(): raise ValueError("Inventory value is not specified") return INV + def upgrade(): op.create_table('session', - sa.Column('updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='The last time Devicehub recorded a change for \n this thing.\n '), - sa.Column('created', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='When Devicehub created this.'), + sa.Column('updated', sa.TIMESTAMP(timezone=True), + server_default=sa.text('CURRENT_TIMESTAMP'), + nullable=False, + comment=comment_update), + sa.Column('created', sa.TIMESTAMP(timezone=True), + server_default=sa.text('CURRENT_TIMESTAMP'), + nullable=False, comment='When Devicehub created this.'), sa.Column('id', sa.BigInteger(), nullable=False), sa.Column('expired', sa.BigInteger(), nullable=True), sa.Column('token', postgresql.UUID(as_uuid=True), nullable=False), @@ -45,9 +52,11 @@ def upgrade(): ) op.create_index(op.f('ix_session_created'), 'session', ['created'], unique=False, schema='common') op.create_index(op.f('ix_session_updated'), 'session', ['updated'], unique=False, schema='common') + op.create_index(op.f('ix_session_token'), 'session', ['token'], unique=True, schema='common') def downgrade(): op.drop_table('trade', schema=f'{get_inv()}') op.drop_index(op.f('ix_session_created'), table_name='session', schema='common') op.drop_index(op.f('ix_session_updated'), table_name='session', schema='common') + op.drop_index(op.f('ix_session_token'), table_name='session', schema='common') diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index 324ee851..5923e35b 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -67,3 +67,9 @@ class Session(Thing): token = Column(UUID(as_uuid=True), default=uuid4, unique=True, nullable=False) type = Column(IntEnum(SessionType), default=SessionType.Internal, nullable=False) user_id = db.Column(db.UUID(as_uuid=True), db.ForeignKey(User.id)) + user = db.relationship(User, + backref=db.backref('sessions', lazy=True, collection_class=set), + collection_class=set) + + def __str__(self) -> str: + return '{0.token}'.format(self) From e1f8f89a9bbfd608fe7c24566c1aa3b6c9fff438 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 15 Apr 2021 21:19:20 +0200 Subject: [PATCH 21/27] fixing auth for token --- ereuse_devicehub/auth.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/auth.py b/ereuse_devicehub/auth.py index 5820c326..19f6e5fa 100644 --- a/ereuse_devicehub/auth.py +++ b/ereuse_devicehub/auth.py @@ -3,12 +3,17 @@ from teal.auth import TokenAuth from teal.db import ResourceNotFound from werkzeug.exceptions import Unauthorized -from ereuse_devicehub.resources.user.models import User +from ereuse_devicehub.resources.user.models import User, Session class Auth(TokenAuth): def authenticate(self, token: str, *args, **kw) -> User: try: - return User.query.filter_by(token=token).one() + user = User.query.filter_by(token=token).first() + if user: + return user + + ses = Session.query.filter_by(token=token).one() + return ses.user except (ResourceNotFound, DataError): raise Unauthorized('Provide a suitable token.') From 3f423e771253a64440772768b7854a4989698f16 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 15 Apr 2021 21:20:08 +0200 Subject: [PATCH 22/27] drop schema users for view --- ereuse_devicehub/resources/user/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ereuse_devicehub/resources/user/views.py b/ereuse_devicehub/resources/user/views.py index e6376f3c..b9638e24 100644 --- a/ereuse_devicehub/resources/user/views.py +++ b/ereuse_devicehub/resources/user/views.py @@ -7,7 +7,6 @@ from teal.resource import View from ereuse_devicehub.db import db from ereuse_devicehub.resources.user.exceptions import WrongCredentials from ereuse_devicehub.resources.user.models import User -from ereuse_devicehub.resources.user.schemas import User as UserS class UserView(View): From 70188f43a2cfd83ca42852b171483ce963ed11a5 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 15 Apr 2021 21:21:41 +0200 Subject: [PATCH 23/27] simplify get_token method --- .../resources/documents/documents.py | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 7175ab06..8796efa6 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -19,8 +19,8 @@ from flask.json import jsonify from teal.cache import cache from teal.resource import Resource, View +from ereuse_devicehub import auth from ereuse_devicehub.db import db -from ereuse_devicehub.resources.user.models import Session from ereuse_devicehub.resources.enums import SessionType from ereuse_devicehub.resources.action import models as evs from ereuse_devicehub.resources.device import models as devs @@ -339,26 +339,9 @@ class WbConfDocumentView(DeviceView): return output def get_token(self): - internal_session = Session.query.filter_by(user_id=g.user.id, - type=SessionType.Internal).first() - if not internal_session: - internal_session = Session(user_id=g.user.id, type=SessionType.Internal) - db.session.add(internal_session) - - db.session.commit() - return internal_session.token - - # TODO @cayop for when in others iterations we need implement external token - # external_session = Session.query.filter_by(user_id=g.user.id, - # type=SessionType.Internal).first() - # if not external_session: - # external_session = Session(user_id=g.user.id, type=SessionType.External) - # external_session = Session(user_id=g.user.id, type=SessionType.External) - # db.session.add(external_session) - - # db.session.commit() - - # return external_session.token + tk = [s.token for s in g.user.sessions if s.type == SessionType.Internal][0] + token = auth.Auth.encode(tk) + return token class DocumentDef(Resource): From 7836f2fc8d9a9414e8834d80b8337ba5df008af5 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 15 Apr 2021 21:23:02 +0200 Subject: [PATCH 24/27] drop pdbs --- tests/test_action.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_action.py b/tests/test_action.py index 2f0a1ea4..01d824ec 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -750,7 +750,6 @@ def test_deallocate_bad_dates(user: UserClient): def test_trade(action_model_state: Tuple[Type[models.Action], states.Trading], user: UserClient): """Tests POSTing all Trade actions.""" # todo missing None states.Trading for after cancelling renting, for example - # import pdb; pdb.set_trace() # Remove this test action_model, state = action_model_state snapshot, _ = user.post(file('basic.snapshot'), res=models.Snapshot) From 68ffa0ddffeb027863a9a9e1ff379bcd5e5d8b84 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 16 Apr 2021 11:14:36 +0200 Subject: [PATCH 25/27] fixing tests --- tests/files/basic.csv | 2 +- tests/files/proposal_extended_csv_report.csv | 6 +++--- tests/test_action.py | 10 +++++----- tests/test_documents.py | 1 + tests/test_snapshot.py | 5 +++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/files/basic.csv b/tests/files/basic.csv index c4962b4d..5255cd97 100644 --- a/tests/files/basic.csv +++ b/tests/files/basic.csv @@ -1,2 +1,2 @@ System ID;DocumentID;Public Link;Tag 1 Type;Tag 1 ID;Tag 1 Organization;Tag 2 Type;Tag 2 ID;Tag 2 Organization;Tag 3 Type;Tag 3 ID;Tag 3 Organization;Device Hardware ID;Device Type;Device Chassis;Device Serial Number;Device Model;Device Manufacturer;Registered in;Registered (process);Updated in (software);Updated in (web);Physical state;Trading state;Processor;RAM (MB);Data Storage Size (MB);Processor 1;Processor 1 Manufacturer;Processor 1 Model;Processor 1 Serial Number;Processor 1 Number of cores;Processor 1 Speed (GHz);Benchmark Processor 1 (points);Benchmark ProcessorSysbench Processor 1 (points);Processor 2;Processor 2 Manufacturer;Processor 2 Model;Processor 2 Serial Number;Processor 2 Number of cores;Processor 2 Speed (GHz);Benchmark Processor 2 (points);Benchmark ProcessorSysbench Processor 2 (points);RamModule 1;RamModule 1 Manufacturer;RamModule 1 Model;RamModule 1 Serial Number;RamModule 1 Size (MB);RamModule 1 Speed (MHz);RamModule 2;RamModule 2 Manufacturer;RamModule 2 Model;RamModule 2 Serial Number;RamModule 2 Size (MB);RamModule 2 Speed (MHz);RamModule 3;RamModule 3 Manufacturer;RamModule 3 Model;RamModule 3 Serial Number;RamModule 3 Size (MB);RamModule 3 Speed (MHz);RamModule 4;RamModule 4 Manufacturer;RamModule 4 Model;RamModule 4 Serial Number;RamModule 4 Size (MB);RamModule 4 Speed (MHz);DataStorage 1;DataStorage 1 Manufacturer;DataStorage 1 Model;DataStorage 1 Serial Number;DataStorage 1 Size (MB);Erasure DataStorage 1;Erasure DataStorage 1 Serial Number;Erasure DataStorage 1 Size (MB);Erasure DataStorage 1 Software;Erasure DataStorage 1 Result;Erasure DataStorage 1 Type;Erasure DataStorage 1 Method;Erasure DataStorage 1 Elapsed (hours);Erasure DataStorage 1 Date;Erasure DataStorage 1 Steps;Erasure DataStorage 1 Steps Start Time;Erasure DataStorage 1 Steps End Time;Benchmark DataStorage 1 Read Speed (MB/s);Benchmark DataStorage 1 Writing speed (MB/s);Test DataStorage 1 Software;Test DataStorage 1 Type;Test DataStorage 1 Result;Test DataStorage 1 Power on (hours used);Test DataStorage 1 Lifetime remaining (percentage);DataStorage 2;DataStorage 2 Manufacturer;DataStorage 2 Model;DataStorage 2 Serial Number;DataStorage 2 Size (MB);Erasure DataStorage 2;Erasure DataStorage 2 Serial Number;Erasure DataStorage 2 Size (MB);Erasure DataStorage 2 Software;Erasure DataStorage 2 Result;Erasure DataStorage 2 Type;Erasure DataStorage 2 Method;Erasure DataStorage 2 Elapsed (hours);Erasure DataStorage 2 Date;Erasure DataStorage 2 Steps;Erasure DataStorage 2 Steps Start Time;Erasure DataStorage 2 Steps End Time;Benchmark DataStorage 2 Read Speed (MB/s);Benchmark DataStorage 2 Writing speed (MB/s);Test DataStorage 2 Software;Test DataStorage 2 Type;Test DataStorage 2 Result;Test DataStorage 2 Power on (hours used);Test DataStorage 2 Lifetime remaining (percentage);DataStorage 3;DataStorage 3 Manufacturer;DataStorage 3 Model;DataStorage 3 Serial Number;DataStorage 3 Size (MB);Erasure DataStorage 3;Erasure DataStorage 3 Serial Number;Erasure DataStorage 3 Size (MB);Erasure DataStorage 3 Software;Erasure DataStorage 3 Result;Erasure DataStorage 3 Type;Erasure DataStorage 3 Method;Erasure DataStorage 3 Elapsed (hours);Erasure DataStorage 3 Date;Erasure DataStorage 3 Steps;Erasure DataStorage 3 Steps Start Time;Erasure DataStorage 3 Steps End Time;Benchmark DataStorage 3 Read Speed (MB/s);Benchmark DataStorage 3 Writing speed (MB/s);Test DataStorage 3 Software;Test DataStorage 3 Type;Test DataStorage 3 Result;Test DataStorage 3 Power on (hours used);Test DataStorage 3 Lifetime remaining (percentage);DataStorage 4;DataStorage 4 Manufacturer;DataStorage 4 Model;DataStorage 4 Serial Number;DataStorage 4 Size (MB);Erasure DataStorage 4;Erasure DataStorage 4 Serial Number;Erasure DataStorage 4 Size (MB);Erasure DataStorage 4 Software;Erasure DataStorage 4 Result;Erasure DataStorage 4 Type;Erasure DataStorage 4 Method;Erasure DataStorage 4 Elapsed (hours);Erasure DataStorage 4 Date;Erasure DataStorage 4 Steps;Erasure DataStorage 4 Steps Start Time;Erasure DataStorage 4 Steps End Time;Benchmark DataStorage 4 Read Speed (MB/s);Benchmark DataStorage 4 Writing speed (MB/s);Test DataStorage 4 Software;Test DataStorage 4 Type;Test DataStorage 4 Result;Test DataStorage 4 Power on (hours used);Test DataStorage 4 Lifetime remaining (percentage);Motherboard 1;Motherboard 1 Manufacturer;Motherboard 1 Model;Motherboard 1 Serial Number;Display 1;Display 1 Manufacturer;Display 1 Model;Display 1 Serial Number;GraphicCard 1;GraphicCard 1 Manufacturer;GraphicCard 1 Model;GraphicCard 1 Serial Number;GraphicCard 1 Memory (MB);GraphicCard 2;GraphicCard 2 Manufacturer;GraphicCard 2 Model;GraphicCard 2 Serial Number;GraphicCard 2 Memory (MB);NetworkAdapter 1;NetworkAdapter 1 Manufacturer;NetworkAdapter 1 Model;NetworkAdapter 1 Serial Number;NetworkAdapter 2;NetworkAdapter 2 Manufacturer;NetworkAdapter 2 Model;NetworkAdapter 2 Serial Number;SoundCard 1;SoundCard 1 Manufacturer;SoundCard 1 Model;SoundCard 1 Serial Number;SoundCard 2;SoundCard 2 Manufacturer;SoundCard 2 Model;SoundCard 2 Serial Number;Device Rate;Device Range;Processor Rate;Processor Range;RAM Rate;RAM Range;Data Storage Rate;Data Storage Range;Price;Benchmark RamSysbench (points) -1;;http://localhost/devices/1;;;;;;;;;;desktop-d1mr-d1ml-d1s;Desktop;Microtower;d1s;d1ml;d1mr;Thu Oct 22 15:36:47 2020;Workbench 11.0;2020-10-22 15:36:47.814316+02:00;;;;p1ml;0;0;Processor 4: model p1ml, S/N p1s;p1mr;p1ml;p1s;;1.6;2410.0;;;;;;;;;;RamModule 3: model rm1ml, S/N rm1s;rm1mr;rm1ml;rm1s;;1333;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GraphicCard 2: model gc1ml, S/N gc1s;gc1mr;gc1ml;gc1s;;;;;;;;;;;;;;;;;;;;;;;1.0;VERY_LOW;1.0;VERY_LOW;1.0;VERY_LOW;1.0;VERY_LOW;; +3;;http://localhost/devices/3;;;;;;;;;;desktop-d1mr-d1ml-d1s;Desktop;Microtower;d1s;d1ml;d1mr;Fri Apr 16 10:34:18 2021;Workbench 11.0;2021-04-16 10:34:18.540027+02:00;;;;p1ml;0;0;Processor 6: model p1ml, S/N p1s;p1mr;p1ml;p1s;;1.6;2410.0;;;;;;;;;;RamModule 5: model rm1ml, S/N rm1s;rm1mr;rm1ml;rm1s;;1333;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GraphicCard 4: model gc1ml, S/N gc1s;gc1mr;gc1ml;gc1s;;;;;;;;;;;;;;;;;;;;;;;1.0;VERY_LOW;1.0;VERY_LOW;1.0;VERY_LOW;1.0;VERY_LOW;; diff --git a/tests/files/proposal_extended_csv_report.csv b/tests/files/proposal_extended_csv_report.csv index cf1e88a7..3d0356bd 100644 --- a/tests/files/proposal_extended_csv_report.csv +++ b/tests/files/proposal_extended_csv_report.csv @@ -1,3 +1,3 @@ -System ID;DocumentID;Public Link;Tag 1 Type;Tag 1 ID;Tag 1 Organization;Tag 2 Type;Tag 2 ID;Tag 2 Organization;Tag 3 Type;Tag 3 ID;Tag 3 Organization;Device Hardware ID;Device Type;Device Chassis;Device Serial Number;Device Model;Device Manufacturer;Registered in;Registered (process);Updated in (software);Updated in (web);Physical state;Trading state;Processor;RAM (MB);Data Storage Size (MB);Processor 1;Processor 1 Manufacturer;Processor 1 Model;Processor 1 Serial Number;Processor 1 Number of cores;Processor 1 Speed (GHz);Benchmark Processor 1 (points);Benchmark ProcessorSysbench Processor 1 (points);Processor 2;Processor 2 Manufacturer;Processor 2 Model;Processor 2 Serial Number;Processor 2 Number of cores;Processor 2 Speed (GHz);Benchmark Processor 2 (points);Benchmark ProcessorSysbench Processor 2 (points);RamModule 1;RamModule 1 Manufacturer;RamModule 1 Model;RamModule 1 Serial Number;RamModule 1 Size (MB);RamModule 1 Speed (MHz);RamModule 2;RamModule 2 Manufacturer;RamModule 2 Model;RamModule 2 Serial Number;RamModule 2 Size (MB);RamModule 2 Speed (MHz);RamModule 3;RamModule 3 Manufacturer;RamModule 3 Model;RamModule 3 Serial Number;RamModule 3 Size (MB);RamModule 3 Speed (MHz);RamModule 4;RamModule 4 Manufacturer;RamModule 4 Model;RamModule 4 Serial Number;RamModule 4 Size (MB);RamModule 4 Speed (MHz);DataStorage 1;DataStorage 1 Manufacturer;DataStorage 1 Model;DataStorage 1 Serial Number;DataStorage 1 Size (MB);Erasure DataStorage 1;Erasure DataStorage 1 Serial Number;Erasure DataStorage 1 Size (MB);Erasure DataStorage 1 Software;Erasure DataStorage 1 Result;Erasure DataStorage 1 Type;Erasure DataStorage 1 Method;Erasure DataStorage 1 Elapsed (hours);Erasure DataStorage 1 Date;Erasure DataStorage 1 Steps;Erasure DataStorage 1 Steps Start Time;Erasure DataStorage 1 Steps End Time;Benchmark DataStorage 1 Read Speed (MB/s);Benchmark DataStorage 1 Writing speed (MB/s);Test DataStorage 1 Software;Test DataStorage 1 Type;Test DataStorage 1 Result;Test DataStorage 1 Power on (hours used);Test DataStorage 1 Lifetime remaining (percentage);DataStorage 2;DataStorage 2 Manufacturer;DataStorage 2 Model;DataStorage 2 Serial Number;DataStorage 2 Size (MB);Erasure DataStorage 2;Erasure DataStorage 2 Serial Number;Erasure DataStorage 2 Size (MB);Erasure DataStorage 2 Software;Erasure DataStorage 2 Result;Erasure DataStorage 2 Type;Erasure DataStorage 2 Method;Erasure DataStorage 2 Elapsed (hours);Erasure DataStorage 2 Date;Erasure DataStorage 2 Steps;Erasure DataStorage 2 Steps Start Time;Erasure DataStorage 2 Steps End Time;Benchmark DataStorage 2 Read Speed (MB/s);Benchmark DataStorage 2 Writing speed (MB/s);Test DataStorage 2 Software;Test DataStorage 2 Type;Test DataStorage 2 Result;Test DataStorage 2 Power on (hours used);Test DataStorage 2 Lifetime remaining (percentage);DataStorage 3;DataStorage 3 Manufacturer;DataStorage 3 Model;DataStorage 3 Serial Number;DataStorage 3 Size (MB);Erasure DataStorage 3;Erasure DataStorage 3 Serial Number;Erasure DataStorage 3 Size (MB);Erasure DataStorage 3 Software;Erasure DataStorage 3 Result;Erasure DataStorage 3 Type;Erasure DataStorage 3 Method;Erasure DataStorage 3 Elapsed (hours);Erasure DataStorage 3 Date;Erasure DataStorage 3 Steps;Erasure DataStorage 3 Steps Start Time;Erasure DataStorage 3 Steps End Time;Benchmark DataStorage 3 Read Speed (MB/s);Benchmark DataStorage 3 Writing speed (MB/s);Test DataStorage 3 Software;Test DataStorage 3 Type;Test DataStorage 3 Result;Test DataStorage 3 Power on (hours used);Test DataStorage 3 Lifetime remaining (percentage);DataStorage 4;DataStorage 4 Manufacturer;DataStorage 4 Model;DataStorage 4 Serial Number;DataStorage 4 Size (MB);Erasure DataStorage 4;Erasure DataStorage 4 Serial Number;Erasure DataStorage 4 Size (MB);Erasure DataStorage 4 Software;Erasure DataStorage 4 Result;Erasure DataStorage 4 Type;Erasure DataStorage 4 Method;Erasure DataStorage 4 Elapsed (hours);Erasure DataStorage 4 Date;Erasure DataStorage 4 Steps;Erasure DataStorage 4 Steps Start Time;Erasure DataStorage 4 Steps End Time;Benchmark DataStorage 4 Read Speed (MB/s);Benchmark DataStorage 4 Writing speed (MB/s);Test DataStorage 4 Software;Test DataStorage 4 Type;Test DataStorage 4 Result;Test DataStorage 4 Power on (hours used);Test DataStorage 4 Lifetime remaining (percentage);Motherboard 1;Motherboard 1 Manufacturer;Motherboard 1 Model;Motherboard 1 Serial Number;Display 1;Display 1 Manufacturer;Display 1 Model;Display 1 Serial Number;GraphicCard 1;GraphicCard 1 Manufacturer;GraphicCard 1 Model;GraphicCard 1 Serial Number;GraphicCard 1 Memory (MB);GraphicCard 2;GraphicCard 2 Manufacturer;GraphicCard 2 Model;GraphicCard 2 Serial Number;GraphicCard 2 Memory (MB);NetworkAdapter 1;NetworkAdapter 1 Manufacturer;NetworkAdapter 1 Model;NetworkAdapter 1 Serial Number;NetworkAdapter 2;NetworkAdapter 2 Manufacturer;NetworkAdapter 2 Model;NetworkAdapter 2 Serial Number;SoundCard 1;SoundCard 1 Manufacturer;SoundCard 1 Model;SoundCard 1 Serial Number;SoundCard 2;SoundCard 2 Manufacturer;SoundCard 2 Model;SoundCard 2 Serial Number;Device Rate;Device Range;Processor Rate;Processor Range;RAM Rate;RAM Range;Data Storage Rate;Data Storage Range;Price;Benchmark RamSysbench (points) -1;;http://localhost/devices/1;named;foo;FooOrg;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048285-14:da:e9:42:f6:7b;Laptop;Netbook;b8oaas048285;1001pxd;asustek computer inc.;Thu Nov 12 19:53:01 2020;Workbench 11.0a2;2020-11-12 19:54:03.959185+01:00;;;;intel atom cpu n455 @ 2.66ghz;1024;238475;Processor 4: model intel atom cpu n455 @ 2.66ghz, S/N None;intel corp.;intel atom cpu n455 @ 2.66ghz;;1;2.667;6666.24;164.0803;;;;;;;;;RamModule 8: model None, S/N None;;;;1024;667;;;;;;;;;;;;;;;;;;;HardDrive 9: model hts54322, S/N e2024242cv86mm;hitachi;hts54322;e2024242cv86mm;238475;harddrive-hitachi-hts54322-e2024242cv86mm;e2024242cv86mm;238475;Workbench 11.0a2;Success;EraseBasic;Shred;1:16:49;2020-11-12 19:53:01.899092+01:00;✓ – StepRandom 1:16:49;2018-07-03 11:15:22.257059+02:00;2018-07-03 12:32:11.843190+02:00;66.2;21.8;Workbench 11.0a2;Short;Failure;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 10: model 1001pxd, S/N eee0123456720;asustek computer inc.;1001pxd;eee0123456720;;;;;GraphicCard 5: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None;intel corporation;atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller;;256;;;;;;NetworkAdapter 2: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c9;qualcomm atheros;ar9285 wireless network adapter;74:2f:68:8b:fd:c9;NetworkAdapter 3: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7b;qualcomm atheros;ar8152 v2.0 fast ethernet;14:da:e9:42:f6:7b;SoundCard 6: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;;;;;1.75;LOW;1.55;LOW;1.53;LOW;3.76;HIGH;52.50 €;15.7188 -11;;http://localhost/devices/11;;;;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048287-14:da:e9:42:f6:7c;Laptop;Netbook;b8oaas048287;1001pxd;asustek computer inc.;Thu Nov 12 19:53:02 2020;Workbench 11.0b11;2020-11-12 19:53:02.225373+01:00;;;;intel atom cpu n455 @ 1.66ghz;2048;558558;Processor 15: model intel atom cpu n455 @ 1.66ghz, S/N None;intel corp.;intel atom cpu n455 @ 1.66ghz;;1;1.667;6666.24;164.0803;;;;;;;;;RamModule 18: model None, S/N None;;;;1024;667;RamModule 19: model 48594d503131325336344350362d53362020, S/N 4f43487b;hynix semiconductor;48594d503131325336344350362d53362020;4f43487b;1024;667;;;;;;;;;;;;;HardDrive 20: model hts54322, S/N e2024242cv86hj;hitachi;hts54322;e2024242cv86hj;238475;harddrive-hitachi-hts54322-e2024242cv86hj;e2024242cv86hj;238475;Workbench 11.0b11;Success;EraseBasic;Shred;1:16:49;2020-11-12 19:53:02.175189+01:00;✓ – StepRandom 1:16:49;2018-07-03 11:15:22.257059+02:00;2018-07-03 12:32:11.843190+02:00;66.2;21.8;Workbench 11.0b11;Extended;Failure;;;DataStorage 21: model wdc wd1600bevt-2, S/N wd-wx11a80w7430;western digital;wdc wd1600bevt-2;wd-wx11a80w7430;160041;datastorage-western_digital-wdc_wd1600bevt-2-wd-wx11a80w7430;wd-wx11a80w7430;160041;Workbench 11.0b11;Failure;EraseBasic;Shred;0:45:36;2020-11-12 19:53:02.176882+01:00;✓ – StepRandom 0:45:36;2019-10-23 09:49:54.410830+02:00;2019-10-23 10:35:31.400587+02:00;41.6;17.3;Workbench 11.0b11;Short;Success;5293;195 days, 12:00:00;SolidStateDrive 22: model wdc wd1600bevt-2, S/N wd-wx11a80w7430;western digital;wdc wd1600bevt-2;wd-wx11a80w7430;160042;solidstatedrive-western_digital-wdc_wd1600bevt-2-wd-wx11a80w7430;wd-wx11a80w7430;160042;Workbench 11.0b11;Success;EraseSectors;Badblocks;1:46:03;2020-11-12 19:53:02.180043+01:00;✓ – StepRandom 0:46:03,✓ – StepZero 1:00:00;2019-08-19 18:48:19.690458+02:00,2019-08-19 19:34:22.690458+02:00;2019-08-19 19:34:22.930562+02:00,2019-08-19 20:34:22.930562+02:00;41.1;17.1;Workbench 11.0b11;Short;Success;5231;194 days, 17:00:00;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 23: model 1001pxd, S/N eee0123456789;asustek computer inc.;1001pxd;eee0123456789;;"auo ""auo""";auo lcd monitor;;GraphicCard 16: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None;intel corporation;atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller;;256;;;;;;NetworkAdapter 13: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c8;qualcomm atheros;ar9285 wireless network adapter;74:2f:68:8b:fd:c8;NetworkAdapter 14: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7c;qualcomm atheros;ar8152 v2.0 fast ethernet;14:da:e9:42:f6:7c;SoundCard 7: model usb 2.0 uvc vga webcam, S/N 0x0001;azurewave;usb 2.0 uvc vga webcam;0x0001;SoundCard 17: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;1.72;LOW;1.31;LOW;1.99;LOW;3.97;HIGH;51.60 €;15.7188 +System ID;DocumentID;Public Link;Tag 1 Type;Tag 1 ID;Tag 1 Organization;Tag 2 Type;Tag 2 ID;Tag 2 Organization;Tag 3 Type;Tag 3 ID;Tag 3 Organization;Device Hardware ID;Device Type;Device Chassis;Device Serial Number;Device Model;Device Manufacturer;Registered in;Registered (process);Updated in (software);Updated in (web);Physical state;Trading state;Processor;RAM (MB);Data Storage Size (MB);Processor 1;Processor 1 Manufacturer;Processor 1 Model;Processor 1 Serial Number;Processor 1 Number of cores;Processor 1 Speed (GHz);Benchmark Processor 1 (points);Benchmark ProcessorSysbench Processor 1 (points);Processor 2;Processor 2 Manufacturer;Processor 2 Model;Processor 2 Serial Number;Processor 2 Number of cores;Processor 2 Speed (GHz);Benchmark Processor 2 (points);Benchmark ProcessorSysbench Processor 2 (points);RamModule 1;RamModule 1 Manufacturer;RamModule 1 Model;RamModule 1 Serial Number;RamModule 1 Size (MB);RamModule 1 Speed (MHz);RamModule 2;RamModule 2 Manufacturer;RamModule 2 Model;RamModule 2 Serial Number;RamModule 2 Size (MB);RamModule 2 Speed (MHz);RamModule 3;RamModule 3 Manufacturer;RamModule 3 Model;RamModule 3 Serial Number;RamModule 3 Size (MB);RamModule 3 Speed (MHz);RamModule 4;RamModule 4 Manufacturer;RamModule 4 Model;RamModule 4 Serial Number;RamModule 4 Size (MB);RamModule 4 Speed (MHz);DataStorage 1;DataStorage 1 Manufacturer;DataStorage 1 Model;DataStorage 1 Serial Number;DataStorage 1 Size (MB);Erasure DataStorage 1;Erasure DataStorage 1 Serial Number;Erasure DataStorage 1 Size (MB);Erasure DataStorage 1 Software;Erasure DataStorage 1 Result;Erasure DataStorage 1 Type;Erasure DataStorage 1 Method;Erasure DataStorage 1 Elapsed (hours);Erasure DataStorage 1 Date;Erasure DataStorage 1 Steps;Erasure DataStorage 1 Steps Start Time;Erasure DataStorage 1 Steps End Time;Benchmark DataStorage 1 Read Speed (MB/s);Benchmark DataStorage 1 Writing speed (MB/s);Test DataStorage 1 Software;Test DataStorage 1 Type;Test DataStorage 1 Result;Test DataStorage 1 Power on (hours used);Test DataStorage 1 Lifetime remaining (percentage);DataStorage 2;DataStorage 2 Manufacturer;DataStorage 2 Model;DataStorage 2 Serial Number;DataStorage 2 Size (MB);Erasure DataStorage 2;Erasure DataStorage 2 Serial Number;Erasure DataStorage 2 Size (MB);Erasure DataStorage 2 Software;Erasure DataStorage 2 Result;Erasure DataStorage 2 Type;Erasure DataStorage 2 Method;Erasure DataStorage 2 Elapsed (hours);Erasure DataStorage 2 Date;Erasure DataStorage 2 Steps;Erasure DataStorage 2 Steps Start Time;Erasure DataStorage 2 Steps End Time;Benchmark DataStorage 2 Read Speed (MB/s);Benchmark DataStorage 2 Writing speed (MB/s);Test DataStorage 2 Software;Test DataStorage 2 Type;Test DataStorage 2 Result;Test DataStorage 2 Power on (hours used);Test DataStorage 2 Lifetime remaining (percentage);DataStorage 3;DataStorage 3 Manufacturer;DataStorage 3 Model;DataStorage 3 Serial Number;DataStorage 3 Size (MB);Erasure DataStorage 3;Erasure DataStorage 3 Serial Number;Erasure DataStorage 3 Size (MB);Erasure DataStorage 3 Software;Erasure DataStorage 3 Result;Erasure DataStorage 3 Type;Erasure DataStorage 3 Method;Erasure DataStorage 3 Elapsed (hours);Erasure DataStorage 3 Date;Erasure DataStorage 3 Steps;Erasure DataStorage 3 Steps Start Time;Erasure DataStorage 3 Steps End Time;Benchmark DataStorage 3 Read Speed (MB/s);Benchmark DataStorage 3 Writing speed (MB/s);Test DataStorage 3 Software;Test DataStorage 3 Type;Test DataStorage 3 Result;Test DataStorage 3 Power on (hours used);Test DataStorage 3 Lifetime remaining (percentage);DataStorage 4;DataStorage 4 Manufacturer;DataStorage 4 Model;DataStorage 4 Serial Number;DataStorage 4 Size (MB);Erasure DataStorage 4;Erasure DataStorage 4 Serial Number;Erasure DataStorage 4 Size (MB);Erasure DataStorage 4 Software;Erasure DataStorage 4 Result;Erasure DataStorage 4 Type;Erasure DataStorage 4 Method;Erasure DataStorage 4 Elapsed (hours);Erasure DataStorage 4 Date;Erasure DataStorage 4 Steps;Erasure DataStorage 4 Steps Start Time;Erasure DataStorage 4 Steps End Time;Benchmark DataStorage 4 Read Speed (MB/s);Benchmark DataStorage 4 Writing speed (MB/s);Test DataStorage 4 Software;Test DataStorage 4 Type;Test DataStorage 4 Result;Test DataStorage 4 Power on (hours used);Test DataStorage 4 Lifetime remaining (percentage);Motherboard 1;Motherboard 1 Manufacturer;Motherboard 1 Model;Motherboard 1 Serial Number;Display 1;Display 1 Manufacturer;Display 1 Model;Display 1 Serial Number;GraphicCard 1;GraphicCard 1 Manufacturer;GraphicCard 1 Model;GraphicCard 1 Serial Number;GraphicCard 1 Memory (MB);GraphicCard 2;GraphicCard 2 Manufacturer;GraphicCard 2 Model;GraphicCard 2 Serial Number;GraphicCard 2 Memory (MB);NetworkAdapter 1;NetworkAdapter 1 Manufacturer;NetworkAdapter 1 Model;NetworkAdapter 1 Serial Number;NetworkAdapter 2;NetworkAdapter 2 Manufacturer;NetworkAdapter 2 Model;NetworkAdapter 2 Serial Number;SoundCard 1;SoundCard 1 Manufacturer;SoundCard 1 Model;SoundCard 1 Serial Number;SoundCard 2;SoundCard 2 Manufacturer;SoundCard 2 Model;SoundCard 2 Serial Number;Device Rate;Device Range;Processor Rate;Processor Range;RAM Rate;RAM Range;Data Storage Rate;Data Storage Range;Price;Benchmark RamSysbench (points) +3;;http://localhost/devices/3;named;foo;FooOrg;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048285-14:da:e9:42:f6:7b;Laptop;Netbook;b8oaas048285;1001pxd;asustek computer inc.;Fri Apr 16 10:42:21 2021;Workbench 11.0a2;2021-04-16 10:42:21.737031+02:00;;;;intel atom cpu n455 @ 2.66ghz;1024;238475;Processor 6: model intel atom cpu n455 @ 2.66ghz, S/N None;intel corp.;intel atom cpu n455 @ 2.66ghz;;1;2.667;6666.24;164.0803;;;;;;;;;RamModule 10: model None, S/N None;;;;1024;667;;;;;;;;;;;;;;;;;;;HardDrive 11: model hts54322, S/N e2024242cv86mm;hitachi;hts54322;e2024242cv86mm;238475;harddrive-hitachi-hts54322-e2024242cv86mm;e2024242cv86mm;238475;Workbench 11.0a2;Success;EraseBasic;Shred;1:16:49;2021-04-16 10:42:21.171908+02:00;✓ – StepRandom 1:16:49;2018-07-03 11:15:22.257059+02:00;2018-07-03 12:32:11.843190+02:00;66.2;21.8;Workbench 11.0a2;Short;Failure;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 12: model 1001pxd, S/N eee0123456720;asustek computer inc.;1001pxd;eee0123456720;;;;;GraphicCard 7: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None;intel corporation;atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller;;256;;;;;;NetworkAdapter 4: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c9;qualcomm atheros;ar9285 wireless network adapter;74:2f:68:8b:fd:c9;NetworkAdapter 5: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7b;qualcomm atheros;ar8152 v2.0 fast ethernet;14:da:e9:42:f6:7b;SoundCard 8: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;;;;;1.75;LOW;1.55;LOW;1.53;LOW;3.76;HIGH;52.50 €;15.7188 +13;;http://localhost/devices/13;;;;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048287-14:da:e9:42:f6:7c;Laptop;Netbook;b8oaas048287;1001pxd;asustek computer inc.;Fri Apr 16 10:42:21 2021;Workbench 11.0b11;2021-04-16 10:42:21.565046+02:00;;;;intel atom cpu n455 @ 1.66ghz;2048;558558;Processor 17: model intel atom cpu n455 @ 1.66ghz, S/N None;intel corp.;intel atom cpu n455 @ 1.66ghz;;1;1.667;6666.24;164.0803;;;;;;;;;RamModule 20: model None, S/N None;;;;1024;667;RamModule 21: model 48594d503131325336344350362d53362020, S/N 4f43487b;hynix semiconductor;48594d503131325336344350362d53362020;4f43487b;1024;667;;;;;;;;;;;;;HardDrive 22: model hts54322, S/N e2024242cv86hj;hitachi;hts54322;e2024242cv86hj;238475;harddrive-hitachi-hts54322-e2024242cv86hj;e2024242cv86hj;238475;Workbench 11.0b11;Success;EraseBasic;Shred;1:16:49;2021-04-16 10:42:21.496034+02:00;✓ – StepRandom 1:16:49;2018-07-03 11:15:22.257059+02:00;2018-07-03 12:32:11.843190+02:00;66.2;21.8;Workbench 11.0b11;Extended;Failure;;;DataStorage 23: model wdc wd1600bevt-2, S/N wd-wx11a80w7430;western digital;wdc wd1600bevt-2;wd-wx11a80w7430;160041;datastorage-western_digital-wdc_wd1600bevt-2-wd-wx11a80w7430;wd-wx11a80w7430;160041;Workbench 11.0b11;Failure;EraseBasic;Shred;0:45:36;2021-04-16 10:42:21.498207+02:00;✓ – StepRandom 0:45:36;2019-10-23 09:49:54.410830+02:00;2019-10-23 10:35:31.400587+02:00;41.6;17.3;Workbench 11.0b11;Short;Success;5293;195 days, 12:00:00;SolidStateDrive 24: model wdc wd1600bevt-2, S/N wd-wx11a80w7430;western digital;wdc wd1600bevt-2;wd-wx11a80w7430;160042;solidstatedrive-western_digital-wdc_wd1600bevt-2-wd-wx11a80w7430;wd-wx11a80w7430;160042;Workbench 11.0b11;Success;EraseSectors;Badblocks;1:46:03;2021-04-16 10:42:21.503229+02:00;✓ – StepRandom 0:46:03,✓ – StepZero 1:00:00;2019-08-19 18:48:19.690458+02:00,2019-08-19 19:34:22.690458+02:00;2019-08-19 19:34:22.930562+02:00,2019-08-19 20:34:22.930562+02:00;41.1;17.1;Workbench 11.0b11;Short;Success;5231;194 days, 17:00:00;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 25: model 1001pxd, S/N eee0123456789;asustek computer inc.;1001pxd;eee0123456789;;"auo ""auo""";auo lcd monitor;;GraphicCard 18: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None;intel corporation;atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller;;256;;;;;;NetworkAdapter 15: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c8;qualcomm atheros;ar9285 wireless network adapter;74:2f:68:8b:fd:c8;NetworkAdapter 16: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7c;qualcomm atheros;ar8152 v2.0 fast ethernet;14:da:e9:42:f6:7c;SoundCard 9: model usb 2.0 uvc vga webcam, S/N 0x0001;azurewave;usb 2.0 uvc vga webcam;0x0001;SoundCard 19: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;1.72;LOW;1.31;LOW;1.99;LOW;3.97;HIGH;51.60 €;15.7188 diff --git a/tests/test_action.py b/tests/test_action.py index 01d824ec..ee784372 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -382,7 +382,7 @@ def test_live_without_TestDataStorage(user: UserClient, client: Client, app: Dev acer = file('acer.happy.battery.snapshot') snapshot, _ = user.post(acer, res=models.Snapshot) device_id = snapshot['device']['id'] - db_device = Device.query.filter_by(id=1).one() + db_device = Device.query.filter_by(id=device_id).one() post_request = {"transaction": "ccc", "name": "John", "endUsers": 1, "devices": [device_id], "description": "aaa", "finalUserCode": "abcdefjhi", @@ -415,7 +415,7 @@ def test_live_without_hdd_1(user: UserClient, client: Client, app: Devicehub): acer = file('acer.happy.battery.snapshot') snapshot, _ = user.post(acer, res=models.Snapshot) device_id = snapshot['device']['id'] - db_device = Device.query.filter_by(id=1).one() + db_device = Device.query.filter_by(id=device_id).one() post_request = {"transaction": "ccc", "name": "John", "endUsers": 1, "devices": [device_id], "description": "aaa", "finalUserCode": "abcdefjhi", @@ -446,7 +446,7 @@ def test_live_without_hdd_2(user: UserClient, client: Client, app: Devicehub): acer['components'] = components snapshot, _ = user.post(acer, res=models.Snapshot) device_id = snapshot['device']['id'] - db_device = Device.query.filter_by(id=1).one() + db_device = Device.query.filter_by(id=device_id).one() post_request = {"transaction": "ccc", "name": "John", "endUsers": 1, "devices": [device_id], "description": "aaa", "finalUserCode": "abcdefjhi", @@ -477,7 +477,7 @@ def test_live_without_hdd_3(user: UserClient, client: Client, app: Devicehub): acer['components'] = components snapshot, _ = user.post(acer, res=models.Snapshot) device_id = snapshot['device']['id'] - db_device = Device.query.filter_by(id=1).one() + db_device = Device.query.filter_by(id=device_id).one() post_request = {"transaction": "ccc", "name": "John", "endUsers": 1, "devices": [device_id], "description": "aaa", "finalUserCode": "abcdefjhi", @@ -510,7 +510,7 @@ def test_live_with_hdd_with_old_time(user: UserClient, client: Client, app: Devi acer = file('acer.happy.battery.snapshot') snapshot, _ = user.post(acer, res=models.Snapshot) device_id = snapshot['device']['id'] - db_device = Device.query.filter_by(id=1).one() + db_device = Device.query.filter_by(id=device_id).one() post_request = {"transaction": "ccc", "name": "John", "endUsers": 1, "devices": [device_id], "description": "aaa", "finalUserCode": "abcdefjhi", diff --git a/tests/test_documents.py b/tests/test_documents.py index 7699b468..fe254b33 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -265,6 +265,7 @@ def test_export_extended(app: Devicehub, user: UserClient): pc.tags.add(tag) db.session.add(pc) db.session.commit() + csv_str, _ = user.get(res=documents.DocumentDef.t, item='devices/', accept='text/csv', diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index a653e95b..ac0f65be 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -37,6 +37,7 @@ from tests import conftest @pytest.mark.mvp @pytest.mark.usefixtures('auth_app_context') +# cayop def test_snapshot_model(): """Tests creating a Snapshot with its relationships ensuring correct DB mapping. @@ -63,7 +64,7 @@ def test_snapshot_model(): assert m.Desktop.query.one_or_none() is None assert m.Device.query.one_or_none() is None # Check properties - assert device.url == urlutils.URL('http://localhost/devices/1') + assert device.url == urlutils.URL('http://localhost/devices/3') @pytest.mark.mvp @@ -315,7 +316,7 @@ def test_snapshot_tag_inner_tag(user: UserClient, tag_id: str, app: Devicehub): action_types=(RateComputer.t, BenchmarkProcessor.t, VisualTest.t)) with app.app_context(): tag = Tag.query.one() # type: Tag - assert tag.device_id == 1, 'Tag should be linked to the first device' + assert tag.device_id == 3, 'Tag should be linked to the first device' @pytest.mark.mvp From 4122ac165e65d5dfb21bfdb66817d984b82d2175 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 16 Apr 2021 12:45:14 +0200 Subject: [PATCH 26/27] fixing tests --- tests/test_device.py | 149 ++++++++++++++++++++++--------------------- 1 file changed, 75 insertions(+), 74 deletions(-) diff --git a/tests/test_device.py b/tests/test_device.py index 851698fb..510a3a37 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -65,13 +65,13 @@ def test_device_model(): gcard = d.GraphicCard.query.one() db.session.delete(pc) db.session.flush() - assert pc.id == 1 + assert pc.id == 3 assert d.Desktop.query.first() is None db.session.commit() assert d.Desktop.query.first() is None - assert network_adapter.id == 2 + assert network_adapter.id == 4 assert d.NetworkAdapter.query.first() is not None, 'We removed the network adaptor' - assert gcard.id == 3, 'We should still hold a reference to a zombie graphic card' + assert gcard.id == 5, 'We should still hold a reference to a zombie graphic card' assert d.GraphicCard.query.first() is None, 'We should have deleted it –it was inside the pc' @@ -396,72 +396,73 @@ def test_sync_execute_register_mismatch_between_tags_and_hid(): @pytest.mark.mvp -def test_get_device(app: Devicehub, user: UserClient): +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_get_device(user: UserClient): """Checks GETting a d.Desktop with its components.""" - with app.app_context(): - pc = d.Desktop(model='p1mo', - manufacturer='p1ma', - serial_number='p1s', - chassis=ComputerChassis.Tower, - owner_id=user.user['id']) - pc.components = OrderedSet([ - d.NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s', - owner_id=user.user['id']), - d.GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500, owner_id=user.user['id']) - ]) - db.session.add(pc) - # todo test is an abstract class. replace with another one - db.session.add(TestConnectivity(device=pc, - severity=Severity.Info, - agent=Person(name='Timmy'), - author=User(email='bar@bar.com'))) - db.session.commit() - pc, _ = user.get(res=d.Device, item=1) - assert len(pc['actions']) == 1 - assert pc['actions'][0]['type'] == 'TestConnectivity' - assert pc['actions'][0]['device'] == 1 - assert pc['actions'][0]['severity'] == 'Info' - assert UUID(pc['actions'][0]['author']) - assert 'actions_components' not in pc, 'actions_components are internal use only' - assert 'actions_one' not in pc, 'they are internal use only' - assert 'author' not in pc - assert tuple(c['id'] for c in pc['components']) == (2, 3) - assert pc['hid'] == 'desktop-p1ma-p1mo-p1s' - assert pc['model'] == 'p1mo' - assert pc['manufacturer'] == 'p1ma' - assert pc['serialNumber'] == 'p1s' - assert pc['type'] == d.Desktop.t + pc = d.Desktop(model='p1mo', + manufacturer='p1ma', + serial_number='p1s', + chassis=ComputerChassis.Tower, + owner_id=user.user['id']) + pc.components = OrderedSet([ + d.NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s', + owner_id=user.user['id']), + d.GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500, owner_id=user.user['id']) + ]) + db.session.add(pc) + # todo test is an abstract class. replace with another one + db.session.add(TestConnectivity(device=pc, + severity=Severity.Info, + agent=Person(name='Timmy'), + author=User(email='bar@bar.com'))) + db.session.commit() + pc_api, _ = user.get(res=d.Device, item=pc.id) + assert len(pc_api['actions']) == 1 + assert pc_api['actions'][0]['type'] == 'TestConnectivity' + assert pc_api['actions'][0]['device'] == pc.id + assert pc_api['actions'][0]['severity'] == 'Info' + assert UUID(pc_api['actions'][0]['author']) + assert 'actions_components' not in pc_api, 'actions_components are internal use only' + assert 'actions_one' not in pc_api, 'they are internal use only' + assert 'author' not in pc_api + assert tuple(c['id'] for c in pc_api['components']) == tuple(c.id for c in pc.components) + assert pc_api['hid'] == 'desktop-p1ma-p1mo-p1s' + assert pc_api['model'] == 'p1mo' + assert pc_api['manufacturer'] == 'p1ma' + assert pc_api['serialNumber'] == 'p1s' + assert pc_api['type'] == d.Desktop.t @pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) def test_get_devices(app: Devicehub, user: UserClient): """Checks GETting multiple devices.""" - with app.app_context(): - pc = d.Desktop(model='p1mo', - manufacturer='p1ma', - serial_number='p1s', - chassis=ComputerChassis.Tower, - owner_id=user.user['id']) - pc.components = OrderedSet([ - d.NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s', - owner_id=user.user['id']), - d.GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500, - owner_id=user.user['id']) - ]) - pc1 = d.Desktop(model='p2mo', - manufacturer='p2ma', - serial_number='p2s', - chassis=ComputerChassis.Tower, - owner_id=user.user['id']) - pc2 = d.Laptop(model='p3mo', - manufacturer='p3ma', - serial_number='p3s', - chassis=ComputerChassis.Netbook, - owner_id=user.user['id']) - db.session.add_all((pc, pc1, pc2)) - db.session.commit() + pc = d.Desktop(model='p1mo', + manufacturer='p1ma', + serial_number='p1s', + chassis=ComputerChassis.Tower, + owner_id=user.user['id']) + pc.components = OrderedSet([ + d.NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s', + owner_id=user.user['id']), + d.GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500, + owner_id=user.user['id']) + ]) + pc1 = d.Desktop(model='p2mo', + manufacturer='p2ma', + serial_number='p2s', + chassis=ComputerChassis.Tower, + owner_id=user.user['id']) + pc2 = d.Laptop(model='p3mo', + manufacturer='p3ma', + serial_number='p3s', + chassis=ComputerChassis.Netbook, + owner_id=user.user['id']) + db.session.add_all((pc, pc1, pc2)) + db.session.commit() devices, _ = user.get(res=d.Device) - assert tuple(dev['id'] for dev in devices['items']) == (1, 2, 3, 4, 5) + ids = (pc.id, pc1.id, pc2.id, pc.components[0].id, pc.components[1].id) + assert tuple(dev['id'] for dev in devices['items']) == ids assert tuple(dev['type'] for dev in devices['items']) == ( d.Desktop.t, d.Desktop.t, d.Laptop.t, d.NetworkAdapter.t, d.GraphicCard.t ) @@ -534,7 +535,7 @@ def test_device_properties_format(app: Devicehub, user: UserClient): user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot) with app.app_context(): pc = d.Laptop.query.one() # type: d.Laptop - assert format(pc) == 'Laptop 1: model 1000h, S/N 94oaaq021116' + assert format(pc) == 'Laptop 3: model 1000h, S/N 94oaaq021116' assert format(pc, 't') == 'Netbook 1000h' assert format(pc, 's') == '(asustek computer inc.) S/N 94OAAQ021116' assert pc.ram_size == 1024 @@ -542,12 +543,12 @@ def test_device_properties_format(app: Devicehub, user: UserClient): assert pc.graphic_card_model == 'mobile 945gse express integrated graphics controller' assert pc.processor_model == 'intel atom cpu n270 @ 1.60ghz' net = next(c for c in pc.components if isinstance(c, d.NetworkAdapter)) - assert format(net) == 'NetworkAdapter 2: model ar8121/ar8113/ar8114 ' \ + assert format(net) == 'NetworkAdapter 4: model ar8121/ar8113/ar8114 ' \ 'gigabit or fast ethernet, S/N 00:24:8c:7f:cf:2d' assert format(net, 't') == 'NetworkAdapter ar8121/ar8113/ar8114 gigabit or fast ethernet' assert format(net, 's') == 'qualcomm atheros 00:24:8C:7F:CF:2D – 100 Mbps' hdd = next(c for c in pc.components if isinstance(c, d.DataStorage)) - assert format(hdd) == 'HardDrive 7: model st9160310as, S/N 5sv4tqa6' + assert format(hdd) == 'HardDrive 9: model st9160310as, S/N 5sv4tqa6' assert format(hdd, 't') == 'HardDrive st9160310as' assert format(hdd, 's') == 'seagate 5SV4TQA6 – 152 GB' @@ -615,7 +616,7 @@ def test_hid_with_mac(app: Devicehub, user: UserClient): """Checks hid with mac.""" snapshot = file('asus-eee-1000h.snapshot.11') user.post(snapshot, res=m.Snapshot) - pc, _ = user.get(res=d.Device, item=1) + pc, _ = user.get(res=d.Device, item=3) assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' @@ -624,8 +625,8 @@ def test_hid_without_mac(app: Devicehub, user: UserClient): """Checks hid without mac.""" snapshot = file('asus-eee-1000h.snapshot.11') snapshot['components'] = [c for c in snapshot['components'] if c['type'] != 'NetworkAdapter'] - user.post(snapshot, res=m.Snapshot) - pc, _ = user.get(res=d.Device, item=1) + snap, _ = user.post(snapshot, res=m.Snapshot) + pc, _ = user.get(res=d.Device, item=snap['device']['id']) assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116' @@ -635,8 +636,8 @@ def test_hid_with_mac_none(app: Devicehub, user: UserClient): snapshot = file('asus-eee-1000h.snapshot.11') network = [c for c in snapshot['components'] if c['type'] == 'NetworkAdapter'][0] network['serialNumber'] = None - user.post(snapshot, res=m.Snapshot) - pc, _ = user.get(res=d.Device, item=1) + snap, _ = user.post(snapshot, res=m.Snapshot) + pc, _ = user.get(res=d.Device, item=snap['device']['id']) assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116' @@ -664,8 +665,8 @@ def test_hid_with_2network_and_drop_no_mac_in_hid(app: Devicehub, user: UserClie network2 = copy.copy(network) snapshot['components'].append(network2) network['serialNumber'] = 'a0:24:8c:7f:cf:2d' - user.post(snapshot, res=m.Snapshot) - pc, _ = user.get(res=d.Device, item=1) + snap, _ = user.post(snapshot, res=m.Snapshot) + pc, _ = user.get(res=d.Device, item=snap['device']['id']) assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abb' @@ -687,8 +688,8 @@ def test_hid_with_2network_and_drop_mac_in_hid(app: Devicehub, user: UserClient) network2 = copy.copy(network) snapshot['components'].append(network2) network['serialNumber'] = 'a0:24:8c:7f:cf:2d' - user.post(snapshot, res=m.Snapshot) - pc, _ = user.get(res=d.Device, item=1) + snap, _ = user.post(snapshot, res=m.Snapshot) + pc, _ = user.get(res=d.Device, item=snap['device']['id']) assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' # we drop the network card then is used for to build the hid From ebe089499d7b51e7980264d022bd890df9c5402a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 16 Apr 2021 13:25:41 +0200 Subject: [PATCH 27/27] fixing tests --- tests/test_device_find.py | 10 +++++----- tests/test_tag.py | 2 +- tests/test_workbench.py | 28 ++++++++++++++++------------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/tests/test_device_find.py b/tests/test_device_find.py index 7e9ac291..82716719 100644 --- a/tests/test_device_find.py +++ b/tests/test_device_find.py @@ -176,10 +176,10 @@ def test_device_query_filter_lots(user: UserClient): @pytest.mark.mvp def test_device_query(user: UserClient): """Checks result of inventory.""" - user.post(conftest.file('basic.snapshot'), res=Snapshot) + snapshot, _ = user.post(conftest.file('basic.snapshot'), res=Snapshot) i, _ = user.get(res=Device) assert i['url'] == '/devices/' - assert i['items'][0]['url'] == '/devices/1' + assert i['items'][0]['url'] == '/devices/{}'.format(snapshot['device']['id']) pc = next(d for d in i['items'] if d['type'] == 'Desktop') assert len(pc['actions']) == 4 assert len(pc['components']) == 3 @@ -241,14 +241,14 @@ def test_device_search_regenerate_table(app: DeviceSearch, user: UserClient): @pytest.mark.mvp def test_device_query_search(user: UserClient): # todo improve - user.post(file('basic.snapshot'), res=Snapshot) + snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) user.post(file('computer-monitor.snapshot'), res=Snapshot) user.post(file('real-eee-1001pxd.snapshot.11'), res=Snapshot) i, _ = user.get(res=Device, query=[('search', 'desktop')]) - assert i['items'][0]['id'] == 1 + assert i['items'][0]['id'] == snapshot['device']['id'] i, _ = user.get(res=Device, query=[('search', 'intel')]) assert len(i['items']) == 1 - i, _ = user.get(res=Device, query=[('search', '1')]) + i, _ = user.get(res=Device, query=[('search', snapshot['device']['id'])]) assert len(i['items']) == 1 diff --git a/tests/test_tag.py b/tests/test_tag.py index f6402bd4..5e8d6648 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -282,7 +282,7 @@ def test_tag_manual_link_search(app: Devicehub, user: UserClient): db.session.commit() desktop_id = desktop.id user.put({}, res=Tag, item='foo-bar/device/{}'.format(desktop_id), status=204) - device, _ = user.get(res=Device, item=1) + device, _ = user.get(res=Device, item=desktop_id) assert device['tags'][0]['id'] == 'foo-bar' # Device already linked diff --git a/tests/test_workbench.py b/tests/test_workbench.py index e2d5ce9a..6f453739 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -32,20 +32,24 @@ def test_workbench_server_condensed(user: UserClient): user.post({'id': t['id']}, res=Tag) snapshot, _ = user.post(res=em.Snapshot, data=s) + pc_id = snapshot['device']['id'] + cpu_id = snapshot['components'][3]['id'] + ssd_id= snapshot['components'][4]['id'] + hdd_id = snapshot['components'][5]['id'] actions = snapshot['actions'] assert {(action['type'], action['device']) for action in actions} == { - ('BenchmarkProcessorSysbench', 5), - ('StressTest', 1), - ('EraseSectors', 6), - ('EreusePrice', 1), - ('BenchmarkRamSysbench', 1), - ('BenchmarkProcessor', 5), - ('Install', 6), - ('EraseSectors', 7), - ('BenchmarkDataStorage', 6), - ('BenchmarkDataStorage', 7), - ('TestDataStorage', 6), - ('RateComputer', 1) + ('BenchmarkProcessorSysbench', cpu_id), + ('StressTest', pc_id), + ('EraseSectors', ssd_id), + ('EreusePrice', pc_id), + ('BenchmarkRamSysbench', pc_id), + ('BenchmarkProcessor', cpu_id), + ('Install', ssd_id), + ('EraseSectors', hdd_id), + ('BenchmarkDataStorage', ssd_id), + ('BenchmarkDataStorage', hdd_id), + ('TestDataStorage', ssd_id), + ('RateComputer', pc_id) } assert snapshot['closed'] assert snapshot['severity'] == 'Info'