fix tests

This commit is contained in:
Cayo Puigdefabregas 2023-04-28 14:45:22 +02:00
parent c9f996dd8e
commit 4e5dbe8cd1
3 changed files with 21 additions and 6 deletions

View File

@ -1014,11 +1014,11 @@ class ExportsView(View):
return export_ids[export_id]() return export_ids[export_id]()
def find_devices(self): def find_devices(self):
# import pdb; pdb.set_trace()
sql = """ sql = """
select lot_device.device_id as id from select lot_device.device_id as id from {schema}.share_lot as share
{schema}.share_lot as share inner join {schema}.lot_device as lot_device
join {schema}.lot_device as lot_device on on share.lot_id=lot_device.lot_id
share.lot_id=lot_device.lot_id
where share.user_to_id='{user_id}' where share.user_to_id='{user_id}'
""".format( """.format(
schema=app.config.get('SCHEMA'), user_id=g.user.id schema=app.config.get('SCHEMA'), user_id=g.user.id

View File

@ -8,7 +8,7 @@ from requests.exceptions import ConnectionError
from ereuse_devicehub import __version__, messages from ereuse_devicehub import __version__, messages
from ereuse_devicehub.labels.forms import PrintLabelsForm, TagForm, TagUnnamedForm 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 from ereuse_devicehub.resources.tag.model import Tag
labels = Blueprint('labels', __name__, url_prefix='/labels') labels = Blueprint('labels', __name__, url_prefix='/labels')
@ -23,6 +23,7 @@ class TagListView(View):
def dispatch_request(self): def dispatch_request(self):
lots = Lot.query.filter(Lot.owner_id == current_user.id) 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( tags = Tag.query.filter(Tag.owner_id == current_user.id).order_by(
Tag.created.desc() Tag.created.desc()
) )
@ -31,6 +32,7 @@ class TagListView(View):
'tags': tags, 'tags': tags,
'page_title': 'Unique Identifiers Management', 'page_title': 'Unique Identifiers Management',
'version': __version__, 'version': __version__,
'share_lots': share_lots,
} }
return flask.render_template(self.template_name, **context) return flask.render_template(self.template_name, **context)
@ -42,7 +44,13 @@ class TagAddView(View):
def dispatch_request(self): def dispatch_request(self):
lots = Lot.query.filter(Lot.owner_id == current_user.id) 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() form = TagForm()
if form.validate_on_submit(): if form.validate_on_submit():
form.save() form.save()
@ -59,10 +67,12 @@ class TagAddUnnamedView(View):
def dispatch_request(self): def dispatch_request(self):
lots = Lot.query.filter(Lot.owner_id == current_user.id) lots = Lot.query.filter(Lot.owner_id == current_user.id)
share_lots = ShareLot.query.filter_by(user_to_id=current_user.id)
context = { context = {
'page_title': 'New Unnamed Tag', 'page_title': 'New Unnamed Tag',
'lots': lots, 'lots': lots,
'version': __version__, 'version': __version__,
'share_lots': share_lots,
} }
form = TagUnnamedForm() form = TagUnnamedForm()
if form.validate_on_submit(): if form.validate_on_submit():
@ -94,11 +104,13 @@ class PrintLabelsView(View):
def dispatch_request(self): def dispatch_request(self):
lots = Lot.query.filter(Lot.owner_id == current_user.id) lots = Lot.query.filter(Lot.owner_id == current_user.id)
share_lots = ShareLot.query.filter_by(user_to_id=current_user.id)
context = { context = {
'lots': lots, 'lots': lots,
'page_title': self.title, 'page_title': self.title,
'version': __version__, 'version': __version__,
'referrer': request.referrer, 'referrer': request.referrer,
'share_lots': share_lots,
} }
form = PrintLabelsForm() form = PrintLabelsForm()
@ -123,6 +135,7 @@ class LabelDetailView(View):
def dispatch_request(self, id): def dispatch_request(self, id):
lots = Lot.query.filter(Lot.owner_id == current_user.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 = (
Tag.query.filter(Tag.owner_id == current_user.id).filter(Tag.id == id).one() 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, 'page_title': self.title,
'version': __version__, 'version': __version__,
'referrer': request.referrer, 'referrer': request.referrer,
'share_lots': share_lots,
} }
devices = [] devices = []

View File

@ -67,6 +67,7 @@ def _app(config: TestConfig) -> Devicehub:
app.register_blueprint(workbench) app.register_blueprint(workbench)
app.config["SQLALCHEMY_RECORD_QUERIES"] = True app.config["SQLALCHEMY_RECORD_QUERIES"] = True
app.config['PROFILE'] = True app.config['PROFILE'] = True
app.config['SCHEMA'] = 'test'
# app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30]) # app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])
mail = Mail(app) mail = Mail(app)
app.mail = mail app.mail = mail