fixing tests

This commit is contained in:
Cayo Puigdefabregas 2021-04-16 12:45:14 +02:00
parent 68ffa0ddff
commit 4122ac165e
1 changed files with 75 additions and 74 deletions

View File

@ -65,13 +65,13 @@ def test_device_model():
gcard = d.GraphicCard.query.one() gcard = d.GraphicCard.query.one()
db.session.delete(pc) db.session.delete(pc)
db.session.flush() db.session.flush()
assert pc.id == 1 assert pc.id == 3
assert d.Desktop.query.first() is None assert d.Desktop.query.first() is None
db.session.commit() db.session.commit()
assert d.Desktop.query.first() is None assert d.Desktop.query.first() is None
assert network_adapter.id == 2 assert network_adapter.id == 4
assert d.NetworkAdapter.query.first() is not None, 'We removed the network adaptor' assert d.NetworkAdapter.query.first() is not None, 'We removed the network adaptor'
assert gcard.id == 3, 'We should still hold a reference to a zombie graphic card' assert gcard.id == 5, 'We should still hold a reference to a zombie graphic card'
assert d.GraphicCard.query.first() is None, 'We should have deleted it it was inside the pc' assert d.GraphicCard.query.first() is None, 'We should have deleted it it was inside the pc'
@ -396,9 +396,9 @@ def test_sync_execute_register_mismatch_between_tags_and_hid():
@pytest.mark.mvp @pytest.mark.mvp
def test_get_device(app: Devicehub, user: UserClient): @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_get_device(user: UserClient):
"""Checks GETting a d.Desktop with its components.""" """Checks GETting a d.Desktop with its components."""
with app.app_context():
pc = d.Desktop(model='p1mo', pc = d.Desktop(model='p1mo',
manufacturer='p1ma', manufacturer='p1ma',
serial_number='p1s', serial_number='p1s',
@ -416,27 +416,27 @@ def test_get_device(app: Devicehub, user: UserClient):
agent=Person(name='Timmy'), agent=Person(name='Timmy'),
author=User(email='bar@bar.com'))) author=User(email='bar@bar.com')))
db.session.commit() db.session.commit()
pc, _ = user.get(res=d.Device, item=1) pc_api, _ = user.get(res=d.Device, item=pc.id)
assert len(pc['actions']) == 1 assert len(pc_api['actions']) == 1
assert pc['actions'][0]['type'] == 'TestConnectivity' assert pc_api['actions'][0]['type'] == 'TestConnectivity'
assert pc['actions'][0]['device'] == 1 assert pc_api['actions'][0]['device'] == pc.id
assert pc['actions'][0]['severity'] == 'Info' assert pc_api['actions'][0]['severity'] == 'Info'
assert UUID(pc['actions'][0]['author']) assert UUID(pc_api['actions'][0]['author'])
assert 'actions_components' not in pc, 'actions_components are internal use only' assert 'actions_components' not in pc_api, 'actions_components are internal use only'
assert 'actions_one' not in pc, 'they are internal use only' assert 'actions_one' not in pc_api, 'they are internal use only'
assert 'author' not in pc assert 'author' not in pc_api
assert tuple(c['id'] for c in pc['components']) == (2, 3) assert tuple(c['id'] for c in pc_api['components']) == tuple(c.id for c in pc.components)
assert pc['hid'] == 'desktop-p1ma-p1mo-p1s' assert pc_api['hid'] == 'desktop-p1ma-p1mo-p1s'
assert pc['model'] == 'p1mo' assert pc_api['model'] == 'p1mo'
assert pc['manufacturer'] == 'p1ma' assert pc_api['manufacturer'] == 'p1ma'
assert pc['serialNumber'] == 'p1s' assert pc_api['serialNumber'] == 'p1s'
assert pc['type'] == d.Desktop.t assert pc_api['type'] == d.Desktop.t
@pytest.mark.mvp @pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_get_devices(app: Devicehub, user: UserClient): def test_get_devices(app: Devicehub, user: UserClient):
"""Checks GETting multiple devices.""" """Checks GETting multiple devices."""
with app.app_context():
pc = d.Desktop(model='p1mo', pc = d.Desktop(model='p1mo',
manufacturer='p1ma', manufacturer='p1ma',
serial_number='p1s', serial_number='p1s',
@ -461,7 +461,8 @@ def test_get_devices(app: Devicehub, user: UserClient):
db.session.add_all((pc, pc1, pc2)) db.session.add_all((pc, pc1, pc2))
db.session.commit() db.session.commit()
devices, _ = user.get(res=d.Device) devices, _ = user.get(res=d.Device)
assert tuple(dev['id'] for dev in devices['items']) == (1, 2, 3, 4, 5) ids = (pc.id, pc1.id, pc2.id, pc.components[0].id, pc.components[1].id)
assert tuple(dev['id'] for dev in devices['items']) == ids
assert tuple(dev['type'] for dev in devices['items']) == ( assert tuple(dev['type'] for dev in devices['items']) == (
d.Desktop.t, d.Desktop.t, d.Laptop.t, d.NetworkAdapter.t, d.GraphicCard.t d.Desktop.t, d.Desktop.t, d.Laptop.t, d.NetworkAdapter.t, d.GraphicCard.t
) )
@ -534,7 +535,7 @@ def test_device_properties_format(app: Devicehub, user: UserClient):
user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot) user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
with app.app_context(): with app.app_context():
pc = d.Laptop.query.one() # type: d.Laptop pc = d.Laptop.query.one() # type: d.Laptop
assert format(pc) == 'Laptop 1: model 1000h, S/N 94oaaq021116' assert format(pc) == 'Laptop 3: model 1000h, S/N 94oaaq021116'
assert format(pc, 't') == 'Netbook 1000h' assert format(pc, 't') == 'Netbook 1000h'
assert format(pc, 's') == '(asustek computer inc.) S/N 94OAAQ021116' assert format(pc, 's') == '(asustek computer inc.) S/N 94OAAQ021116'
assert pc.ram_size == 1024 assert pc.ram_size == 1024
@ -542,12 +543,12 @@ def test_device_properties_format(app: Devicehub, user: UserClient):
assert pc.graphic_card_model == 'mobile 945gse express integrated graphics controller' assert pc.graphic_card_model == 'mobile 945gse express integrated graphics controller'
assert pc.processor_model == 'intel atom cpu n270 @ 1.60ghz' assert pc.processor_model == 'intel atom cpu n270 @ 1.60ghz'
net = next(c for c in pc.components if isinstance(c, d.NetworkAdapter)) net = next(c for c in pc.components if isinstance(c, d.NetworkAdapter))
assert format(net) == 'NetworkAdapter 2: model ar8121/ar8113/ar8114 ' \ assert format(net) == 'NetworkAdapter 4: model ar8121/ar8113/ar8114 ' \
'gigabit or fast ethernet, S/N 00:24:8c:7f:cf:2d' 'gigabit or fast ethernet, S/N 00:24:8c:7f:cf:2d'
assert format(net, 't') == 'NetworkAdapter ar8121/ar8113/ar8114 gigabit or fast ethernet' assert format(net, 't') == 'NetworkAdapter ar8121/ar8113/ar8114 gigabit or fast ethernet'
assert format(net, 's') == 'qualcomm atheros 00:24:8C:7F:CF:2D 100 Mbps' assert format(net, 's') == 'qualcomm atheros 00:24:8C:7F:CF:2D 100 Mbps'
hdd = next(c for c in pc.components if isinstance(c, d.DataStorage)) hdd = next(c for c in pc.components if isinstance(c, d.DataStorage))
assert format(hdd) == 'HardDrive 7: model st9160310as, S/N 5sv4tqa6' assert format(hdd) == 'HardDrive 9: model st9160310as, S/N 5sv4tqa6'
assert format(hdd, 't') == 'HardDrive st9160310as' assert format(hdd, 't') == 'HardDrive st9160310as'
assert format(hdd, 's') == 'seagate 5SV4TQA6 152 GB' assert format(hdd, 's') == 'seagate 5SV4TQA6 152 GB'
@ -615,7 +616,7 @@ def test_hid_with_mac(app: Devicehub, user: UserClient):
"""Checks hid with mac.""" """Checks hid with mac."""
snapshot = file('asus-eee-1000h.snapshot.11') snapshot = file('asus-eee-1000h.snapshot.11')
user.post(snapshot, res=m.Snapshot) user.post(snapshot, res=m.Snapshot)
pc, _ = user.get(res=d.Device, item=1) pc, _ = user.get(res=d.Device, item=3)
assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'
@ -624,8 +625,8 @@ def test_hid_without_mac(app: Devicehub, user: UserClient):
"""Checks hid without mac.""" """Checks hid without mac."""
snapshot = file('asus-eee-1000h.snapshot.11') snapshot = file('asus-eee-1000h.snapshot.11')
snapshot['components'] = [c for c in snapshot['components'] if c['type'] != 'NetworkAdapter'] snapshot['components'] = [c for c in snapshot['components'] if c['type'] != 'NetworkAdapter']
user.post(snapshot, res=m.Snapshot) snap, _ = user.post(snapshot, res=m.Snapshot)
pc, _ = user.get(res=d.Device, item=1) pc, _ = user.get(res=d.Device, item=snap['device']['id'])
assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116' assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116'
@ -635,8 +636,8 @@ def test_hid_with_mac_none(app: Devicehub, user: UserClient):
snapshot = file('asus-eee-1000h.snapshot.11') snapshot = file('asus-eee-1000h.snapshot.11')
network = [c for c in snapshot['components'] if c['type'] == 'NetworkAdapter'][0] network = [c for c in snapshot['components'] if c['type'] == 'NetworkAdapter'][0]
network['serialNumber'] = None network['serialNumber'] = None
user.post(snapshot, res=m.Snapshot) snap, _ = user.post(snapshot, res=m.Snapshot)
pc, _ = user.get(res=d.Device, item=1) pc, _ = user.get(res=d.Device, item=snap['device']['id'])
assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116' assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116'
@ -664,8 +665,8 @@ def test_hid_with_2network_and_drop_no_mac_in_hid(app: Devicehub, user: UserClie
network2 = copy.copy(network) network2 = copy.copy(network)
snapshot['components'].append(network2) snapshot['components'].append(network2)
network['serialNumber'] = 'a0:24:8c:7f:cf:2d' network['serialNumber'] = 'a0:24:8c:7f:cf:2d'
user.post(snapshot, res=m.Snapshot) snap, _ = user.post(snapshot, res=m.Snapshot)
pc, _ = user.get(res=d.Device, item=1) pc, _ = user.get(res=d.Device, item=snap['device']['id'])
assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'
snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abb' snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abb'
@ -687,8 +688,8 @@ def test_hid_with_2network_and_drop_mac_in_hid(app: Devicehub, user: UserClient)
network2 = copy.copy(network) network2 = copy.copy(network)
snapshot['components'].append(network2) snapshot['components'].append(network2)
network['serialNumber'] = 'a0:24:8c:7f:cf:2d' network['serialNumber'] = 'a0:24:8c:7f:cf:2d'
user.post(snapshot, res=m.Snapshot) snap, _ = user.post(snapshot, res=m.Snapshot)
pc, _ = user.get(res=d.Device, item=1) pc, _ = user.get(res=d.Device, item=snap['device']['id'])
assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'
# we drop the network card then is used for to build the hid # we drop the network card then is used for to build the hid