fix tests

This commit is contained in:
Cayo Puigdefabregas 2022-07-19 12:27:10 +02:00
parent d7b9d01165
commit aed23450df
6 changed files with 438 additions and 259 deletions

File diff suppressed because one or more lines are too long

View File

@ -190,7 +190,7 @@ def test_inventory_with_device(user3: UserClientFlask):
assert status == '200 OK'
assert "Unassigned" in body
assert db_snapthot.device.devicehub_id in body
assert db_snapthot.device.binding.device.devicehub_id in body
@pytest.mark.mvp
@ -203,7 +203,7 @@ def test_inventory_filter(user3: UserClientFlask):
assert status == '200 OK'
assert "Unassigned" in body
assert db_snapthot.device.devicehub_id in body
assert db_snapthot.device.binding.device.devicehub_id in body
@pytest.mark.mvp
@ -709,7 +709,7 @@ def test_action_recycling(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Allocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
}
uri = '/inventory/action/add/'
@ -722,15 +722,15 @@ def test_action_recycling(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Recycling",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
}
uri = '/inventory/action/add/'
body, status = user3.post(uri, data=data)
assert status == '200 OK'
assert dev.actions[-1].type == 'Recycling'
assert dev.binding.device.actions[-1].type == 'Recycling'
assert 'Action "Recycling" created successfully!' in body
assert dev.devicehub_id in body
assert dev.binding.device.devicehub_id in body
@pytest.mark.mvp
@ -764,15 +764,15 @@ def test_action_use(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Use",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
}
uri = '/inventory/action/add/'
body, status = user3.post(uri, data=data)
assert status == '200 OK'
assert dev.actions[-1].type == 'Use'
assert dev.binding.device.actions[-1].type == 'Use'
assert 'Action "Use" created successfully!' in body
assert dev.devicehub_id in body
assert dev.binding.device.devicehub_id in body
@pytest.mark.mvp
@ -787,15 +787,15 @@ def test_action_refurbish(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Refurbish",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
}
uri = '/inventory/action/add/'
body, status = user3.post(uri, data=data)
assert status == '200 OK'
assert dev.actions[-1].type == 'Refurbish'
assert dev.binding.device.actions[-1].type == 'Refurbish'
assert 'Action "Refurbish" created successfully!' in body
assert dev.devicehub_id in body
assert dev.binding.device.devicehub_id in body
@pytest.mark.mvp
@ -810,15 +810,15 @@ def test_action_management(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Management",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
}
uri = '/inventory/action/add/'
body, status = user3.post(uri, data=data)
assert status == '200 OK'
assert dev.actions[-1].type == 'Management'
assert dev.binding.device.actions[-1].type == 'Management'
assert 'Action "Management" created successfully!' in body
assert dev.devicehub_id in body
assert dev.binding.device.devicehub_id in body
@pytest.mark.mvp
@ -833,7 +833,7 @@ def test_action_allocate(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Allocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-01-01',
'end_time': '2000-06-01',
'end_users': 2,
@ -842,9 +842,9 @@ def test_action_allocate(user3: UserClientFlask):
uri = '/inventory/action/allocate/add/'
body, status = user3.post(uri, data=data)
assert status == '200 OK'
assert dev.actions[-1].type == 'Allocate'
assert dev.binding.device.actions[-1].type == 'Allocate'
assert 'Action "Allocate" created successfully!' in body
assert dev.devicehub_id in body
assert dev.binding.device.devicehub_id in body
@pytest.mark.mvp
@ -859,18 +859,18 @@ def test_action_allocate_error_required(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Trade",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
}
uri = '/inventory/action/allocate/add/'
body, status = user3.post(uri, data=data)
assert dev.actions[-1].type != 'Allocate'
assert 'Allocate' not in [x.type for x in dev.binding.device.actions]
data = {
'csrf_token': generate_csrf(),
'type': "Allocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
}
uri = '/inventory/action/allocate/add/'
@ -892,7 +892,7 @@ def test_action_allocate_error_dates(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Allocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-06-01',
'end_time': '2000-01-01',
'end_users': 2,
@ -903,7 +903,7 @@ def test_action_allocate_error_dates(user3: UserClientFlask):
assert status == '200 OK'
assert 'Action Allocate error' in body
assert 'The action cannot finish before it starts.' in body
assert dev.actions[-1].type != 'Allocate'
assert 'Allocate' not in [x.type for x in dev.binding.device.actions]
@pytest.mark.mvp
@ -920,7 +920,7 @@ def test_action_allocate_error_future_dates(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Allocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': start_time,
'end_time': end_time,
'end_users': 2,
@ -931,7 +931,7 @@ def test_action_allocate_error_future_dates(user3: UserClientFlask):
assert status == '200 OK'
assert 'Action Allocate error' in body
assert 'Not a valid date value.!' in body
assert dev.actions[-1].type != 'Allocate'
assert 'Allocate' not in [x.type for x in dev.binding.device.actions]
@pytest.mark.mvp
@ -946,7 +946,7 @@ def test_action_deallocate(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Allocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-01-01',
'end_time': '2000-06-01',
'end_users': 2,
@ -955,22 +955,22 @@ def test_action_deallocate(user3: UserClientFlask):
uri = '/inventory/action/allocate/add/'
user3.post(uri, data=data)
assert dev.allocated_status.type == 'Allocate'
assert dev.binding.device.allocated_status.type == 'Allocate'
data = {
'csrf_token': generate_csrf(),
'type': "Deallocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-01-01',
'end_time': '2000-06-01',
'end_users': 2,
}
body, status = user3.post(uri, data=data)
assert status == '200 OK'
assert dev.allocated_status.type == 'Deallocate'
assert dev.binding.device.allocated_status.type == 'Deallocate'
assert 'Action "Deallocate" created successfully!' in body
assert dev.devicehub_id in body
assert dev.binding.device.devicehub_id in body
@pytest.mark.mvp
@ -985,7 +985,7 @@ def test_action_deallocate_error(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Allocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-05-01',
'end_time': '2000-06-01',
'end_users': 2,
@ -994,20 +994,20 @@ def test_action_deallocate_error(user3: UserClientFlask):
uri = '/inventory/action/allocate/add/'
user3.post(uri, data=data)
assert dev.allocated_status.type == 'Allocate'
assert dev.binding.device.allocated_status.type == 'Allocate'
data = {
'csrf_token': generate_csrf(),
'type': "Deallocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-01-01',
'end_time': '2000-02-01',
'end_users': 2,
}
body, status = user3.post(uri, data=data)
assert status == '200 OK'
assert dev.allocated_status.type != 'Deallocate'
assert dev.binding.device.allocated_status.type != 'Deallocate'
assert 'Action Deallocate error!' in body
assert 'Sorry some of this devices are actually deallocate' in body
@ -1024,7 +1024,7 @@ def test_action_allocate_deallocate_error(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Allocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-01-01',
'end_time': '2000-01-01',
'end_users': 2,
@ -1033,36 +1033,36 @@ def test_action_allocate_deallocate_error(user3: UserClientFlask):
uri = '/inventory/action/allocate/add/'
user3.post(uri, data=data)
assert dev.allocated_status.type == 'Allocate'
assert len(dev.actions) == 11
assert dev.binding.device.allocated_status.type == 'Allocate'
assert len(dev.binding.device.actions) == 1
data = {
'csrf_token': generate_csrf(),
'type': "Deallocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-02-01',
'end_time': '2000-02-01',
'end_users': 2,
}
body, status = user3.post(uri, data=data)
assert status == '200 OK'
assert dev.allocated_status.type == 'Deallocate'
assert len(dev.actions) == 12
assert dev.binding.device.allocated_status.type == 'Deallocate'
assert len(dev.binding.device.actions) == 2
# is not possible to do an allocate between an allocate and an deallocate
data = {
'csrf_token': generate_csrf(),
'type': "Allocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-01-15',
'end_time': '2000-01-15',
'end_users': 2,
}
user3.post(uri, data=data)
assert dev.allocated_status.type == 'Deallocate'
assert dev.binding.device.allocated_status.type == 'Deallocate'
# assert 'Action Deallocate error!' in body
# assert 'Sorry some of this devices are actually deallocate' in body
#
@ -1070,14 +1070,14 @@ def test_action_allocate_deallocate_error(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Deallocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-01-15',
'end_time': '2000-01-15',
'end_users': 2,
}
user3.post(uri, data=data)
assert len(dev.actions) == 12
assert len(dev.binding.device.actions) == 2
@pytest.mark.mvp
@ -1092,7 +1092,7 @@ def test_action_allocate_deallocate_error2(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "Allocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-01-10',
'end_users': 2,
}
@ -1100,25 +1100,25 @@ def test_action_allocate_deallocate_error2(user3: UserClientFlask):
uri = '/inventory/action/allocate/add/'
user3.post(uri, data=data)
assert len(dev.actions) == 11
assert len(dev.binding.device.actions) == 1
data = {
'csrf_token': generate_csrf(),
'type': "Deallocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-01-20',
'end_users': 2,
}
body, status = user3.post(uri, data=data)
assert status == '200 OK'
assert len(dev.actions) == 12
assert len(dev.binding.device.actions) == 2
data = {
'csrf_token': generate_csrf(),
'type': "Allocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-02-10',
'end_users': 2,
}
@ -1126,40 +1126,40 @@ def test_action_allocate_deallocate_error2(user3: UserClientFlask):
uri = '/inventory/action/allocate/add/'
user3.post(uri, data=data)
assert len(dev.actions) == 13
assert len(dev.binding.device.actions) == 3
data = {
'csrf_token': generate_csrf(),
'type': "Deallocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-02-20',
'end_users': 2,
}
user3.post(uri, data=data)
assert len(dev.actions) == 14
assert len(dev.binding.device.actions) == 4
data = {
'csrf_token': generate_csrf(),
'type': "Allocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-01-25',
'end_users': 2,
}
user3.post(uri, data=data)
assert len(dev.actions) == 15
assert len(dev.binding.device.actions) == 5
data = {
'csrf_token': generate_csrf(),
'type': "Deallocate",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
'start_time': '2000-01-27',
'end_users': 2,
}
user3.post(uri, data=data)
assert len(dev.actions) == 16
assert len(dev.binding.device.actions) == 6
@pytest.mark.mvp
@ -1174,20 +1174,21 @@ def test_action_toprepare(user3: UserClientFlask):
'csrf_token': generate_csrf(),
'type': "ToPrepare",
'severity': "Info",
'devices': "{}".format(dev.id),
'devices': "{}".format(dev.binding.device.id),
}
uri = '/inventory/action/add/'
body, status = user3.post(uri, data=data)
assert status == '200 OK'
assert dev.actions[-1].type == 'ToPrepare'
assert dev.binding.device.actions[-1].type == 'ToPrepare'
assert 'Action "ToPrepare" created successfully!' in body
assert dev.devicehub_id in body
assert dev.binding.device.devicehub_id in body
@pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_action_prepare(user3: UserClientFlask):
# ???
snap = create_device(user3, 'real-eee-1001pxd.snapshot.12.json')
dev = snap.device
uri = '/inventory/device/'

View File

@ -367,18 +367,6 @@ def test_snapshot_mismatch_id():
pass
@pytest.mark.mvp
def test_snapshot_tag_inner_tag(user: UserClient, tag_id: str, app: Devicehub):
"""Tests a posting Snapshot with a local tag."""
b = yaml2json('basic.snapshot')
b['device']['tags'] = [{'type': 'Tag', 'id': tag_id}]
snapshot_and_check(user, b, action_types=(BenchmarkProcessor.t, VisualTest.t))
with app.app_context():
tag = Tag.query.all()[0] # type: Tag
assert tag.device_id == 3, 'Tag should be linked to the first device'
@pytest.mark.mvp
def test_snapshot_tag_inner_tag_mismatch_between_tags_and_hid(
user: UserClient, tag_id: str

View File

@ -92,7 +92,7 @@ def test_wb11_to_wb11_with_uuid_api(user: UserClient):
db_snapthot = Snapshot.query.one()
device = db_snapthot.device
assert Computer.query.count() == 1
assert Computer.query.count() == 2
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert device.system_uuid is None
@ -106,9 +106,13 @@ def test_wb11_to_wb11_with_uuid_api(user: UserClient):
snapshot_11['debug']['lshw']['configuration']['uuid']
== '364ee69c-9c82-9cb1-2111-88ae1da6f3d0'
)
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
@ -123,9 +127,13 @@ def test_wb11_with_uuid_to_wb11_api(user: UserClient):
snapshot_11['uuid'] = '0973fda0-589a-11eb-ae93-0242ac130003'
user.post(snapshot_11, res=Snapshot)
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
# insert the same computer with wb11 with hid and with uuid, (new version)
@ -133,9 +141,13 @@ def test_wb11_with_uuid_to_wb11_api(user: UserClient):
assert 'debug' not in snapshot_11
user.post(snapshot_11, res=Snapshot)
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
@ -150,9 +162,13 @@ def test_wb11_with_uuid_to_wb11_without_hid_api(user: UserClient):
snapshot_11['uuid'] = '0973fda0-589a-11eb-ae93-0242ac130003'
user.post(snapshot_11, res=Snapshot)
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
# insert the same computer with wb11 with hid and with uuid, (new version)
@ -162,7 +178,7 @@ def test_wb11_with_uuid_to_wb11_without_hid_api(user: UserClient):
snapshot_11['debug'] = {'lshw': snapshot_lite['data']['lshw']}
user.post(snapshot_11, res=Snapshot)
assert Computer.query.count() == 1
assert Computer.query.count() == 2
@pytest.mark.mvp
@ -186,7 +202,7 @@ def test_wb11_to_wb11_with_uuid_form(user3: UserClientFlask):
db_snapthot = Snapshot.query.one()
device = db_snapthot.device
assert Computer.query.count() == 1
assert Computer.query.count() == 2
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert device.system_uuid is None
@ -203,9 +219,13 @@ def test_wb11_to_wb11_with_uuid_form(user3: UserClientFlask):
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
@ -231,9 +251,13 @@ def test_wb11_with_uuid_to_wb11_form(user3: UserClientFlask):
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
# insert the same computer with wb11 with hid and with uuid, (new version)
@ -248,9 +272,13 @@ def test_wb11_with_uuid_to_wb11_form(user3: UserClientFlask):
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
@ -276,9 +304,13 @@ def test_wb11_with_uuid_to_wb11_without_hid_form(user3: UserClientFlask):
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
# insert the same computer with wb11 with hid and with uuid, (new version)
@ -295,7 +327,7 @@ def test_wb11_with_uuid_to_wb11_without_hid_form(user3: UserClientFlask):
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
assert Computer.query.count() == 2
@pytest.mark.mvp
@ -305,16 +337,24 @@ def test_wb11_to_wblite_api(user: UserClient):
# insert computer with wb11 with hid and without uuid, (old version)
snapshot_11 = conftest.file_json('system_uuid3.json')
user.post(snapshot_11, res=Snapshot)
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert device.system_uuid is None
snapshot_lite = conftest.file_json('system_uuid2.json')
user.post(snapshot_lite, uri="/api/inventory/")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
@ -324,16 +364,24 @@ def test_wblite_to_wb11_api(user: UserClient):
snapshot_lite = conftest.file_json('system_uuid2.json')
user.post(snapshot_lite, uri="/api/inventory/")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
snapshot_11 = conftest.file_json('system_uuid3.json')
user.post(snapshot_11, res=Snapshot)
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
@ -354,9 +402,13 @@ def test_wb11_to_wblite_form(user3: UserClientFlask):
'csrf_token': generate_csrf(),
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert device.system_uuid is None
file_name = 'system_uuid2.json'
@ -369,9 +421,13 @@ def test_wb11_to_wblite_form(user3: UserClientFlask):
'csrf_token': generate_csrf(),
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
@ -392,9 +448,13 @@ def test_wblite_to_wb11_form(user3: UserClientFlask):
'csrf_token': generate_csrf(),
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
file_name = 'system_uuid3.json'
@ -407,9 +467,13 @@ def test_wblite_to_wb11_form(user3: UserClientFlask):
'csrf_token': generate_csrf(),
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
@ -419,17 +483,25 @@ def test_wblite_to_wblite_api(user: UserClient):
snapshot_lite = conftest.file_json('system_uuid2.json')
user.post(snapshot_lite, uri="/api/inventory/")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
snapshot_lite = conftest.file_json('system_uuid2.json')
snapshot_lite['uuid'] = '0973fda0-589a-11eb-ae93-0242ac130003'
user.post(snapshot_lite, uri="/api/inventory/")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
@ -450,9 +522,13 @@ def test_wblite_to_wblite_form(user3: UserClientFlask):
'csrf_token': generate_csrf(),
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
file_name = 'system_uuid2.json'
@ -466,9 +542,13 @@ def test_wblite_to_wblite_form(user3: UserClientFlask):
'csrf_token': generate_csrf(),
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
@ -479,9 +559,13 @@ def test_wb11_to_wb11_duplicity_api(user: UserClient):
# insert computer with wb11 with hid and without uuid, (old version)
snapshot_11 = conftest.file_json('system_uuid3.json')
user.post(snapshot_11, res=Snapshot)
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert device.system_uuid is None
snapshot_11 = conftest.file_json('system_uuid3.json')
@ -489,7 +573,7 @@ def test_wb11_to_wb11_duplicity_api(user: UserClient):
components = [x for x in snapshot_11['components'] if x['type'] != 'NetworkAdapter']
snapshot_11['components'] = components
user.post(snapshot_11, res=Snapshot)
assert Computer.query.count() == 2
assert Computer.query.count() == 4
for c in Computer.query.all():
assert 'laptop-acer-aohappy-lusea0d010038879a01601' in c.hid
assert c.system_uuid is None
@ -512,9 +596,13 @@ def test_wb11_to_wb11_duplicity_form(user3: UserClientFlask):
'csrf_token': generate_csrf(),
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert device.system_uuid is None
snapshot_11 = conftest.file_json('system_uuid3.json')
@ -530,10 +618,12 @@ def test_wb11_to_wb11_duplicity_form(user3: UserClientFlask):
'csrf_token': generate_csrf(),
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 2
for c in Computer.query.all():
assert 'laptop-acer-aohappy-lusea0d010038879a01601' in c.hid
assert c.system_uuid is None
assert Computer.query.count() == 4
for device in Computer.query.all():
if device.binding:
assert 'laptop-acer-aohappy-lusea0d010038879a01601' in device.hid
assert device.system_uuid is None
@pytest.mark.mvp
@ -543,9 +633,13 @@ def test_wb11_smbios_2_5_api(user: UserClient):
# insert computer with wb11 with hid and without uuid, (old version)
snapshot_11 = conftest.file_json('system_uuid4.json')
user.post(snapshot_11, res=Snapshot)
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert device.system_uuid is None
@ -566,9 +660,13 @@ def test_wb11_smbios_2_5_form(user3: UserClientFlask):
'csrf_token': generate_csrf(),
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert device.system_uuid is None
@ -580,9 +678,13 @@ def test_wblite_smbios_2_5_api(user: UserClient):
snapshot_lite = conftest.file_json('system_uuid2.json')
snapshot_lite['data']['lshw']['capabilities']['smbios-3.0'] = 'SMBIOS version 2.5'
user.post(snapshot_lite, uri="/api/inventory/")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'
@ -604,7 +706,11 @@ def test_wblite_smbios_2_5_form(user3: UserClientFlask):
'csrf_token': generate_csrf(),
}
user3.post(uri, data=data, content_type="multipart/form-data")
assert Computer.query.count() == 1
device = Computer.query.one()
assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
assert Computer.query.count() == 2
for device in Computer.query.all():
if device.binding:
assert (
device.hid
== 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0'
)
assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0'

View File

@ -2,26 +2,29 @@ import pathlib
import pytest
import requests_mock
from flask import g
from boltons.urlutils import URL
from ereuse_utils.session import DevicehubClient
from flask import g
from pytest import raises
from teal.db import MultipleResourcesFound, ResourceNotFound, UniqueViolation, DBError
from teal.db import DBError, MultipleResourcesFound, ResourceNotFound, UniqueViolation
from teal.marshmallow import ValidationError
from ereuse_devicehub.client import UserClient, Client
from ereuse_devicehub.client import Client, UserClient
from ereuse_devicehub.db import db
from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.resources.user.models import User
from ereuse_devicehub.resources.action.models import Snapshot
from ereuse_devicehub.resources.agent.models import Organization
from ereuse_devicehub.resources.device.models import Desktop, Device
from ereuse_devicehub.resources.enums import ComputerChassis
from ereuse_devicehub.resources.tag import Tag
from ereuse_devicehub.resources.tag.view import CannotCreateETag, LinkedToAnotherDevice, \
TagNotLinked
from ereuse_devicehub.resources.tag.view import (
CannotCreateETag,
LinkedToAnotherDevice,
TagNotLinked,
)
from ereuse_devicehub.resources.user.models import User
from tests import conftest
from tests.conftest import yaml2json, json_encode
from tests.conftest import json_encode, yaml2json
@pytest.mark.mvp
@ -29,7 +32,9 @@ from tests.conftest import yaml2json, json_encode
def test_create_tag(user: UserClient):
"""Creates a tag specifying a custom organization."""
org = Organization(name='bar', tax_id='bartax')
tag = Tag(id='bar-1', org=org, provider=URL('http://foo.bar'), owner_id=user.user['id'])
tag = Tag(
id='bar-1', org=org, provider=URL('http://foo.bar'), owner_id=user.user['id']
)
db.session.add(tag)
db.session.commit()
tag = Tag.query.one()
@ -44,7 +49,9 @@ def test_create_tag(user: UserClient):
def test_create_tag_with_device(user: UserClient):
"""Creates a tag specifying linked with one device."""
g.user = User.query.one()
pc = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id'])
pc = Desktop(
serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id']
)
db.session.add(pc)
db.session.commit()
tag = Tag(id='bar', owner_id=user.user['id'])
@ -64,7 +71,9 @@ def test_delete_tags(user: UserClient, client: Client):
"""Delete a named tag."""
# Delete Tag Named
g.user = User.query.one()
pc = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id'])
pc = Desktop(
serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id']
)
db.session.add(pc)
db.session.commit()
tag = Tag(id='bar', owner_id=user.user['id'], device_id=pc.id)
@ -89,7 +98,9 @@ def test_delete_tags(user: UserClient, client: Client):
# Delete Tag UnNamed
org = Organization(name='bar', tax_id='bartax')
tag = Tag(id='bar-1', org=org, provider=URL('http://foo.bar'), owner_id=user.user['id'])
tag = Tag(
id='bar-1', org=org, provider=URL('http://foo.bar'), owner_id=user.user['id']
)
db.session.add(tag)
db.session.commit()
tag = Tag.query.all()[-1]
@ -106,7 +117,9 @@ def test_delete_tags(user: UserClient, client: Client):
def test_create_tag_default_org(user: UserClient):
"""Creates a tag using the default organization."""
tag = Tag(id='foo-1', owner_id=user.user['id'])
assert not tag.org_id, 'org-id is set as default value so it should only load on flush'
assert (
not tag.org_id
), 'org-id is set as default value so it should only load on flush'
# We don't want the organization to load, or it would make this
# object, from transient to new (added to session)
assert 'org' not in vars(tag), 'Organization should not have been loaded'
@ -188,7 +201,9 @@ def test_tag_get_device_from_tag_endpoint(app: Devicehub, user: UserClient):
# Create a pc with a tag
g.user = User.query.one()
tag = Tag(id='foo-bar', owner_id=user.user['id'])
pc = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id'])
pc = Desktop(
serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id']
)
pc.tags.add(tag)
db.session.add(pc)
db.session.commit()
@ -213,7 +228,9 @@ def test_tag_get_device_from_tag_endpoint_no_tag(user: UserClient):
@pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_tag_get_device_from_tag_endpoint_multiple_tags(app: Devicehub, user: UserClient, user2: UserClient, client: Client):
def test_tag_get_device_from_tag_endpoint_multiple_tags(
app: Devicehub, user: UserClient, user2: UserClient, client: Client
):
"""As above, but when there are two tags with the secondary ID, the
system should not return any of both (to be deterministic) so
it should raise an exception.
@ -232,8 +249,12 @@ def test_tag_get_device_from_tag_endpoint_multiple_tags(app: Devicehub, user: Us
tag1 = Tag.from_an_id('foo').filter_by(owner_id=user.user['id']).one()
tag2 = Tag.from_an_id('foo').filter_by(owner_id=user2.user['id']).one()
pc1 = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id'])
pc2 = Desktop(serial_number='sn2', chassis=ComputerChassis.Tower, owner_id=user2.user['id'])
pc1 = Desktop(
serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id']
)
pc2 = Desktop(
serial_number='sn2', chassis=ComputerChassis.Tower, owner_id=user2.user['id']
)
pc1.tags.add(tag1)
pc2.tags.add(tag2)
db.session.add(pc1)
@ -266,7 +287,17 @@ def test_tag_create_etags_cli(app: Devicehub, user: UserClient):
# todo what happens to organization?
owner_id = user.user['id']
runner = app.test_cli_runner()
args = ('tag', 'add', '-p', 'https://t.ereuse.org', '-s', 'foo', 'DT-BARBAR', '-u', owner_id)
args = (
'tag',
'add',
'-p',
'https://t.ereuse.org',
'-s',
'foo',
'DT-BARBAR',
'-u',
owner_id,
)
runner.invoke(*args)
with app.app_context():
tag = Tag.query.one() # type: Tag
@ -284,7 +315,11 @@ def test_tag_manual_link_search(app: Devicehub, user: UserClient):
with app.app_context():
g.user = User.query.one()
db.session.add(Tag('foo-bar', secondary='foo-sec', owner_id=user.user['id']))
desktop = Desktop(serial_number='foo', chassis=ComputerChassis.AllInOne, owner_id=user.user['id'])
desktop = Desktop(
serial_number='foo',
chassis=ComputerChassis.AllInOne,
owner_id=user.user['id'],
)
db.session.add(desktop)
db.session.commit()
desktop_id = desktop.id
@ -330,13 +365,21 @@ def test_tag_secondary_workbench_link_find(user: UserClient):
s['device']['tags'] = [{'id': 'foo', 'secondary': 'bar', 'type': 'Tag'}]
snapshot, _ = user.post(json_encode(s), res=Snapshot)
device, _ = user.get(res=Device, item=snapshot['device']['devicehubID'])
assert 'foo' in [x['id'] for x in device['tags']]
assert 'bar' in [x.get('secondary') for x in device['tags']]
desktop = Device.query.filter_by(
devicehub_id=snapshot['device']['devicehubID']
).one()
assert ['O48N2'] == [x['id'] for x in device['tags']]
assert 'foo' in [x.id for x in desktop.binding.device.tags]
assert 'bar' in [x.secondary for x in desktop.binding.device.tags]
r, _ = user.get(res=Device, query=[('search', 'foo'), ('filter', {'type': ['Computer']})])
assert len(r['items']) == 1
r, _ = user.get(res=Device, query=[('search', 'bar'), ('filter', {'type': ['Computer']})])
assert len(r['items']) == 1
r, _ = user.get(
res=Device, query=[('search', 'foo'), ('filter', {'type': ['Computer']})]
)
assert len(r['items']) == 0
r, _ = user.get(
res=Device, query=[('search', 'bar'), ('filter', {'type': ['Computer']})]
)
assert len(r['items']) == 0
@pytest.mark.mvp
@ -359,19 +402,24 @@ def test_tag_multiple_secondary_org(user: UserClient):
@pytest.mark.mvp
def test_create_num_regular_tags(user: UserClient, requests_mock: requests_mock.mocker.Mocker):
def test_create_num_regular_tags(
user: UserClient, requests_mock: requests_mock.mocker.Mocker
):
"""Create regular tags. This is done using a tag provider that
returns IDs. These tags are printable.
"""
requests_mock.post('https://example.com/',
requests_mock.post(
'https://example.com/',
# request
request_headers={
'Authorization': 'Basic {}'.format(DevicehubClient.encode_token(
'52dacef0-6bcb-4919-bfed-f10d2c96ecee'))
'Authorization': 'Basic {}'.format(
DevicehubClient.encode_token('52dacef0-6bcb-4919-bfed-f10d2c96ecee')
)
},
# response
json=['tag1id', 'tag2id'],
status_code=201)
status_code=201,
)
data, _ = user.post({}, res=Tag, query=[('num', 2)])
assert data['items'][0]['id'] == 'tag1id'
assert data['items'][0]['printable'], 'Tags made this way are printable'
@ -380,28 +428,37 @@ def test_create_num_regular_tags(user: UserClient, requests_mock: requests_mock.
@pytest.mark.mvp
def test_get_tags_endpoint(user: UserClient, app: Devicehub,
requests_mock: requests_mock.mocker.Mocker):
def test_get_tags_endpoint(
user: UserClient, app: Devicehub, requests_mock: requests_mock.mocker.Mocker
):
"""Performs GET /tags after creating 3 tags, 2 printable and one
not. Only the printable ones are returned.
"""
# Prepare test
with app.app_context():
org = Organization(name='bar', tax_id='bartax')
tag = Tag(id='bar-1', org=org, provider=URL('http://foo.bar'), owner_id=user.user['id'])
tag = Tag(
id='bar-1',
org=org,
provider=URL('http://foo.bar'),
owner_id=user.user['id'],
)
db.session.add(tag)
db.session.commit()
assert not tag.printable
requests_mock.post('https://example.com/',
requests_mock.post(
'https://example.com/',
# request
request_headers={
'Authorization': 'Basic {}'.format(DevicehubClient.encode_token(
'52dacef0-6bcb-4919-bfed-f10d2c96ecee'))
'Authorization': 'Basic {}'.format(
DevicehubClient.encode_token('52dacef0-6bcb-4919-bfed-f10d2c96ecee')
)
},
# response
json=['tag1id', 'tag2id'],
status_code=201)
status_code=201,
)
user.post({}, res=Tag, query=[('num', 2)])
# Test itself
@ -421,7 +478,9 @@ def test_get_tag_permissions(app: Devicehub, user: UserClient, user2: UserClient
# Create a pc with a tag
g.user = User.query.all()[0]
tag = Tag(id='foo-bar', owner_id=user.user['id'])
pc = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id'])
pc = Desktop(
serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id']
)
pc.tags.add(tag)
db.session.add(pc)
db.session.commit()

View File

@ -1,17 +1,21 @@
"""Tests that emulates the behaviour of a WorkbenchServer."""
import json
import math
import pathlib
import math
import pytest
from ereuse_devicehub.client import UserClient
from ereuse_devicehub.resources.action import models as em
from ereuse_devicehub.resources.action.models import RateComputer, BenchmarkProcessor, BenchmarkRamSysbench
from ereuse_devicehub.resources.action.models import (
BenchmarkProcessor,
BenchmarkRamSysbench,
RateComputer,
)
from ereuse_devicehub.resources.device.exceptions import NeedsId
from ereuse_devicehub.resources.device.models import Device
from ereuse_devicehub.resources.tag.model import Tag
from tests.conftest import file, file_workbench, yaml2json, json_encode
from tests.conftest import file, file_workbench, json_encode, yaml2json
@pytest.mark.mvp
@ -22,10 +26,9 @@ def test_workbench_server_condensed(user: UserClient):
"""
s = yaml2json('workbench-server-1.snapshot')
s['device']['actions'].append(yaml2json('workbench-server-2.stress-test'))
s['components'][4]['actions'].extend((
yaml2json('workbench-server-3.erase'),
yaml2json('workbench-server-4.install')
))
s['components'][4]['actions'].extend(
(yaml2json('workbench-server-3.erase'), yaml2json('workbench-server-4.install'))
)
s['components'][5]['actions'].append(yaml2json('workbench-server-3.erase'))
# Create tags
for t in s['device']['tags']:
@ -34,7 +37,7 @@ def test_workbench_server_condensed(user: UserClient):
snapshot, _ = user.post(res=em.Snapshot, data=json_encode(s))
pc_id = snapshot['device']['id']
cpu_id = snapshot['components'][3]['id']
ssd_id= snapshot['components'][4]['id']
ssd_id = snapshot['components'][4]['id']
hdd_id = snapshot['components'][5]['id']
actions = snapshot['actions']
assert {(action['type'], action['device']) for action in actions} == {
@ -60,8 +63,13 @@ def test_workbench_server_condensed(user: UserClient):
assert device['processorModel'] == device['components'][3]['model'] == 'p1-1ml'
assert device['ramSize'] == 2048, 'There are 3 RAM: 2 x 1024 and 1 None sizes'
# TODO JN why haven't same order in actions on each execution?
assert any([ac['type'] in [BenchmarkProcessor.t, BenchmarkRamSysbench.t] for ac in device['actions']])
assert 'tag1' in [x['id'] for x in device['tags']]
assert any(
[
ac['type'] in [BenchmarkProcessor.t, BenchmarkRamSysbench.t]
for ac in device['actions']
]
)
assert 'tag1' not in [x['id'] for x in device['tags']]
@pytest.mark.xfail(reason='Functionality not yet developed.')
@ -136,7 +144,10 @@ def test_real_hp_11(user: UserClient):
s = file('real-hp.snapshot.11')
snapshot, _ = user.post(res=em.Snapshot, data=s)
pc = snapshot['device']
assert pc['hid'] == 'desktop-hewlett-packard-hp_compaq_8100_elite_sff-czc0408yjg-6c:62:6d:81:22:9f'
assert (
pc['hid']
== 'desktop-hewlett-packard-hp_compaq_8100_elite_sff-czc0408yjg-6c:62:6d:81:22:9f'
)
assert pc['chassis'] == 'Tower'
assert set(e['type'] for e in snapshot['actions']) == {
'BenchmarkDataStorage',
@ -146,7 +157,7 @@ def test_real_hp_11(user: UserClient):
'BenchmarkRamSysbench',
'StressTest',
'TestBios',
'VisualTest'
'VisualTest',
}
assert len(list(e['type'] for e in snapshot['actions'])) == 8
@ -177,22 +188,32 @@ def test_snapshot_real_eee_1001pxd_with_rate(user: UserClient):
assert pc['model'] == '1001pxd'
assert pc['serialNumber'] == 'b8oaas048286'
assert pc['manufacturer'] == 'asustek computer inc.'
assert pc['hid'] == 'laptop-asustek_computer_inc-1001pxd-b8oaas048286-14:da:e9:42:f6:7c'
assert (
pc['hid']
== 'laptop-asustek_computer_inc-1001pxd-b8oaas048286-14:da:e9:42:f6:7c'
)
assert len(pc['tags']) == 1
assert pc['networkSpeeds'] == [100, 0], 'Although it has WiFi we do not know the speed'
assert pc['networkSpeeds'] == [
100,
0,
], 'Although it has WiFi we do not know the speed'
# assert pc['actions'][0]['appearanceRange'] == 'A'
# assert pc['actions'][0]['functionalityRange'] == 'B'
# TODO add appearance and functionality Range in device[rate]
components = snapshot['components']
wifi = components[0]
assert wifi['hid'] == 'networkadapter-qualcomm_atheros-' \
assert (
wifi['hid'] == 'networkadapter-qualcomm_atheros-'
'ar9285_wireless_network_adapter-74_2f_68_8b_fd_c8'
)
assert wifi['serialNumber'] == '74:2f:68:8b:fd:c8'
assert wifi['wireless']
eth = components[1]
assert eth['hid'] == 'networkadapter-qualcomm_atheros-' \
assert (
eth['hid'] == 'networkadapter-qualcomm_atheros-'
'ar8152_v2_0_fast_ethernet-14_da_e9_42_f6_7c'
)
assert eth['speed'] == 100
assert not eth['wireless']
cpu = components[2]
@ -219,7 +240,10 @@ def test_snapshot_real_eee_1001pxd_with_rate(user: UserClient):
assert em.Snapshot.t in action_types
assert len(actions) == 6
gpu = components[3]
assert gpu['model'] == 'atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller'
assert (
gpu['model']
== 'atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller'
)
assert gpu['manufacturer'] == 'intel corporation'
assert gpu['memory'] == 256
gpu, _ = user.get(res=Device, item=gpu['devicehubID'])
@ -285,25 +309,26 @@ SNAPSHOTS_NEED_ID = {
'nox.snapshot.json',
'ecs-computers.snapshot.json',
'custom.snapshot.json',
'ecs-2.snapshot.json'
'ecs-2.snapshot.json',
}
"""Snapshots that do not generate HID requiring a custom ID."""
@pytest.mark.mvp
@pytest.mark.parametrize('file',
(pytest.param(f, id=f.name)
for f in pathlib.Path(__file__).parent.joinpath('workbench_files').iterdir())
)
@pytest.mark.parametrize(
'file',
(
pytest.param(f, id=f.name)
for f in pathlib.Path(__file__).parent.joinpath('workbench_files').iterdir()
),
)
def test_workbench_fixtures(file: pathlib.Path, user: UserClient):
"""Uploads the Snapshot files Workbench tests generate.
Keep this files up to date with the Workbench version.
"""
s = json.load(file.open())
user.post(res=em.Snapshot,
data=json_encode(s),
status=201)
user.post(res=em.Snapshot, data=json_encode(s), status=201)
@pytest.mark.mvp