fixing tests

This commit is contained in:
Cayo Puigdefabregas 2021-12-21 10:32:04 +01:00
parent 4acd03e714
commit 47dcb5efe8
2 changed files with 24 additions and 6 deletions

View File

@ -65,7 +65,26 @@ class DocumentView(DeviceView):
if 'filter' in request.args: if 'filter' in request.args:
filters = json.loads(request.args.get('filter', {})) filters = json.loads(request.args.get('filter', {}))
ids = filters.get('ids', []) ids = filters.get('ids', [])
query = devs.Device.query.filter(Device.id.in_(ids))
if not ids and not id:
msg = 'Document must be an ID or UUID.'
raise teal.marshmallow.ValidationError(msg)
if id:
try:
id = uuid.UUID(id)
except ValueError:
try:
ids.append(int(id))
except ValueError:
msg = 'Document must be an ID or UUID.'
raise teal.marshmallow.ValidationError(msg)
else:
query = devs.Device.query.filter(Device.id.in_(ids))
else:
query = evs.Action.query.filter_by(id=id)
else:
query = devs.Device.query.filter(Device.id.in_(ids))
# if id: # if id:
# # todo we assume we can pass both device id and action id # # todo we assume we can pass both device id and action id
@ -99,7 +118,6 @@ class DocumentView(DeviceView):
@staticmethod @staticmethod
def erasure(query: db.Query): def erasure(query: db.Query):
# import pdb; pdb.set_trace()
def erasures(): def erasures():
for model in query: for model in query:
if isinstance(model, devs.Computer): if isinstance(model, devs.Computer):

View File

@ -70,7 +70,7 @@ def test_erasure_certificate_private_query(user: UserClient):
doc, response = user.get(res=documents.DocumentDef.t, doc, response = user.get(res=documents.DocumentDef.t,
item='erasures/', item='erasures/',
query=[ query=[
('filter', {'id': [snapshot['device']['id']]})], ('filter', {'ids': [snapshot['device']['id']]})],
accept=ANY) accept=ANY)
assert 'html' in response.content_type assert 'html' in response.content_type
assert '<html' in doc assert '<html' in doc
@ -80,7 +80,7 @@ def test_erasure_certificate_private_query(user: UserClient):
item='erasures/', item='erasures/',
query=[ query=[
('filter', { ('filter', {
'id': [snapshot['device']['id']]}), 'ids': [snapshot['device']['id']]}),
('format', 'PDF') ('format', 'PDF')
], ],
accept='application/pdf') accept='application/pdf')
@ -601,7 +601,7 @@ def test_verify_stamp_erasure_certificate(user: UserClient, client: Client):
doc, _ = user.get(res=documents.DocumentDef.t, doc, _ = user.get(res=documents.DocumentDef.t,
item='erasures/', item='erasures/',
query=[('filter', {'id': [snapshot['device']['id']]})], query=[('filter', {'ids': [snapshot['device']['id']]})],
accept=ANY) accept=ANY)
response, _ = client.post(res=documents.DocumentDef.t, response, _ = client.post(res=documents.DocumentDef.t,
@ -616,7 +616,7 @@ def test_verify_stamp_erasure_certificate(user: UserClient, client: Client):
doc, _ = user.get(res=documents.DocumentDef.t, doc, _ = user.get(res=documents.DocumentDef.t,
item='erasures/', item='erasures/',
query=[ query=[
('filter', {'id': [snapshot['device']['id']]}), ('filter', {'ids': [snapshot['device']['id']]}),
('format', 'PDF') ('format', 'PDF')
], ],
accept='application/pdf') accept='application/pdf')