From 4e5dbe8cd1165d38c10b290e9e3dab016143fddc Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 28 Apr 2023 14:45:22 +0200 Subject: [PATCH] fix tests --- ereuse_devicehub/inventory/views.py | 8 ++++---- ereuse_devicehub/labels/views.py | 18 ++++++++++++++++-- tests/conftest.py | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index b326f268..4ddf5a23 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1014,11 +1014,11 @@ class ExportsView(View): return export_ids[export_id]() def find_devices(self): + # import pdb; pdb.set_trace() sql = """ - select lot_device.device_id as id from - {schema}.share_lot as share - join {schema}.lot_device as lot_device on - share.lot_id=lot_device.lot_id + select lot_device.device_id as id from {schema}.share_lot as share + inner join {schema}.lot_device as lot_device + on share.lot_id=lot_device.lot_id where share.user_to_id='{user_id}' """.format( schema=app.config.get('SCHEMA'), user_id=g.user.id diff --git a/ereuse_devicehub/labels/views.py b/ereuse_devicehub/labels/views.py index 13766bfe..89697271 100644 --- a/ereuse_devicehub/labels/views.py +++ b/ereuse_devicehub/labels/views.py @@ -8,7 +8,7 @@ from requests.exceptions import ConnectionError from ereuse_devicehub import __version__, messages from ereuse_devicehub.labels.forms import PrintLabelsForm, TagForm, TagUnnamedForm -from ereuse_devicehub.resources.lot.models import Lot +from ereuse_devicehub.resources.lot.models import Lot, ShareLot from ereuse_devicehub.resources.tag.model import Tag labels = Blueprint('labels', __name__, url_prefix='/labels') @@ -23,6 +23,7 @@ class TagListView(View): def dispatch_request(self): lots = Lot.query.filter(Lot.owner_id == current_user.id) + share_lots = ShareLot.query.filter_by(user_to_id=current_user.id) tags = Tag.query.filter(Tag.owner_id == current_user.id).order_by( Tag.created.desc() ) @@ -31,6 +32,7 @@ class TagListView(View): 'tags': tags, 'page_title': 'Unique Identifiers Management', 'version': __version__, + 'share_lots': share_lots, } return flask.render_template(self.template_name, **context) @@ -42,7 +44,13 @@ class TagAddView(View): def dispatch_request(self): lots = Lot.query.filter(Lot.owner_id == current_user.id) - context = {'page_title': 'New Tag', 'lots': lots, 'version': __version__} + share_lots = ShareLot.query.filter_by(user_to_id=current_user.id) + context = { + 'page_title': 'New Tag', + 'lots': lots, + 'version': __version__, + 'share_lots': share_lots, + } form = TagForm() if form.validate_on_submit(): form.save() @@ -59,10 +67,12 @@ class TagAddUnnamedView(View): def dispatch_request(self): lots = Lot.query.filter(Lot.owner_id == current_user.id) + share_lots = ShareLot.query.filter_by(user_to_id=current_user.id) context = { 'page_title': 'New Unnamed Tag', 'lots': lots, 'version': __version__, + 'share_lots': share_lots, } form = TagUnnamedForm() if form.validate_on_submit(): @@ -94,11 +104,13 @@ class PrintLabelsView(View): def dispatch_request(self): lots = Lot.query.filter(Lot.owner_id == current_user.id) + share_lots = ShareLot.query.filter_by(user_to_id=current_user.id) context = { 'lots': lots, 'page_title': self.title, 'version': __version__, 'referrer': request.referrer, + 'share_lots': share_lots, } form = PrintLabelsForm() @@ -123,6 +135,7 @@ class LabelDetailView(View): def dispatch_request(self, id): lots = Lot.query.filter(Lot.owner_id == current_user.id) + share_lots = ShareLot.query.filter_by(user_to_id=current_user.id) tag = ( Tag.query.filter(Tag.owner_id == current_user.id).filter(Tag.id == id).one() ) @@ -131,6 +144,7 @@ class LabelDetailView(View): 'page_title': self.title, 'version': __version__, 'referrer': request.referrer, + 'share_lots': share_lots, } devices = [] diff --git a/tests/conftest.py b/tests/conftest.py index ac75ecc8..f99f7717 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -67,6 +67,7 @@ def _app(config: TestConfig) -> Devicehub: app.register_blueprint(workbench) app.config["SQLALCHEMY_RECORD_QUERIES"] = True app.config['PROFILE'] = True + app.config['SCHEMA'] = 'test' # app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30]) mail = Mail(app) app.mail = mail