Merge branch 'testing' into feature/container

This commit is contained in:
Cayo Puigdefabregas 2021-09-03 11:05:47 +02:00
commit 1d73a8f0c1
4 changed files with 55 additions and 1 deletions

View File

@ -11,6 +11,7 @@ ml).
## testing
[1.0.9-beta]
- [addend] #159 external document as proof of erase of disk
- [addend] #162 adding lot for devices unassigned
## [1.0.8-beta]

View File

@ -86,6 +86,7 @@ class DeviceView(View):
filter = f.Nested(Filters, missing=[])
sort = f.Nested(Sorting, missing=[Device.id.asc()])
page = f.Integer(validate=v.Range(min=1), missing=1)
unassign = f.Integer(validate=v.Range(min=0, max=1), missing=0)
def get(self, id):
"""Devices view
@ -161,6 +162,7 @@ class DeviceView(View):
(Device.owner_id == g.user.id) | (Device.id.in_(trades_dev_ids))
).distinct()
unassign = args.get('unassign', None)
search_p = args.get('search', None)
if search_p:
properties = DeviceSearch.properties
@ -175,6 +177,11 @@ class DeviceView(View):
search.Search.rank(tags, search_p) +
search.Search.rank(devicehub_ids, search_p)
)
if unassign:
subquery = LotDeviceDescendants.query.with_entities(
LotDeviceDescendants.device_id
)
query = query.filter(Device.id.notin_(subquery))
return query.filter(*args['filter']).order_by(*args['sort'])

View File

@ -277,7 +277,13 @@ class StampsView(View):
ok = '100% coincidence. The attached file contains data 100% existing in \
to our backend'
result = ('Bad', bad)
if file_check.mimetype in ['text/csv', 'application/pdf']:
mime = ['text/csv', 'application/pdf', 'text/plain','text/markdown',
'image/jpeg', 'image/png', 'text/html',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.oasis.opendocument.spreadsheet',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/msword']
if file_check.mimetype in mime:
if verify_hash(file_check):
result = ('Ok', ok)

View File

@ -500,6 +500,46 @@ def test_get_devices_permissions(app: Devicehub, user: UserClient, user2: UserCl
assert len(devices['items']) == 1
assert len(devices2['items']) == 0
@pytest.mark.mvp
def test_get_devices_unassigned(app: Devicehub, user: UserClient):
"""Checks GETting multiple devices."""
user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
url = '/devices/?filter={"type":["Computer"]}&unassign=0'
devices, res = user.get(url, None)
assert res.status_code == 200
assert len(devices['items']) == 1
url = '/devices/?filter={"type":["Computer"]}&unassign=1'
devices, res = user.get(url, None)
assert res.status_code == 200
assert len(devices['items']) == 1
from ereuse_devicehub.resources.lot.models import Lot
device_id = devices['items'][0]['id']
my_lot, _ = user.post(({'name': 'My_lot'}), res=Lot)
lot, _ = user.post({},
res=Lot,
item='{}/devices'.format(my_lot['id']),
query=[('id', device_id)])
assert lot['devices'][0]['id'] == device_id, 'Lot contains device'
url = '/devices/?filter={"type":["Computer"]}&unassign=0'
devices, res = user.get(url, None)
assert res.status_code == 200
assert len(devices['items']) == 1
url = '/devices/?filter={"type":["Computer"]}&unassign=1'
devices, res = user.get(url, None)
assert res.status_code == 200
assert len(devices['items']) == 0
@pytest.mark.mvp
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
def test_computer_monitor():