From 1bfb80de520b2621b66b7d76281b5ae86c34d41c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 22 Oct 2021 22:34:32 +0200 Subject: [PATCH] fixing tests --- tests/test_device.py | 17 ++++++++++++----- tests/test_device_find.py | 6 +++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/test_device.py b/tests/test_device.py index 9dcfd53f..4f366c51 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -309,9 +309,10 @@ def test_sync_execute_register_no_hid_tag_not_linked(tag_id: str): # they are not the same tags though # tag is a transient obj and db_tag the one from the db # they have the same pk though - assert tag != db_tag, 'They are not the same tags though' - assert db_tag.id == tag.id assert d.Desktop.query.one() == pc, 'd.Desktop had to be set to db' + assert tag != db_tag, 'They are not the same tags though' + for tag in pc.tags: + assert tag.id in ['foo', pc.devicehub_id] @pytest.mark.mvp @@ -346,8 +347,10 @@ 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) == 1 - assert next(iter(db_pc.tags)).id == 'foo' + assert len(db_pc.tags) == 2 + # import pdb; pdb.set_trace() + for tag in db_pc.tags: + assert tag.id in ['foo', db_pc.devicehub_id] @pytest.mark.mvp @@ -399,13 +402,14 @@ def test_sync_execute_register_mismatch_between_tags_and_hid(): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_get_device(user: UserClient): """Checks GETting a d.Desktop with its components.""" + g.user = User.query.one() pc = d.Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s', chassis=ComputerChassis.Tower, owner_id=user.user['id']) pc.components = OrderedSet([ - d.NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s', + d.NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s', owner_id=user.user['id']), d.GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500, owner_id=user.user['id']) ]) @@ -437,6 +441,7 @@ def test_get_device(user: UserClient): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_get_devices(app: Devicehub, user: UserClient): """Checks GETting multiple devices.""" + g.user = User.query.one() pc = d.Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s', @@ -604,6 +609,7 @@ def test_device_public(user: UserClient, client: Client): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) def test_computer_accessory_model(user: UserClient): + g.user = User.query.one() sai = d.SAI(owner_id=user.user['id']) db.session.add(sai) keyboard = d.Keyboard(layout=Layouts.ES, owner_id=user.user['id']) @@ -616,6 +622,7 @@ def test_computer_accessory_model(user: UserClient): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) def test_networking_model(user: UserClient): + g.user = User.query.one() router = d.Router(speed=1000, wireless=True, owner_id=user.user['id']) db.session.add(router) switch = d.Switch(speed=1000, wireless=False, owner_id=user.user['id']) diff --git a/tests/test_device_find.py b/tests/test_device_find.py index 306dae32..7407f3f8 100644 --- a/tests/test_device_find.py +++ b/tests/test_device_find.py @@ -183,7 +183,7 @@ def test_device_query(user: UserClient): pc = next(d for d in i['items'] if d['type'] == 'Desktop') assert len(pc['actions']) == 4 assert len(pc['components']) == 3 - assert not pc['tags'] + assert pc['tags'][0]['id'] == pc['devicehubID'] @pytest.mark.mvp @@ -201,10 +201,10 @@ def test_device_query_permitions(user: UserClient, user2: UserClient): user2.post(json_encode(basic_snapshot), res=Snapshot) i2, _ = user2.get(res=Device) pc2 = next(d for d in i2['items'] if d['type'] == 'Desktop') - + assert pc1['id'] != pc2['id'] assert pc1['hid'] == pc2['hid'] - + @pytest.mark.mvp def test_device_search_all_devices_token_if_empty(app: Devicehub, user: UserClient):