def test_lot_post_add_remove_device_view(app: Devicehub, user: UserClient): """Tests adding a device to a lot using POST and removing it with DELETE.""" # todo check with components with app.app_context(): device = Desktop(serial_number='foo', model='bar', manufacturer='foobar', chassis=ComputerChassis.Lunchbox) db.session.add(device) db.session.commit() device_id = device.id parent, _ = user.post(({'name': 'lot'}), res=Lot) lot, _ = user.post({}, res=Lot, item='{}/devices'.format(parent['id']), query=[('id', device_id)]) assert lot['devices'][0]['id'] == device_id, 'Lot contains device' device, _ = user.get(res=Device, item=device_id) assert len(device['lots']) == 1 assert device['lots'][0]['id'] == lot['id'], 'Device is inside lot' # Remove the device lot, _ = user.delete(res=Lot, item='{}/devices'.format(parent['id']), query=[('id', device_id)], status=200) assert not len(lot['devices'])
def test_not_remove_ram_in_same_computer(user: UserClient): """Tests a Snapshot We want check than all components is not duplicate in a second snapshot of the same device. """ s = yaml2json('erase-sectors.snapshot') s['device']['type'] = 'Server' snap1, _ = user.post(json_encode(s), res=Snapshot) s['uuid'] = '74caa7eb-2bad-4333-94f6-6f1b031d0774' s['components'].append({ "actions": [], "manufacturer": "Intel Corporation", "model": "NM10/ICH7 Family High Definition Audio Controller", "serialNumber": "mp2pc", "type": "SoundCard" }) dev1 = m.Device.query.filter_by(id=snap1['device']['id']).one() ram1 = [x.id for x in dev1.components if x.type == 'RamModule'][0] snap2, _ = user.post(json_encode(s), res=Snapshot) dev2 = m.Device.query.filter_by(id=snap2['device']['id']).one() ram2 = [x.id for x in dev2.components if x.type == 'RamModule'][0] assert ram1 != ram2 assert len(dev1.components) == 4 assert len(dev2.components) == 4 assert dev1.id == dev2.id assert dev1.components == dev2.components
def test_export_full_snapshot(user: UserClient): """ Test a export device with all information and a lot of components """ snapshot, _ = user.post(file('real-eee-1001pxd.snapshot.11'), res=Snapshot) csv_str, _ = user.get(res=documents.DocumentDef.t, item='devices/', accept='text/csv', query=[('filter', {'type': ['Computer']})]) f = StringIO(csv_str) obj_csv = csv.reader(f, f) export_csv = list(obj_csv) # Open fixture csv and transform to list with Path(__file__).parent.joinpath('files').joinpath('real-eee-1001pxd.csv').open() \ as csv_file: obj_csv = csv.reader(csv_file) fixture_csv = list(obj_csv) assert isinstance(datetime.strptime(export_csv[1][8], '%c'), datetime), \ 'Register in field is not a datetime' # Pop dates fields from csv lists to compare them fixture_csv[1] = fixture_csv[1][:8] + fixture_csv[1][9:] export_csv[1] = export_csv[1][:8] + export_csv[1][9:] assert fixture_csv[0] == export_csv[0], 'Headers are not equal' assert fixture_csv[1] == export_csv[1], 'Computer information are not equal'
def test_lot_post_add_remove_device_view(user: UserClient): """Tests adding a device to a lot using POST and removing it with DELETE. """ # todo check with components g.user = User.query.one() device = Desktop(serial_number='foo', model='bar', manufacturer='foobar', chassis=ComputerChassis.Lunchbox, owner_id=user.user['id']) db.session.add(device) db.session.commit() device_id = device.id devicehub_id = device.devicehub_id parent, _ = user.post(({'name': 'lot'}), res=Lot) lot, _ = user.post({}, res=Lot, item='{}/devices'.format(parent['id']), query=[('id', device_id)]) lot = Lot.query.filter_by(id=lot['id']).one() assert list(lot.devices)[0].id == device_id, 'Lot contains device' device = Device.query.filter_by(devicehub_id=devicehub_id).one() assert len(device.lots) == 1 # assert device['lots'][0]['id'] == lot['id'], 'Device is inside lot' assert list(device.lots)[0].id == lot.id, 'Device is inside lot' # Remove the device user.delete(res=Lot, item='{}/devices'.format(parent['id']), query=[('id', device_id)], status=200) assert not len(lot.devices)
def test_snapshot_post(user: UserClient): """ Tests the post snapshot endpoint (validation, etc), data correctness, and relationship correctness. """ snapshot = snapshot_and_check(user, file('basic.snapshot'), event_types=( WorkbenchRate.t, AggregateRate.t, BenchmarkProcessor.t ), perform_second_snapshot=False) assert snapshot['software'] == 'Workbench' assert snapshot['version'] == '11.0' assert snapshot['uuid'] == 'f5efd26e-8754-46bc-87bf-fbccc39d60d9' assert snapshot['elapsed'] == 4 assert snapshot['author']['id'] == user.user['id'] assert 'events' not in snapshot['device'] assert 'author' not in snapshot['device'] device, _ = user.get(res=m.Device, item=snapshot['device']['id']) key = itemgetter('serialNumber') snapshot['components'].sort(key=key) device['components'].sort(key=key) assert snapshot['components'] == device['components'] assert {c['type'] for c in snapshot['components']} == {m.GraphicCard.t, m.RamModule.t, m.Processor.t} rate = next(e for e in snapshot['events'] if e['type'] == WorkbenchRate.t) rate, _ = user.get(res=Event, item=rate['id']) assert rate['device']['id'] == snapshot['device']['id'] rate['components'].sort(key=key) assert rate['components'] == snapshot['components'] assert rate['snapshot']['id'] == snapshot['id']
def test_export_multiple_devices(user: UserClient): """ Test a export multiple devices (Computers and other types) with different information """ # Post all devices snapshots snapshot_pc, _ = user.post(file('real-eee-1001pxd.snapshot.11'), res=Snapshot) snapshot_empty, _ = user.post(file('basic.snapshot'), res=Snapshot) snapshot_keyboard, _ = user.post(file('keyboard.snapshot'), res=Snapshot) snapshot_monitor, _ = user.post(file('computer-monitor.snapshot'), res=Snapshot) # need query param?? csv_str, _ = user.get(res=documents.DocumentDef.t, item='devices/', accept='text/csv') f = StringIO(csv_str) obj_csv = csv.reader(f, f) export_csv = list(obj_csv) # Open fixture csv and transform to list with Path(__file__).parent.joinpath('files').joinpath('multiples_devices.csv').open() \ as csv_file: obj_csv = csv.reader(csv_file) fixture_csv = list(obj_csv) assert fixture_csv[0] == export_csv[0], 'Headers are not equal' max_range = max(len(export_csv), len(fixture_csv)) - 1 # check if all devices information is correct for i in range(1, max_range): if isinstance(datetime.strptime(export_csv[i][8], '%c'), datetime): export_csv[i] = export_csv[i][:8] + export_csv[i][9:] fixture_csv[i] = fixture_csv[i][:8] + fixture_csv[i][9:] assert fixture_csv[i] == export_csv[i], 'Some fields are not equal'
def test_tag_get_device_from_tag_endpoint_no_linked(app: Devicehub, user: UserClient): """As above, but when the tag is not linked.""" with app.app_context(): db.session.add(Tag(id='foo-bar')) db.session.commit() user.get(res=Tag, item='foo-bar/device', status=TagNotLinked)
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']) db.session.add(tag) db.session.commit() assert not tag.printable requests_mock.post('https://example.com/', # request request_headers={ 'Authorization': 'Basic {}'.format(DevicehubClient.encode_token( '52dacef0-6bcb-4919-bfed-f10d2c96ecee')) }, # response json=['tag1id', 'tag2id'], status_code=201) user.post({}, res=Tag, query=[('num', 2)]) # Test itself data, _ = user.get(res=Tag) assert len(data['items']) == 2, 'Only 2 tags are printable, thus retreived' # Order is created descending assert data['items'][0]['id'] == 'tag2id' assert data['items'][0]['printable'] assert data['items'][1]['id'] == 'tag1id' assert data['items'][1]['printable'], 'Tags made this way are printable'
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. """ g.user = User.query.all()[0] db.session.add(Tag(id='foo', secondary='bar', owner_id=user.user['id'])) db.session.commit() db.session.add(Tag(id='foo', secondary='bar', owner_id=user2.user['id'])) db.session.commit() db.session.add(Tag(id='foo2', secondary='bar', owner_id=user.user['id'])) with raises(DBError): db.session.commit() db.session.rollback() 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.tags.add(tag1) pc2.tags.add(tag2) db.session.add(pc1) db.session.add(pc2) db.session.commit() computer, _ = user.get(res=Tag, item='foo/device') assert computer['serialNumber'] == 'sn1' computer, _ = user2.get(res=Tag, item='foo/device') assert computer['serialNumber'] == 'sn2' _, status = client.get(res=Tag, item='foo/device', status=MultipleResourcesFound) assert status.status_code == 422
def test_lot_error_add_device_from_other_user(user: UserClient): # TODO """Tests adding a device to a lot using POST and removing it with DELETE. """ g.user = User.query.one() user2 = User(email='*****@*****.**', password='******') user2.individuals.add(Person(name='Tommy')) db.session.add(user2) db.session.commit() device = Desktop(serial_number='foo', model='bar', manufacturer='foobar', chassis=ComputerChassis.Lunchbox, owner_id=user2.id) db.session.add(device) db.session.commit() device_id = device.id parent, _ = user.post(({'name': 'lot'}), res=Lot) lot, _ = user.post({}, res=Lot, item='{}/devices'.format(parent['id']), query=[('id', device_id)]) lot = Lot.query.filter_by(id=lot['id']).one() assert list(lot.devices) == [], 'Lot contains device' assert len(lot.devices) == 0
def test_bug_141(user: UserClient): """This test check one bug that create a problem when try to up one snapshot with a big number in the parameter command_timeout of the DataStorage """ dev = file('2021-5-4-13-41_time_out_test_datastorage') user.post(dev, res=Snapshot)
def create_client(self, email='*****@*****.**', password='******'): client = UserClient(self, email, password, response_wrapper=self.response_class) client.login() return client
def test_hid_with_mac(app: Devicehub, user: UserClient): """Checks hid with mac.""" snapshot = file('asus-eee-1000h.snapshot.11') snap, _ = user.post(snapshot, res=m.Snapshot) pc, _ = user.get(res=d.Device, item=snap['device']['devicehubID']) assert pc[ 'hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'
def test_rate_with_multiple_visual_tests(user: UserClient): """Perform a ComputerRate and then update the device with a new VisualTest. Devicehub must make the final rate with the first computer rate plus the new visual test, without considering the appearance / functionality values of the computer rate. """ s = file('real-hp.snapshot.11') snapshot, _ = user.post(s, res=Snapshot) device, _ = user.get(res=Device, item=snapshot['device']['devicehubID']) visual_test = next(e for e in reversed(device['actions']) if e['type'] == VisualTest.t) assert visual_test['appearanceRange'] == 'B' assert visual_test['functionalityRange'] == 'D' assert device['rate']['rating'] == 2 # Adding new visual test user.post( { 'type': 'VisualTest', 'device': device['id'], 'appearanceRange': 'A', 'functionalityRange': 'A' }, res=Action) device, _ = user.get(res=Device, item=snapshot['device']['devicehubID']) visual_test = next(e for e in reversed(device['actions']) if e['type'] == VisualTest.t) assert visual_test['appearanceRange'] == 'A' assert visual_test['functionalityRange'] == 'A' assert device['rate']['rating'] == 3.7
def test_workbench_server_condensed(user: UserClient): """ As :def:`.test_workbench_server_phases` but all the events condensed in only one big ``Snapshot`` file, as described in the docs. """ s = file('workbench-server-1.snapshot') del s['expectedEvents'] s['device']['events'].append(file('workbench-server-2.stress-test')) s['components'][4]['events'].extend( (file('workbench-server-3.erase'), file('workbench-server-4.install'))) s['components'][5]['events'] = [file('workbench-server-3.erase')] # Create tags user.post(res=Tag, query=[('ids', t['id']) for t in s['device']['tags']], data={}) snapshot, _ = user.post(res=Snapshot, data=s) events = snapshot['events'] assert {(event['type'], event['device']) for event in events} == { # todo missing Rate event aggregating the rates ('WorkbenchRate', 1), ('BenchmarkProcessorSysbench', 5), ('StressTest', 1), ('EraseSectors', 6), ('BenchmarkRamSysbench', 1), ('BenchmarkProcessor', 5), ('Install', 6), ('EraseSectors', 7), ('BenchmarkDataStorage', 6), ('TestDataStorage', 6) } assert snapshot['closed'] assert not snapshot['error']
def test_when_rate_must_not_compute(user: UserClient): """Test to check if rate is computed in case of should not be calculated: 1. Snapshot haven't visual test 2. Snapshot software aren't Workbench 3. Device type are not Computer ... """ # Checking case 1 s = yaml2json('basic.snapshot') # Delete snapshot device actions to delete VisualTest del s['device']['actions'] # Post to compute rate and check to didn't do it snapshot, _ = user.post(json_encode(s), res=Snapshot) assert 'rate' not in snapshot['device'] # Checking case 2 s = yaml2json('basic.snapshot') # Change snapshot software source s['software'] = 'Web' del s['uuid'] del s['elapsed'] del s['components'] # Post to compute rate and check to didn't do it snapshot, _ = user.post(json_encode(s), res=Snapshot) assert 'rate' not in snapshot['device'] # Checking case 3 s = yaml2json('keyboard.snapshot') # Post to compute rate and check to didn't do it snapshot, _ = user.post(json_encode(s), res=Snapshot) assert 'rate' not in snapshot['device']
def test_snapshot_post(user: UserClient): """ Tests the post snapshot endpoint (validation, etc), data correctness, and relationship correctness. """ snapshot = snapshot_and_check(user, file('basic.snapshot'), event_types=('WorkbenchRate', ), perform_second_snapshot=False) assert snapshot['software'] == 'Workbench' assert snapshot['version'] == '11.0' assert snapshot['uuid'] == 'f5efd26e-8754-46bc-87bf-fbccc39d60d9' assert snapshot['elapsed'] == 4 assert snapshot['author']['id'] == user.user['id'] assert 'events' not in snapshot['device'] assert 'author' not in snapshot['device'] device, _ = user.get(res=Device, item=snapshot['device']['id']) assert snapshot['components'] == device['components'] assert tuple(c['type'] for c in snapshot['components']) == ('GraphicCard', 'RamModule') rate, _ = user.get(res=Event, item=snapshot['events'][0]['id']) assert rate['device']['id'] == snapshot['device']['id'] assert rate['components'] == snapshot['components'] assert rate['snapshot']['id'] == snapshot['id']
def test_erase(user: UserClient): """Tests a Snapshot with EraseSectors.""" s = file('erase-sectors.snapshot') snapshot = snapshot_and_check(user, s, ('EraseSectors', ), perform_second_snapshot=True) storage, *_ = snapshot['components'] assert storage[ 'type'] == 'SolidStateDrive', 'Components must be ordered by input order' storage, _ = user.get(res=SolidStateDrive, item=storage['id']) # Let's get storage events too # order: creation time descending _snapshot1, erasure1, _snapshot2, erasure2 = storage['events'] assert erasure1['type'] == erasure2['type'] == 'EraseSectors' assert _snapshot1['type'] == _snapshot2['type'] == 'Snapshot' assert snapshot == user.get(res=Event, item=_snapshot2['id'])[0] erasure, _ = user.get(res=EraseBasic, item=erasure1['id']) assert len(erasure['steps']) == 2 assert erasure['steps'][0]['startTime'] == '2018-06-01T08:15:00+00:00' assert erasure['steps'][0]['endTime'] == '2018-06-01T09:16:00+00:00' assert erasure['steps'][1]['startTime'] == '2018-06-01T08:16:00+00:00' assert erasure['steps'][1]['endTime'] == '2018-06-01T09:17:00+00:00' assert erasure['device']['id'] == storage['id'] for step in erasure['steps']: assert step['type'] == 'StepZero' assert step['error'] is False assert step['secureRandomSteps'] == 1 assert step['cleanWithZeros'] is True assert 'num' not in step
def test_deactivate_merge(app: Devicehub, user: UserClient): """ Check if is correct to do a manual merge """ snapshot1, _ = user.post(import_snap('real-custom.snapshot.11'), res=m.Snapshot) snapshot2, _ = user.post(import_snap('real-hp.snapshot.11'), res=m.Snapshot) pc1_id = snapshot1['device']['id'] pc2_id = snapshot2['device']['id'] with app.app_context(): pc1 = d.Device.query.filter_by(id=pc1_id).one() pc2 = d.Device.query.filter_by(id=pc2_id).one() n_actions1 = len(pc1.actions) n_actions2 = len(pc2.actions) action1 = pc1.actions[0] action2 = pc2.actions[0] assert not action2 in pc1.actions tag = Tag(id='foo-bar', owner_id=user.user['id']) pc2.tags.add(tag) db.session.add(pc2) db.session.commit() components1 = [com for com in pc1.components] components2 = [com for com in pc2.components] components1_excluded = [com for com in pc1.components if not com in components2] assert pc1.hid != pc2.hid assert not tag in pc1.tags uri = '/devices/%d/merge/%d' % (pc1_id, pc2_id) _, code = user.post({'id': 1}, uri=uri, status=404) assert code.status == '404 NOT FOUND'
def test_merge_two_device_with_differents_tags(app: Devicehub, user: UserClient): """ Check if is correct to do a manual merge of 2 diferents devices with diferents tags """ snapshot1, _ = user.post(import_snap('real-custom.snapshot.11'), res=m.Snapshot) snapshot2, _ = user.post(import_snap('real-hp.snapshot.11'), res=m.Snapshot) pc1_id = snapshot1['device']['id'] pc2_id = snapshot2['device']['id'] with app.app_context(): pc1 = d.Device.query.filter_by(id=pc1_id).one() pc2 = d.Device.query.filter_by(id=pc2_id).one() tag1 = Tag(id='fii-bor', owner_id=user.user['id']) tag2 = Tag(id='foo-bar', owner_id=user.user['id']) pc1.tags.add(tag1) pc2.tags.add(tag2) db.session.add(pc1) db.session.add(pc2) db.session.commit() uri = '/devices/%d/merge/%d' % (pc1_id, pc2_id) result, _ = user.post({'id': 1}, uri=uri, status=201) assert pc1.hid == pc2.hid assert tag1 in pc1.tags assert tag2 in pc1.tags
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)
def test_hid_with_2network_and_drop_no_mac_in_hid(app: Devicehub, user: UserClient): """Checks hid with 2 networks adapters and next drop the network is not used in hid""" snapshot = yaml2json('asus-eee-1000h.snapshot.11') network = [ c for c in snapshot['components'] if c['type'] == 'NetworkAdapter' ][0] network2 = copy.copy(network) snapshot['components'].append(network2) network['serialNumber'] = 'a0:24:8c:7f:cf:2d' snap, _ = user.post(json_encode(snapshot), res=m.Snapshot) pc, _ = user.get(res=d.Device, item=snap['device']['devicehubID']) assert pc[ 'hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abb' snapshot['components'] = [ c for c in snapshot['components'] if c != network ] user.post(json_encode(snapshot), res=m.Snapshot) 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 laptop['components'] if c['type'] == 'NetworkAdapter' ]) == 1
def test_post_get_lot(user: UserClient): """Tests submitting and retreiving a basic lot.""" l, _ = user.post({'name': 'Foo'}, res=Lot) assert l['name'] == 'Foo' l, _ = user.get(res=Lot, item=l['id']) assert l['name'] == 'Foo' assert not l['children']
def test_auth_view(user: UserClient, client: Client): """Tests authentication at endpoint / view.""" user.get(res='User', item=user.user['id'], status=200) client.get(res='User', item=user.user['id'], status=Unauthorized) client.get(res='User', item=user.user['id'], token='wrong token', status=Unauthorized)
def user(app: Devicehub) -> UserClient: """Gets a client with a logged-in dummy user.""" with app.app_context(): password = '******' user = create_user(password=password) client = UserClient(app, user.email, password, response_wrapper=app.response_class) client.login() return client
def test_get_multiple_lots(user: UserClient): """Tests submitting and retreiving multiple lots.""" l, _ = user.post({'name': 'Lot1', 'description': 'comments1,lot1,testcomment,'}, res=Lot) l, _ = user.post({'name': 'Lot2', 'description': 'comments2,lot2,testcomment,'}, res=Lot) l, _ = user.post({'name': 'Lot3', 'description': 'comments3,lot3,testcomment,'}, res=Lot) l, _ = user.get(res=Lot) assert len(l) == 3
def test_hid_without_mac(app: Devicehub, user: UserClient): """Checks hid without mac.""" snapshot = yaml2json('asus-eee-1000h.snapshot.11') snapshot['components'] = [ c for c in snapshot['components'] if c['type'] != 'NetworkAdapter' ] snap, _ = user.post(json_encode(snapshot), res=m.Snapshot) pc, _ = user.get(res=d.Device, item=snap['device']['devicehubID']) assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116'
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=s, status=201 if file.name not in SNAPSHOTS_NEED_ID else NeedsId)
def test_workbench_server_condensed(user: UserClient): """As :def:`.test_workbench_server_phases` but all the actions condensed in only one big ``Snapshot`` file, as described in the docs. """ 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'][5]['actions'].append(yaml2json('workbench-server-3.erase')) # Create tags for t in s['device']['tags']: user.post({'id': t['id']}, res=Tag) 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'] hdd_id = snapshot['components'][5]['id'] actions = snapshot['actions'] assert {(action['type'], action['device']) for action in actions} == {('BenchmarkProcessorSysbench', cpu_id), ('StressTest', pc_id), ('EraseSectors', ssd_id), ('EreusePrice', pc_id), ('BenchmarkRamSysbench', pc_id), ('BenchmarkProcessor', cpu_id), ('Install', ssd_id), ('EraseSectors', hdd_id), ('BenchmarkDataStorage', ssd_id), ('BenchmarkDataStorage', hdd_id), ('TestDataStorage', ssd_id), ('RateComputer', pc_id)} assert snapshot['closed'] assert snapshot['severity'] == 'Info' device, _ = user.get(res=Device, item=snapshot['device']['devicehubID']) assert device['dataStorageSize'] == 1100 assert device['chassis'] == 'Tower' assert device['hid'] == 'desktop-d1mr-d1ml-d1s-na1-s' assert device['graphicCardModel'] == device['components'][0][ 'model'] == 'gc1-1ml' assert device['networkSpeeds'] == [1000, 58] assert device['processorModel'] == device['components'][3][ 'model'] == 'p1-1ml' assert device[ 'ramSize'] == 2048, 'There are 3 RAM: 2 x 1024 and 1 None sizes' assert device['rate']['closed'] assert device['rate']['severity'] == 'Info' assert device['rate']['rating'] == 1 assert device['rate']['type'] == RateComputer.t # 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']]
def user(app: Devicehub) -> UserClient: """Gets a client with a logged-in dummy user.""" with app.app_context(): user = create_user() client = UserClient(application=app, response_wrapper=app.response_class, email=user.email, password='******') client.user, _ = client.login(client.email, client.password) return client