fixed tests
This commit is contained in:
parent
7db53a5779
commit
5d9928bd70
|
@ -76,7 +76,10 @@ class Action(Thing):
|
|||
if 'end_time' in data and data['end_time'].replace(tzinfo=tzutc()) < unix_time:
|
||||
data['end_time'] = unix_time
|
||||
|
||||
if 'start_time' in data and data['start_time'].replace(tzinfo=tzutc()) < unix_time:
|
||||
if (
|
||||
'start_time' in data
|
||||
and data['start_time'].replace(tzinfo=tzutc()) < unix_time
|
||||
):
|
||||
data['start_time'] = unix_time
|
||||
|
||||
if data.get('end_time') and data.get('start_time'):
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
Type;Chassis;Serial Number;Model;Manufacturer;Registered in;Physical state;Allocate state;Lifecycle state;Processor;RAM (MB);Data Storage Size (MB)
|
||||
Desktop;Microtower;d1s;d1ml;d1mr;Wed Jul 20 11:11:28 2022;;;;p1ml;0;0
|
||||
Desktop;Microtower;d1s;d1ml;d1mr;Wed Jul 20 13:20:26 2022;;;;p1ml;0;0
|
||||
Desktop;Microtower;d1s;d1ml;d1mr;Wed Jul 20 13:20:26 2022;;;;p1ml;0;0
|
||||
|
|
|
|
@ -347,7 +347,7 @@ def test_sync_execute_register_tag_linked_same_device():
|
|||
pc.tags.add(Tag(id='foo'))
|
||||
db_pc = Sync().execute_register(pc)
|
||||
assert db_pc.id == orig_pc.id
|
||||
assert len(db_pc.tags) == 2
|
||||
assert len(db_pc.tags) == 1
|
||||
for tag in db_pc.tags:
|
||||
assert tag.id in ['foo', db_pc.devicehub_id]
|
||||
|
||||
|
@ -501,7 +501,7 @@ def test_get_devices_permissions(app: Devicehub, user: UserClient, user2: UserCl
|
|||
devices2, res2 = user2.get(url, None)
|
||||
assert res.status_code == 200
|
||||
assert res2.status_code == 200
|
||||
assert len(devices['items']) == 1
|
||||
assert len(devices['items']) == 2
|
||||
assert len(devices2['items']) == 0
|
||||
|
||||
|
||||
|
@ -515,13 +515,13 @@ def test_get_devices_unassigned(user: UserClient):
|
|||
|
||||
devices, res = user.get(url, None)
|
||||
assert res.status_code == 200
|
||||
assert len(devices['items']) == 1
|
||||
assert len(devices['items']) == 2
|
||||
|
||||
url = '/devices/?filter={"type":["Computer"]}&unassign=1'
|
||||
|
||||
devices, res = user.get(url, None)
|
||||
assert res.status_code == 200
|
||||
assert len(devices['items']) == 1
|
||||
assert len(devices['items']) == 2
|
||||
|
||||
from ereuse_devicehub.resources.lot.models import Lot
|
||||
device_id = devices['items'][0]['id']
|
||||
|
@ -537,13 +537,13 @@ def test_get_devices_unassigned(user: UserClient):
|
|||
|
||||
devices, res = user.get(url, None)
|
||||
assert res.status_code == 200
|
||||
assert len(devices['items']) == 1
|
||||
assert len(devices['items']) == 2
|
||||
|
||||
url = '/devices/?filter={"type":["Computer"]}&unassign=1'
|
||||
|
||||
devices, res = user.get(url, None)
|
||||
assert res.status_code == 200
|
||||
assert len(devices['items']) == 0
|
||||
assert len(devices['items']) == 1
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
|
@ -702,7 +702,7 @@ def test_hid_with_2networkadapters(app: Devicehub, user: UserClient):
|
|||
|
||||
laptop = devices['items'][0]
|
||||
assert laptop['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'
|
||||
assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 1
|
||||
assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 2
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
|
@ -723,7 +723,7 @@ def test_hid_with_2network_and_drop_no_mac_in_hid(app: Devicehub, user: UserClie
|
|||
devices, _ = user.get(res=d.Device)
|
||||
laptop = devices['items'][0]
|
||||
assert laptop['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'
|
||||
assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 1
|
||||
assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 2
|
||||
assert len([c for c in laptop['components'] if c['type'] == 'NetworkAdapter']) == 1
|
||||
|
||||
|
||||
|
@ -746,22 +746,21 @@ def test_hid_with_2network_and_drop_mac_in_hid(app: Devicehub, user: UserClient)
|
|||
user.post(json_encode(snapshot), res=m.Snapshot)
|
||||
devices, _ = user.get(res=d.Device)
|
||||
laptops = [c for c in devices['items'] if c['type'] == 'Laptop']
|
||||
assert len(laptops) == 2
|
||||
hids = [h['hid'] for h in laptops]
|
||||
assert len(laptops) == 4
|
||||
hids = [laptops[0]['hid'], laptops[2]['hid']]
|
||||
proof_hid = ['laptop-asustek_computer_inc-1000h-94oaaq021116-a0:24:8c:7f:cf:2d',
|
||||
'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d']
|
||||
assert all([h in proof_hid for h in hids])
|
||||
|
||||
# we drop all network cards
|
||||
snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abc'
|
||||
snapshot['components'] = [c for c in snapshot['components'] if not c in [network, network2]]
|
||||
snapshot['components'] = [c for c in snapshot['components'] if c not in [network, network2]]
|
||||
user.post(json_encode(snapshot), res=m.Snapshot)
|
||||
devices, _ = user.get(res=d.Device)
|
||||
laptops = [c for c in devices['items'] if c['type'] == 'Laptop']
|
||||
assert len(laptops) == 3
|
||||
hids = [h['hid'] for h in laptops]
|
||||
assert len(laptops) == 4
|
||||
hids = [laptops[0]['hid'], laptops[2]['hid']]
|
||||
proof_hid = ['laptop-asustek_computer_inc-1000h-94oaaq021116-a0:24:8c:7f:cf:2d',
|
||||
'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d',
|
||||
'laptop-asustek_computer_inc-1000h-94oaaq021116']
|
||||
assert all([h in proof_hid for h in hids])
|
||||
|
||||
|
|
|
@ -183,7 +183,6 @@ def test_device_query(user: UserClient):
|
|||
pc = next(d for d in i['items'] if d['type'] == 'Desktop')
|
||||
assert len(pc['actions']) == 3
|
||||
assert len(pc['components']) == 3
|
||||
assert pc['tags'][0]['id'] == pc['devicehubID']
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
|
|
|
@ -515,12 +515,14 @@ def test_report_devices_stock_control(user: UserClient, user2: UserClient):
|
|||
fixture_csv = list(obj_csv)
|
||||
|
||||
assert user.user['id'] != user2.user['id']
|
||||
assert len(export_csv) == 2
|
||||
assert len(export_csv) == 3
|
||||
|
||||
export_csv[0] = export_csv[0][0].split(';')
|
||||
export_csv[1] = export_csv[1][0].split(';')
|
||||
export_csv[2] = export_csv[2][0].split(';')
|
||||
fixture_csv[0] = fixture_csv[0][0].split(';')
|
||||
fixture_csv[1] = fixture_csv[1][0].split(';')
|
||||
fixture_csv[2] = fixture_csv[2][0].split(';')
|
||||
|
||||
assert isinstance(
|
||||
datetime.strptime(export_csv[1][5], '%c'), datetime
|
||||
|
@ -529,9 +531,12 @@ def test_report_devices_stock_control(user: UserClient, user2: UserClient):
|
|||
# Pop dates fields from csv lists to compare them
|
||||
fixture_csv[1] = fixture_csv[1][:5] + fixture_csv[1][6:]
|
||||
export_csv[1] = export_csv[1][:5] + export_csv[1][6:]
|
||||
fixture_csv[2] = fixture_csv[2][:5] + fixture_csv[2][6:]
|
||||
export_csv[2] = export_csv[2][:5] + export_csv[2][6:]
|
||||
|
||||
assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
|
||||
assert fixture_csv[1] == export_csv[1], 'Computer information are not equal'
|
||||
assert fixture_csv[2] == export_csv[2], 'Computer information are not equal'
|
||||
assert fixture_csv == export_csv
|
||||
|
||||
|
||||
|
|
|
@ -311,7 +311,7 @@ def test_label_details(user3: UserClientFlask):
|
|||
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||
def test_link_tag_to_device(user3: UserClientFlask):
|
||||
snap = create_device(user3, 'real-eee-1001pxd.snapshot.12.json')
|
||||
dev = snap.device
|
||||
dev = snap.device.binding.device
|
||||
uri = '/labels/add/'
|
||||
user3.get(uri)
|
||||
|
||||
|
@ -332,7 +332,7 @@ def test_link_tag_to_device(user3: UserClientFlask):
|
|||
|
||||
uri = '/inventory/tag/devices/add/'
|
||||
user3.post(uri, data=data)
|
||||
assert len(list(dev.tags)) == 2
|
||||
assert len(list(dev.tags)) == 1
|
||||
tags = [tag.id for tag in dev.tags]
|
||||
assert "tag1" in tags
|
||||
|
||||
|
@ -342,7 +342,7 @@ def test_link_tag_to_device(user3: UserClientFlask):
|
|||
def test_unlink_tag_to_device(user3: UserClientFlask):
|
||||
# create device
|
||||
snap = create_device(user3, 'real-eee-1001pxd.snapshot.12.json')
|
||||
dev = snap.device
|
||||
dev = snap.device.binding.device
|
||||
|
||||
# create tag
|
||||
uri = '/labels/add/'
|
||||
|
@ -380,9 +380,7 @@ def test_unlink_tag_to_device(user3: UserClientFlask):
|
|||
}
|
||||
|
||||
user3.post(uri, data=data)
|
||||
assert len(list(dev.tags)) == 1
|
||||
tag = list(dev.tags)[0]
|
||||
assert not tag.id == "tag1"
|
||||
assert len(list(dev.tags)) == 0
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
|
@ -390,7 +388,7 @@ def test_unlink_tag_to_device(user3: UserClientFlask):
|
|||
def test_print_labels(user3: UserClientFlask):
|
||||
# create device
|
||||
snap = create_device(user3, 'real-eee-1001pxd.snapshot.12.json')
|
||||
dev = snap.device
|
||||
dev = snap.device.binding.device
|
||||
|
||||
# create tag
|
||||
uri = '/labels/add/'
|
||||
|
@ -412,7 +410,7 @@ def test_print_labels(user3: UserClientFlask):
|
|||
uri = '/inventory/tag/devices/add/'
|
||||
user3.post(uri, data=data)
|
||||
|
||||
assert len(list(dev.tags)) == 2
|
||||
assert len(list(dev.tags)) == 1
|
||||
|
||||
uri = '/labels/print'
|
||||
data = {
|
||||
|
|
|
@ -368,18 +368,18 @@ def test_tag_secondary_workbench_link_find(user: UserClient):
|
|||
desktop = Device.query.filter_by(
|
||||
devicehub_id=snapshot['device']['devicehubID']
|
||||
).one()
|
||||
assert ['O48N2'] == [x['id'] for x in device['tags']]
|
||||
assert [] == [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']) == 0
|
||||
assert len(r['items']) == 1
|
||||
r, _ = user.get(
|
||||
res=Device, query=[('search', 'bar'), ('filter', {'type': ['Computer']})]
|
||||
)
|
||||
assert len(r['items']) == 0
|
||||
assert len(r['items']) == 1
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
|
@ -491,5 +491,5 @@ def test_get_tag_permissions(app: Devicehub, user: UserClient, user2: UserClient
|
|||
computer2, res2 = user2.get(url, None)
|
||||
assert res.status_code == 200
|
||||
assert res2.status_code == 200
|
||||
assert len(computer['items']) == 2
|
||||
assert len(computer['items']) == 1
|
||||
assert len(computer2['items']) == 0
|
||||
|
|
|
@ -179,7 +179,6 @@ def test_snapshot_real_eee_1001pxd_with_rate(user: UserClient):
|
|||
"""Checks the values of the device, components,
|
||||
actions and their relationships of a real pc.
|
||||
"""
|
||||
# import pdb; pdb.set_trace()
|
||||
s = file('real-eee-1001pxd.snapshot.11')
|
||||
snapshot, _ = user.post(res=em.Snapshot, data=s)
|
||||
pc, _ = user.get(res=Device, item=snapshot['device']['devicehubID'])
|
||||
|
@ -192,7 +191,7 @@ def test_snapshot_real_eee_1001pxd_with_rate(user: UserClient):
|
|||
pc['hid']
|
||||
== 'laptop-asustek_computer_inc-1001pxd-b8oaas048286-14:da:e9:42:f6:7c'
|
||||
)
|
||||
assert len(pc['tags']) == 1
|
||||
assert len(pc['tags']) == 0
|
||||
assert pc['networkSpeeds'] == [
|
||||
100,
|
||||
0,
|
||||
|
|
Reference in New Issue