Example #1
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)
Example #2
0
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)
Example #3
0
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
Example #4
0
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'])
Example #5
0
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
Example #6
0
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'
Example #7
0
def test_lot_post_add_children_view_ui_tree_normal(user: UserClient):
    """Tests adding children lots to a lot through the view and
    GETting the results."""
    parent, _ = user.post(({'name': 'Parent'}), res=Lot)
    child, _ = user.post(({'name': 'Child'}), res=Lot)
    parent, _ = user.post({},
                          res=Lot,
                          item='{}/children'.format(parent['id']),
                          query=[('id', child['id'])])
    assert parent['children'][0]['id'] == child['id']
    child, _ = user.get(res=Lot, item=child['id'])
    assert child['parents'][0]['id'] == parent['id']

    # Format UiTree
    r = user.get(res=Lot, query=[('format', 'UiTree')])[0]
    lots, nodes = r['items'], r['tree']
    assert 1 == len(nodes)
    assert nodes[0]['id'] == parent['id']
    assert len(nodes[0]['nodes']) == 1
    assert nodes[0]['nodes'][0]['id'] == child['id']
    assert 2 == len(lots)
    assert 'Parent' == lots[parent['id']]['name']
    assert 'Child' == lots[child['id']]['name']
    assert lots[child['id']]['parents'][0]['name'] == 'Parent'

    # Normal list format
    lots = user.get(res=Lot)[0]['items']
    assert 2 == len(lots)
    assert lots[0]['name'] == 'Parent'
    assert lots[1]['name'] == 'Child'

    # List format with a filter
    lots = user.get(res=Lot, query=[('search', 'pa')])[0]['items']
    assert 1 == len(lots)
    assert lots[0]['name'] == 'Parent'
Example #8
0
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
Example #9
0
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']
Example #10
0
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
Example #11
0
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'
Example #12
0
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']
Example #13
0
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
Example #14
0
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'
Example #15
0
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)
Example #16
0
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
Example #17
0
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)
Example #18
0
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 test_device_query(user: UserClient):
    """Checks result of inventory."""
    user.post(conftest.file('basic.snapshot'), res=Snapshot)
    i, _ = user.get(res=Device)
    assert i['url'] == '/devices/'
    assert i['items'][0]['url'] == '/devices/1'
    pc = next(d for d in i['items'] if d['type'] == 'Desktop')
    assert len(pc['events']) == 4
    assert len(pc['components']) == 3
    assert not pc['tags']
Example #20
0
def test_generic_event(event_model_state: Tuple[models.Event, states.Trading],
                       user: UserClient):
    """Tests POSTing all generic events."""
    event_model, state = event_model_state
    snapshot, _ = user.post(file('basic.snapshot'), res=models.Snapshot)
    event = {'type': event_model.t, 'devices': [snapshot['device']['id']]}
    event, _ = user.post(event, res=models.Event)
    assert event['devices'][0]['id'] == snapshot['device']['id']
    device, _ = user.get(res=Device, item=snapshot['device']['id'])
    assert device['events'][-1]['id'] == event['id']
    assert device['physical'] == state.name
Example #21
0
def test_device_query_search_synonyms_intel(user: UserClient):
    s = yaml2json('real-hp.snapshot.11')
    s['device']['model'] = 'foo'  # The model had the word 'HP' in it
    user.post(json_encode(s), res=Snapshot)
    i, _ = user.get(res=Device, query=[('search', 'hewlett packard')])
    assert 1 == len(i['items'])
    i, _ = user.get(res=Device, query=[('search', 'hewlett')])
    assert 1 == len(i['items'])
    i, _ = user.get(res=Device, query=[('search', 'hp')])
    assert 1 == len(i['items'])
    i, _ = user.get(res=Device, query=[('search', 'h.p')])
    assert 1 == len(i['items'])
Example #22
0
def test_get_devices_permissions(app: Devicehub, user: UserClient,
                                 user2: UserClient):
    """Checks GETting multiple devices."""

    user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
    url = '/devices/?filter={"type":["Computer"]}'

    devices, res = user.get(url, None)
    devices2, res2 = user2.get(url, None)
    assert res.status_code == 200
    assert res2.status_code == 200
    assert len(devices['items']) == 1
    assert len(devices2['items']) == 0
Example #23
0
def test_device_query_search(user: UserClient):
    # todo improve
    snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot)
    user.post(file('computer-monitor.snapshot'), res=Snapshot)
    user.post(file('real-eee-1001pxd.snapshot.11'), res=Snapshot)
    i, _ = user.get(res=Device, query=[('search', 'desktop')])
    assert i['items'][0]['id'] == snapshot['device']['id']
    i, _ = user.get(res=Device, query=[('search', 'intel')])
    assert len(i['items']) == 1
    i, _ = user.get(res=Device,
                    query=[('search', i['items'][0]['devicehubID'])])
    assert len(i['items']) == 1
    i, _ = user.get(res=Device, query=[('search', snapshot['device']['id'])])
    assert len(i['items']) == 1
Example #24
0
def test_device_search_regenerate_table(app: DeviceSearch, user: UserClient):
    user.post(file('basic.snapshot'), res=Snapshot)
    i, _ = user.get(res=Device, query=[('search', 'Desktop')])
    assert i['items'], 'Normal search works'
    with app.app_context():
        app.db.session.execute('TRUNCATE TABLE {}'.format(
            DeviceSearch.__table__.name))
        app.db.session.commit()
    i, _ = user.get(res=Device, query=[('search', 'Desktop')])
    assert not i['items'], 'Truncate deleted all items'
    runner = app.test_cli_runner()
    runner.invoke('inv', 'search')
    i, _ = user.get(res=Device, query=[('search', 'Desktop')])
    assert i['items'], 'Regenerated re-made the table'
Example #25
0
def test_snapshot_component_containing_components(user: UserClient):
    """There is no reason for components to have components and when
    this happens it is always an error.

    This test avoids this until an appropriate use-case is presented.
    """
    s = file('basic.snapshot')
    s['device'] = {
        'type': 'Processor',
        'serialNumber': 'foo',
        'manufacturer': 'bar',
        'model': 'baz'
    }
    user.post(s, res=Snapshot, status=ValidationError)
Example #26
0
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'].append(file('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=s)
    events = snapshot['events']
    assert {(event['type'], event['device'])
            for event in events} == {('AggregateRate', 1),
                                     ('WorkbenchRate', 1),
                                     ('BenchmarkProcessorSysbench', 5),
                                     ('StressTest', 1), ('EraseSectors', 6),
                                     ('BenchmarkRamSysbench', 1),
                                     ('BenchmarkProcessor', 5), ('Install', 6),
                                     ('EraseSectors', 7),
                                     ('BenchmarkDataStorage', 6),
                                     ('BenchmarkDataStorage', 7),
                                     ('TestDataStorage', 6)}
    assert snapshot['closed']
    assert snapshot['severity'] == 'Info'
    device, _ = user.get(res=Device, item=snapshot['device']['id'])
    assert device['dataStorageSize'] == 1100
    assert device['chassis'] == 'Tower'
    assert device['hid'] == 'desktop-d1mr-d1ml-d1s'
    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'] == 0
    assert device['rate']['workbench']
    assert device['rate']['appearanceRange'] == 'A'
    assert device['rate']['functionalityRange'] == 'B'
    assert device['tags'][0]['id'] == 'tag1'
Example #27
0
def test_device_search_all_devices_token_if_empty(app: Devicehub,
                                                  user: UserClient):
    """Ensures DeviceSearch can regenerate itself when the table is empty."""
    user.post(file('basic.snapshot'), res=Snapshot)
    with app.app_context():
        app.db.session.execute('TRUNCATE TABLE {}'.format(
            DeviceSearch.__table__.name))
        app.db.session.commit()
    i, _ = user.get(res=Device, query=[('search', 'Desktop')])
    assert not len(i['items'])
    with app.app_context():
        DeviceSearch.set_all_devices_tokens_if_empty(app.db.session)
        app.db.session.commit()
    i, _ = user.get(res=Device, query=[('search', 'Desktop')])
    assert i['items']
Example #28
0
def test_tag_post_etag(user: UserClient):
    """
    Ensures users cannot create eReuse.org tags through POST;
    only terminal.
    """
    user.post(res=Tag,
              query=[('ids', 'FO-123456')],
              data={},
              status=CannotCreateETag)
    # Although similar, these are not eTags and should pass
    user.post(res=Tag,
              query=[('ids', 'FO-0123-45'), ('ids', 'FOO012345678910'),
                     ('ids', 'FO'), ('ids', 'FO-'), ('ids', 'FO-123'),
                     ('ids', 'FOO-123456')],
              data={})
Example #29
0
def test_hid_with_2network_and_drop_mac_in_hid(app: Devicehub,
                                               user: UserClient):
    """Checks hid with 2 networks adapters and next drop the network is used in hid"""
    # One tipical snapshot with 2 network cards
    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'

    # we drop the network card then is used for to build the hid
    snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abb'
    snapshot['components'] = [
        c for c in snapshot['components'] if c != 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) == 2
    hids = [h['hid'] for h in laptops]
    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]
    ]
    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]
    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])
Example #30
0
def test_hid_with_2networkadapters(app: Devicehub, user: UserClient):
    """Checks hid with 2 networks adapters"""
    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'
    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