fix tests

This commit is contained in:
Cayo Puigdefabregas 2022-12-14 16:57:59 +01:00
parent 2cc677a555
commit c066d8a2af
4 changed files with 34 additions and 24 deletions

View File

@ -285,7 +285,7 @@ class DeviceRow(BaseDeviceRow):
self['Tag {} ID'.format(i)] = tag.id self['Tag {} ID'.format(i)] = tag.id
self['Tag {} Organization'.format(i)] = tag.org.name self['Tag {} Organization'.format(i)] = tag.org.name
self['Device Hardware ID'] = device.hid self['Device Hardware ID'] = device.chid
self['Device Type'] = device.t self['Device Type'] = device.t
if isinstance(device, d.Computer) and not device.placeholder: if isinstance(device, d.Computer) and not device.placeholder:
self['Device Chassis'] = device.chassis.name self['Device Chassis'] = device.chassis.name
@ -433,12 +433,12 @@ class DeviceRow(BaseDeviceRow):
] ]
erasure = erasures[-1] if erasures else None erasure = erasures[-1] if erasures else None
if not erasure: if not erasure:
self['Erasure {} {}'.format(ctype, i)] = none2str(component.hid) self['Erasure {} {}'.format(ctype, i)] = none2str(component.chid)
serial_number = none2str(component.serial_number) serial_number = none2str(component.serial_number)
self['Erasure {} {} Serial Number'.format(ctype, i)] = serial_number self['Erasure {} {} Serial Number'.format(ctype, i)] = serial_number
self['Erasure {} {} Size (MB)'.format(ctype, i)] = none2str(component.size) self['Erasure {} {} Size (MB)'.format(ctype, i)] = none2str(component.size)
elif hasattr(erasure, 'type') and erasure.type == 'DataWipe': elif hasattr(erasure, 'type') and erasure.type == 'DataWipe':
self['Erasure {} {}'.format(ctype, i)] = none2str(component.hid) self['Erasure {} {}'.format(ctype, i)] = none2str(component.chid)
serial_number = none2str(component.serial_number) serial_number = none2str(component.serial_number)
self['Erasure {} {} Serial Number'.format(ctype, i)] = serial_number self['Erasure {} {} Serial Number'.format(ctype, i)] = serial_number
self['Erasure {} {} Size (MB)'.format(ctype, i)] = none2str(component.size) self['Erasure {} {} Size (MB)'.format(ctype, i)] = none2str(component.size)
@ -448,7 +448,7 @@ class DeviceRow(BaseDeviceRow):
erasure.document.url and erasure.document.url.to_text() or '' erasure.document.url and erasure.document.url.to_text() or ''
) )
else: else:
self['Erasure {} {}'.format(ctype, i)] = none2str(component.hid) self['Erasure {} {}'.format(ctype, i)] = none2str(component.chid)
serial_number = none2str(component.serial_number) serial_number = none2str(component.serial_number)
self['Erasure {} {} Serial Number'.format(ctype, i)] = serial_number self['Erasure {} {} Serial Number'.format(ctype, i)] = serial_number
self['Erasure {} {} Size (MB)'.format(ctype, i)] = none2str(component.size) self['Erasure {} {} Size (MB)'.format(ctype, i)] = none2str(component.size)
@ -594,7 +594,7 @@ class ActionRow(OrderedDict):
super().__init__() super().__init__()
# General information about allocates, deallocate and lives # General information about allocates, deallocate and lives
self['DHID'] = allocate['devicehubID'] self['DHID'] = allocate['devicehubID']
self['Hid'] = allocate['hid'] self['Hid'] = allocate['chid']
self['Document-Name'] = allocate['document_name'] self['Document-Name'] = allocate['document_name']
self['Action-Type'] = allocate['action_type'] self['Action-Type'] = allocate['action_type']
self['Action-User-LastOwner-Supplier'] = allocate['trade_supplier'] self['Action-User-LastOwner-Supplier'] = allocate['trade_supplier']

File diff suppressed because one or more lines are too long

View File

@ -158,5 +158,6 @@
} }
] ]
}, },
"debug": {"lshw": {"configuration": {"uuid": "79c5098f-bc44-4834-8a59-9ea61d956c31"}}},
"closed": false "closed": false
} }

View File

@ -12,7 +12,6 @@ from flask_wtf.csrf import generate_csrf
from ereuse_devicehub.client import UserClient, UserClientFlask from ereuse_devicehub.client import UserClient, UserClientFlask
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.parser.models import SnapshotsLog
from ereuse_devicehub.resources.action.models import Snapshot from ereuse_devicehub.resources.action.models import Snapshot
from ereuse_devicehub.resources.device.models import Device, Placeholder from ereuse_devicehub.resources.device.models import Device, Placeholder
from ereuse_devicehub.resources.lot.models import Lot from ereuse_devicehub.resources.lot.models import Lot
@ -714,7 +713,9 @@ def test_add_laptop(user3: UserClientFlask):
assert typ == 'Laptop' assert typ == 'Laptop'
assert dev.placeholder.id_device_supplier == "b2" assert dev.placeholder.id_device_supplier == "b2"
assert dev.hid == 'laptop-samsung-lc27t55-aaaab' assert (
dev.chid == '69c57a32166b146c27a37ea74632f167d9a83fcbb23f11f93cc55cb9e6878e2b'
)
assert phid == '1' assert phid == '1'
assert dhid == 'O48N2' assert dhid == 'O48N2'
@ -753,7 +754,10 @@ def test_add_with_ammount_laptops(user3: UserClientFlask):
for dev in Device.query.all(): for dev in Device.query.all():
assert dev.type == 'Laptop' assert dev.type == 'Laptop'
assert dev.placeholder.id_device_supplier is None assert dev.placeholder.id_device_supplier is None
assert dev.hid is None assert (
dev.chid
== 'ab606f8b822dcd9276a6c492161fe592047ea98816387d149b2ccfbb5a7ebd30'
)
assert dev.placeholder.phid in [str(x) for x in range(1, num + 1)] assert dev.placeholder.phid in [str(x) for x in range(1, num + 1)]
assert Device.query.count() == num assert Device.query.count() == num
@ -1729,7 +1733,8 @@ def test_add_placeholder_excel(user3: UserClientFlask):
user3.post(uri, data=data, content_type="multipart/form-data") user3.post(uri, data=data, content_type="multipart/form-data")
assert Device.query.count() == 3 assert Device.query.count() == 3
dev = Device.query.first() dev = Device.query.first()
assert dev.hid == 'laptop-sony-vaio-12345678' chid = 'fa7eb51fad01a46b7bbe92fee9d4067e698f6cee9896beece3ace48e15c67652'
assert dev.chid == chid
assert dev.placeholder.phid == '1' assert dev.placeholder.phid == '1'
assert dev.placeholder.info == 'Good conditions' assert dev.placeholder.info == 'Good conditions'
assert dev.placeholder.pallet == '24A' assert dev.placeholder.pallet == '24A'
@ -1755,7 +1760,8 @@ def test_add_placeholder_csv(user3: UserClientFlask):
user3.post(uri, data=data, content_type="multipart/form-data") user3.post(uri, data=data, content_type="multipart/form-data")
assert Device.query.count() == 3 assert Device.query.count() == 3
dev = Device.query.first() dev = Device.query.first()
assert dev.hid == 'laptop-sony-vaio-12345678' chid = 'fa7eb51fad01a46b7bbe92fee9d4067e698f6cee9896beece3ace48e15c67652'
assert dev.chid == chid
assert dev.placeholder.phid == '1' assert dev.placeholder.phid == '1'
assert dev.placeholder.info == 'Good conditions' assert dev.placeholder.info == 'Good conditions'
assert dev.placeholder.pallet == '24A' assert dev.placeholder.pallet == '24A'
@ -1781,7 +1787,8 @@ def test_add_placeholder_ods(user3: UserClientFlask):
user3.post(uri, data=data, content_type="multipart/form-data") user3.post(uri, data=data, content_type="multipart/form-data")
assert Device.query.count() == 3 assert Device.query.count() == 3
dev = Device.query.first() dev = Device.query.first()
assert dev.hid == 'laptop-sony-vaio-12345678' chid = 'fa7eb51fad01a46b7bbe92fee9d4067e698f6cee9896beece3ace48e15c67652'
assert dev.chid == chid
assert dev.placeholder.phid == '1' assert dev.placeholder.phid == '1'
assert dev.placeholder.info == 'Good conditions' assert dev.placeholder.info == 'Good conditions'
assert dev.placeholder.pallet == '24A' assert dev.placeholder.pallet == '24A'
@ -1809,7 +1816,8 @@ def test_add_placeholder_office_open_xml(user3: UserClientFlask):
user3.post(uri, data=data, content_type="multipart/form-data") user3.post(uri, data=data, content_type="multipart/form-data")
assert Device.query.count() == 3 assert Device.query.count() == 3
dev = Device.query.first() dev = Device.query.first()
assert dev.hid == 'laptop-sony-vaio-12345678' chid = 'fa7eb51fad01a46b7bbe92fee9d4067e698f6cee9896beece3ace48e15c67652'
assert dev.chid == chid
assert dev.placeholder.phid == '1' assert dev.placeholder.phid == '1'
assert dev.placeholder.info == 'Good conditions' assert dev.placeholder.info == 'Good conditions'
assert dev.placeholder.pallet == '24A' assert dev.placeholder.pallet == '24A'
@ -1847,7 +1855,8 @@ def test_edit_laptop(user3: UserClientFlask):
assert typ == 'Laptop' assert typ == 'Laptop'
assert dev.placeholder.id_device_supplier == "b2" assert dev.placeholder.id_device_supplier == "b2"
assert dev.hid == 'laptop-samsung-lc27t55-aaaab' chid = '69c57a32166b146c27a37ea74632f167d9a83fcbb23f11f93cc55cb9e6878e2b'
assert dev.chid == chid
assert dev.serial_number == 'aaaab' assert dev.serial_number == 'aaaab'
assert dev.model == 'lc27t55' assert dev.model == 'lc27t55'
assert phid == '1' assert phid == '1'
@ -1879,7 +1888,7 @@ def test_edit_laptop(user3: UserClientFlask):
assert 'Device "Laptop" edited successfully!' in body assert 'Device "Laptop" edited successfully!' in body
dev = Device.query.one() dev = Device.query.one()
assert dev.type == 'Laptop' assert dev.type == 'Laptop'
assert dev.hid == 'laptop-samsung-lc27t55-aaaab' assert dev.chid == chid
assert dev.placeholder.phid == '1' assert dev.placeholder.phid == '1'
assert dev.placeholder.id_device_supplier == 'a2' assert dev.placeholder.id_device_supplier == 'a2'
assert dev.serial_number == 'aaaac' assert dev.serial_number == 'aaaac'
@ -2077,7 +2086,8 @@ def test_add_placeholder_excel_from_lot(user3: UserClientFlask):
user3.post(uri, data=data, content_type="multipart/form-data") user3.post(uri, data=data, content_type="multipart/form-data")
assert Device.query.count() == 3 assert Device.query.count() == 3
dev = Device.query.first() dev = Device.query.first()
assert dev.hid == 'laptop-sony-vaio-12345678' chid = 'fa7eb51fad01a46b7bbe92fee9d4067e698f6cee9896beece3ace48e15c67652'
assert dev.chid == chid
assert dev.placeholder.phid == '1' assert dev.placeholder.phid == '1'
assert dev.placeholder.info == 'Good conditions' assert dev.placeholder.info == 'Good conditions'
assert dev.placeholder.pallet == '24A' assert dev.placeholder.pallet == '24A'
@ -2116,7 +2126,8 @@ def test_add_new_placeholder_from_lot(user3: UserClientFlask):
} }
user3.post(uri, data=data) user3.post(uri, data=data)
dev = Device.query.one() dev = Device.query.one()
assert dev.hid == 'laptop-samsung-lc27t55-aaaab' chid = '69c57a32166b146c27a37ea74632f167d9a83fcbb23f11f93cc55cb9e6878e2b'
assert dev.chid == chid
assert dev.placeholder.phid == '1' assert dev.placeholder.phid == '1'
assert len(lot.devices) == 1 assert len(lot.devices) == 1
@ -2141,7 +2152,8 @@ def test_manual_binding(user3: UserClientFlask):
} }
user3.post(uri, data=data) user3.post(uri, data=data)
dev = Device.query.one() dev = Device.query.one()
assert dev.hid == 'laptop-samsung-lc27t55-aaaab' chid = '69c57a32166b146c27a37ea74632f167d9a83fcbb23f11f93cc55cb9e6878e2b'
assert dev.chid == chid
assert dev.placeholder.phid == '1' assert dev.placeholder.phid == '1'
assert dev.placeholder.is_abstract is False assert dev.placeholder.is_abstract is False
@ -2153,8 +2165,8 @@ def test_manual_binding(user3: UserClientFlask):
assert dev_wb.binding.is_abstract is True assert dev_wb.binding.is_abstract is True
assert ( assert (
dev_wb.hid dev_wb.chid
== 'laptop-asustek_computer_inc-1001pxd-b8oaas048285-14:da:e9:42:f6:7b' == '49b3920735c11693c43cef6199af95798ac00dbd61cc3224eae5e9f04d3313fb'
) )
assert dev_wb.binding.phid == '11' assert dev_wb.binding.phid == '11'
old_placeholder = dev_wb.binding old_placeholder = dev_wb.binding
@ -2653,10 +2665,7 @@ def test_system_uuid_motherboard(user3: UserClientFlask):
} }
user3.post(uri, data=data, content_type="multipart/form-data") user3.post(uri, data=data, content_type="multipart/form-data")
snapshot2 = Snapshot.query.filter_by(uuid=snapshot_json['uuid']).first() snapshot2 = Snapshot.query.filter_by(uuid=snapshot_json['uuid']).first()
assert snapshot2 is None assert snapshot2.device != snapshot.device
for c in snapshot.device.components: for c in snapshot.device.components:
if c.type == 'Motherboard': if c.type == 'Motherboard':
assert c.serial_number == 'eee0123456720' assert c.serial_number == 'eee0123456720'
txt = "We have detected that a there is a device in your inventory"
assert txt in SnapshotsLog.query.all()[-1].description