Exemplo n.º 1
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']
Exemplo n.º 2
0
def test_snapshot_tag_inner_tag_mismatch_between_tags_and_hid(user: UserClient, tag_id: str):
    """Ensures one device cannot 'steal' the tag from another one."""
    pc1 = yaml2json('basic.snapshot')
    pc1['device']['tags'] = [{'type': 'Tag', 'id': tag_id}]
    user.post(json_encode(pc1), res=Snapshot)
    pc2 = yaml2json('1-device-with-components.snapshot')
    user.post(json_encode(pc2), res=Snapshot)  # PC2 uploads well
    pc2['device']['tags'] = [{'type': 'Tag', 'id': tag_id}]  # Set tag from pc1 to pc2
    user.post(json_encode(pc2), res=Snapshot, status=MismatchBetweenTagsAndHid)
Exemplo n.º 3
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']]
Exemplo n.º 4
0
def test_sync_execute_register_desktop_existing_no_tag():
    """Syncs an existing d.Desktop with HID and without a tag."""
    pc = d.Desktop(**yaml2json('pc-components.db')['device'])
    db.session.add(pc)
    db.session.commit()

    pc = d.Desktop(**yaml2json('pc-components.db')
                   ['device'])  # Create a new transient non-db object
    # 1: device exists on DB
    db_pc = Sync().execute_register(pc)
    pc.amount = 0
    pc.owner_id = db_pc.owner_id
    pc.transfer_state = TransferState.Initial
    assert pc.physical_properties == db_pc.physical_properties
Exemplo n.º 5
0
def test_simple_metrics(user: UserClient):
    """ Checks one standard query of metrics """
    # Insert computer
    lenovo = yaml2json('desktop-9644w8n-lenovo-0169622.snapshot')
    acer = yaml2json('acer.happy.battery.snapshot')
    user.post(json_encode(lenovo), res=ma.Snapshot)
    snapshot, _ = user.post(json_encode(acer), res=ma.Snapshot)
    device_id = snapshot['device']['id']
    post_request = {
        "transaction": "ccc",
        "name": "John",
        "endUsers": 1,
        "finalUserCode": "abcdefjhi",
        "devices": [device_id],
        "description": "aaa",
        "startTime": "2020-11-01T02:00:00+00:00",
        "endTime": "2020-12-01T02:00:00+00:00"
    }

    # Create Allocate
    user.post(res=ma.Allocate, data=post_request)
    acer['uuid'] = "490fb8c0-81a1-42e9-95e0-5e7db7038ec3"
    hdd = [c for c in acer['components'] if c['type'] == 'HardDrive'][0]
    hdd_action = [a for a in hdd['actions']
                  if a['type'] == 'TestDataStorage'][0]
    hdd_action['powerCycleCount'] += 1000
    acer.pop('elapsed')
    acer['licence_version'] = '1.0.0'
    user.post(acer, res=ma.Live)

    # Create a live
    acer['uuid'] = "490fb8c0-81a1-42e9-95e0-5e7db7038ec4"
    hdd = [c for c in acer['components'] if c['type'] == 'HardDrive'][0]
    hdd_action = [a for a in hdd['actions']
                  if a['type'] == 'TestDataStorage'][0]
    hdd_action['powerCycleCount'] += 1000
    user.post(acer, res=ma.Live)

    # Create an other live
    acer['uuid'] = "490fb8c0-81a1-42e9-95e0-5e7db7038ec5"
    hdd = [c for c in acer['components'] if c['type'] == 'HardDrive'][0]
    hdd_action = [a for a in hdd['actions']
                  if a['type'] == 'TestDataStorage'][0]
    hdd_action['powerCycleCount'] += 1000
    user.post(acer, res=ma.Live)

    # Check metrics
    metrics = {'allocateds': 1, 'live': 1}
    res, _ = user.get("/metrics/")
    assert res == metrics
Exemplo n.º 6
0
def test_snapshot_update_timefield_updated(user: UserClient):
    """
    Tests for check if one computer have the time mark updated when one component of it is updated
    """
    computer1 = yaml2json('1-device-with-components.snapshot')
    snapshot = snapshot_and_check(user,
                                  computer1,
                                  action_types=(BenchmarkProcessor.t,
                                                RateComputer.t),
                                  perform_second_snapshot=False)
    computer2 = yaml2json('2-second-device-with-components-of-first.snapshot')
    snapshot_and_check(user, computer2, action_types=('Remove', 'RateComputer'),
                       perform_second_snapshot=False)
    pc1_devicehub_id = snapshot['device']['devicehubID']
    pc1, _ = user.get(res=m.Device, item=pc1_devicehub_id)
    assert pc1['updated'] != snapshot['device']['updated']
Exemplo n.º 7
0
def test_add_remove():
    # Original state:
    # pc has c1 and c2
    # pc2 has c3
    # c4 is not with any pc
    user = User.query.filter().first()
    values = yaml2json('pc-components.db')
    pc = values['device']
    c1, c2 = (d.Component(**c) for c in values['components'])
    pc = d.Desktop(**pc, components=OrderedSet([c1, c2]))
    db.session.add(pc)
    c3 = d.Component(serial_number='nc1', owner_id=user.id)
    pc2 = d.Desktop(serial_number='s2',
                    components=OrderedSet([c3]),
                    chassis=ComputerChassis.Microtower)
    c4 = d.Component(serial_number='c4s', owner_id=user.id)
    db.session.add(pc2)
    db.session.add(c4)
    db.session.commit()

    # Test:
    # pc has only c3
    actions = Sync.add_remove(device=pc, components={c3, c4})
    db.session.add_all(actions)
    db.session.commit()  # We enforce the appliance of order_by
    assert len(actions) == 1
    assert isinstance(actions[0], Remove)
    assert actions[0].device == pc2
    assert actions[0].components == OrderedSet([c3])
Exemplo n.º 8
0
def test_component_similar_one():
    user = User.query.filter().first()
    snapshot = yaml2json('pc-components.db')
    pc = snapshot['device']
    snapshot['components'][0]['serial_number'] = snapshot['components'][1][
        'serial_number'] = None
    pc = d.Desktop(**pc,
                   components=OrderedSet(
                       d.Component(**c) for c in snapshot['components']))
    component1, component2 = pc.components  # type: d.Component
    db.session.add(pc)
    db.session.flush()
    # Let's create a new component named 'A' similar to 1
    componentA = d.Component(model=component1.model,
                             manufacturer=component1.manufacturer,
                             owner_id=user.id)
    similar_to_a = componentA.similar_one(pc, set())
    assert similar_to_a == component1
    # d.Component B does not have the same model
    componentB = d.Component(model='nope',
                             manufacturer=component1.manufacturer)
    with pytest.raises(ResourceNotFound):
        assert componentB.similar_one(pc, set())
    # If we blacklist component A we won't get anything
    with pytest.raises(ResourceNotFound):
        assert componentA.similar_one(pc, blacklist={componentA.id})
Exemplo n.º 9
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
Exemplo n.º 10
0
def test_snapshot_post(user: UserClient):
    """Tests the post snapshot endpoint (validation, etc), data correctness,
    and relationship correctness.
    """
    snapshot = snapshot_and_check(user, yaml2json('basic.snapshot'),
                                  action_types=(
                                      BenchmarkProcessor.t,
                                      VisualTest.t,
                                      RateComputer.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 'actions' not in snapshot['device']
    assert 'author' not in snapshot['device']
    device, _ = user.get(res=m.Device, item=snapshot['device']['devicehubID'])
    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['actions'] if e['type'] == RateComputer.t)
    rate, _ = user.get(res=Action, 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']
Exemplo n.º 11
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
Exemplo n.º 12
0
def test_snapshot_different_properties_same_tags(user: UserClient, tag_id: str):
    """Tests a snapshot performed to device 1 with tag A and then to
    device 2 with tag B. Both don't have HID but are different type.
    Devicehub must fail the Snapshot.
    """
    # 1. Upload PC1 without hid but with tag
    pc1 = yaml2json('basic.snapshot')
    pc1['device']['tags'] = [{'type': 'Tag', 'id': tag_id}]
    del pc1['device']['serialNumber']
    user.post(json_encode(pc1), res=Snapshot)
    # 2. Upload PC2 without hid, a different characteristic than PC1, but with same tag
    pc2 = yaml2json('basic.snapshot')
    pc2['uuid'] = uuid4()
    pc2['device']['tags'] = pc1['device']['tags']
    # pc2 model is unknown but pc1 model is set = different property
    del pc2['device']['model']
    user.post(json_encode(pc2), res=Snapshot, status=MismatchBetweenProperties)
Exemplo n.º 13
0
def test_sync_execute_register_tag_linked_same_device():
    """If the tag is linked to the device, regardless if it has HID,
    the system should match the device through the tag.
    (If it has HID it validates both HID and tag point at the same
    device, this his checked in ).
    """
    orig_pc = d.Desktop(**yaml2json('pc-components.db')['device'])
    db.session.add(Tag(id='foo', device=orig_pc))
    db.session.commit()

    pc = d.Desktop(**yaml2json('pc-components.db')
                   ['device'])  # Create a new transient non-db object
    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
    for tag in db_pc.tags:
        assert tag.id in ['foo', db_pc.devicehub_id]
Exemplo n.º 14
0
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'
Exemplo n.º 15
0
def test_snapshot_tag_inner_tag(user: UserClient, tag_id: str, app: Devicehub):
    """Tests a posting Snapshot with a local tag."""
    b = yaml2json('basic.snapshot')
    b['device']['tags'] = [{'type': 'Tag', 'id': tag_id}]

    snapshot_and_check(user, b,
                       action_types=(RateComputer.t, BenchmarkProcessor.t, VisualTest.t))
    with app.app_context():
        tag = Tag.query.all()[0]  # type: Tag
        assert tag.device_id == 3, 'Tag should be linked to the first device'
Exemplo n.º 16
0
def test_sync_execute_register_tag_linked_other_device_mismatch_between_tags():
    """Checks that sync raises an error if finds that at least two passed-in
    tags are not linked to the same device.
    """
    pc1 = d.Desktop(**yaml2json('pc-components.db')['device'])
    db.session.add(Tag(id='foo-1', device=pc1))
    pc2 = d.Desktop(**yaml2json('pc-components.db')['device'])
    pc2.serial_number = 'pc2-serial'
    pc2.hid = Naming.hid(pc2.type, pc2.manufacturer, pc2.model,
                         pc2.serial_number)
    db.session.add(Tag(id='foo-2', device=pc2))
    db.session.commit()

    pc1 = d.Desktop(**yaml2json('pc-components.db')
                    ['device'])  # Create a new transient non-db object
    pc1.tags.add(Tag(id='foo-1'))
    pc1.tags.add(Tag(id='foo-2'))
    with raises(MismatchBetweenTags):
        Sync().execute_register(pc1)
Exemplo n.º 17
0
def test_sync_execute_register_mismatch_between_tags_and_hid():
    """Checks that sync raises an error if it finds that the HID does
    not point at the same device as the tag does.

    In this case we set HID -> pc1 but tag -> pc2
    """
    pc1 = d.Desktop(**yaml2json('pc-components.db')['device'])
    db.session.add(Tag(id='foo-1', device=pc1))
    pc2 = d.Desktop(**yaml2json('pc-components.db')['device'])
    pc2.serial_number = 'pc2-serial'
    pc2.hid = Naming.hid(pc2.type, pc2.manufacturer, pc2.model,
                         pc2.serial_number)
    db.session.add(Tag(id='foo-2', device=pc2))
    db.session.commit()

    pc1 = d.Desktop(**yaml2json('pc-components.db')
                    ['device'])  # Create a new transient non-db object
    pc1.tags.add(Tag(id='foo-2'))
    with raises(MismatchBetweenTagsAndHid):
        Sync().execute_register(pc1)
Exemplo n.º 18
0
def test_sync_execute_register_desktop_no_hid_no_tag(user: UserClient):
    """Syncs a d.Desktop without HID and no tag.
    This should not fail as we don't have a way to identify it.
    """
    device = yaml2json('pc-components.db')['device']
    device['owner_id'] = user.user['id']
    pc = d.Desktop(**device)
    # 1: device has no HID
    pc.hid = pc.model = None
    returned_pc = Sync().execute_register(pc)
    assert returned_pc == pc
Exemplo n.º 19
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'])
Exemplo n.º 20
0
def test_sync_execute_register_tag_does_not_exist():
    """Ensures not being able to register if the tag does not exist,
    even if the device has HID or it existed before.

    Tags have to be created before trying to link them through a Snapshot.
    """
    user = User.query.filter().first()
    pc = d.Desktop(**yaml2json('pc-components.db')['device'],
                   tags=OrderedSet([Tag('foo')]))
    pc.owner_id = user.id
    with raises(ResourceNotFound):
        Sync().execute_register(pc)
Exemplo n.º 21
0
def test_visual_metrics_for_old_owners(user: UserClient, user2: UserClient):
    """ Checks if one old owner can see the metrics in a trade enviroment."""
    # Insert computer
    lenovo = yaml2json('desktop-9644w8n-lenovo-0169622.snapshot')
    snap1, _ = user.post(json_encode(lenovo), res=ma.Snapshot)
    lot, _ = user.post({'name': 'MyLot'}, res=Lot)
    device_id = snap1['device']['id']
    devices = [('id', device_id)]
    lot, _ = user.post({},
                       res=Lot,
                       item='{}/devices'.format(lot['id']),
                       query=devices)
    request_post = {
        'type': 'Trade',
        'devices': [device_id],
        'userFromEmail': user.email,
        'userToEmail': user2.email,
        'price': 10,
        'date': "2020-12-01T02:00:00+00:00",
        'lot': lot['id'],
        'confirms': True,
    }
    trade, _ = user.post(res=ma.Action, data=request_post)

    request_confirm = {
        'type': 'Confirm',
        'action': trade['id'],
        'devices': [device_id]
    }
    user2.post(res=ma.Action, data=request_confirm)

    action = {'type': ma.Refurbish.t, 'devices': [device_id]}
    action_use, _ = user.post(action, res=ma.Action)
    csv_supplier, _ = user.get(res=documents.DocumentDef.t,
                               item='actions/',
                               accept='text/csv',
                               query=[('filter', {
                                   'type': ['Computer'],
                                   'ids': [device_id]
                               })])
    csv_receiver, _ = user2.get(res=documents.DocumentDef.t,
                                item='actions/',
                                accept='text/csv',
                                query=[('filter', {
                                    'type': ['Computer'],
                                    'ids': [device_id]
                                })])
    body = ';;0;0;Trade;0;0\n'

    assert body in csv_receiver
    assert body in csv_supplier
    assert csv_receiver == csv_supplier
Exemplo n.º 22
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 = yaml2json('basic.snapshot')
    s['device'] = {
        'type': 'Processor',
        'serialNumber': 'foo',
        'manufacturer': 'bar',
        'model': 'baz'
    }
    user.post(json_encode(s), res=Snapshot, status=ValidationError)
Exemplo n.º 23
0
def test_bug_trade_confirmed(user: UserClient, user2: UserClient):
    """When the receiber do a Trade, then the confirmation is wrong."""
    lenovo = yaml2json('desktop-9644w8n-lenovo-0169622.snapshot')
    snap1, _ = user.post(json_encode(lenovo), res=ma.Snapshot)
    lot, _ = user.post({'name': 'MyLot'}, res=Lot)
    device_id = snap1['device']['id']
    devices = [('id', device_id)]
    lot, _ = user.post({},
                       res=Lot,
                       item='{}/devices'.format(lot['id']),
                       query=devices)
    request_post = {
        'type': 'Trade',
        'devices': [device_id],
        'userFromEmail': user2.email,
        'userToEmail': user.email,
        'price': 10,
        'date': "2020-12-01T02:00:00+00:00",
        'lot': lot['id'],
        'confirms': True,
    }
    trade, _ = user.post(res=ma.Action, data=request_post)

    csv_not_confirmed, _ = user.get(res=documents.DocumentDef.t,
                                    item='actions/',
                                    accept='text/csv',
                                    query=[('filter', {
                                        'type': ['Computer'],
                                        'ids': [device_id]
                                    })])
    request_confirm = {
        'type': 'Confirm',
        'action': trade['id'],
        'devices': [device_id]
    }
    user2.post(res=ma.Action, data=request_confirm)
    csv_confirmed, _ = user2.get(res=documents.DocumentDef.t,
                                 item='actions/',
                                 accept='text/csv',
                                 query=[('filter', {
                                     'type': ['Computer'],
                                     'ids': [device_id]
                                 })])

    body_not_confirmed = "Trade;[email protected];[email protected];Receiver;NeedConfirmation;"
    body_confirmed = "Trade;[email protected];[email protected];Receiver;TradeConfirmed;"

    assert body_not_confirmed in csv_not_confirmed
    assert body_confirmed in csv_confirmed
Exemplo n.º 24
0
def test_snapshot_not_failed_null_chassis(app: Devicehub, user: UserClient):
    """ This test check if the file snapshot is create when some snapshot is wrong """
    tmp_snapshots = app.config['TMP_SNAPSHOTS']
    path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
    snapshot_error = yaml2json('desktop-9644w8n-lenovo-0169622.snapshot')
    snapshot_error['device']['chassis'] = None
    uuid = snapshot_error['uuid']

    snapshot, res = user.post(res=Snapshot, data=json_encode(snapshot_error))

    shutil.rmtree(tmp_snapshots)

    assert snapshot['software'] == snapshot_error['software']
    assert snapshot['version'] == snapshot_error['version']
    assert snapshot['uuid'] == uuid
Exemplo n.º 25
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])
Exemplo n.º 26
0
def test_sync_run_components_empty():
    """Syncs a device that has an empty components list. The system should
    remove all the components from the device.
    """
    s = yaml2json('pc-components.db')
    pc = d.Desktop(**s['device'],
                   components=OrderedSet(
                       d.Component(**c) for c in s['components']))
    db.session.add(pc)
    db.session.commit()

    # Create a new transient non-db synced object
    pc = d.Desktop(**s['device'])
    db_pc, _ = Sync().run(pc, components=OrderedSet())
    assert not db_pc.components
    assert not pc.components
Exemplo n.º 27
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
Exemplo n.º 28
0
def test_snapshot_not_failed_end_time_bug(app: Devicehub, user: UserClient):
    """ This test check if the end_time != 0001-01-01 00:00:00+00:00
    and then we get a /devices, this create a crash
    """
    snapshot_file = yaml2json('asus-end_time_bug88.snapshot')
    snapshot_file['endTime'] = '2001-01-01 00:00:00+00:00'
    snapshot, _ = user.post(res=Snapshot, data=json_encode(snapshot_file))
    device, _ = user.get(res=m.Device, item=snapshot['device']['devicehubID'])
    end_times = [x['endTime'] for x in device['actions']]

    assert not '1970-01-02T00:00:00+00:00' in end_times
    assert not '0001-01-01T00:00:00+00:00' in end_times
    assert '2001-01-01T00:00:00+00:00' in end_times

    tmp_snapshots = app.config['TMP_SNAPSHOTS']
    shutil.rmtree(tmp_snapshots)
Exemplo n.º 29
0
def test_sync_run_components_none():
    """Syncs a device that has a None components. The system should
    keep all the components from the device.
    """
    s = yaml2json('pc-components.db')
    pc = d.Desktop(**s['device'],
                   components=OrderedSet(
                       d.Component(**c) for c in s['components']))
    db.session.add(pc)
    db.session.commit()

    # Create a new transient non-db synced object
    transient_pc = d.Desktop(**s['device'])
    db_pc, _ = Sync().run(transient_pc, components=None)
    assert db_pc.components
    assert db_pc.components == pc.components
Exemplo n.º 30
0
def test_sync_execute_register_desktop_tag_not_linked():
    """Syncs a new d.Desktop with HID and a non-linked tag.

    It is OK if the tag was not linked, it will be linked in this process.
    """
    tag = Tag(id='foo')
    db.session.add(tag)
    db.session.commit()

    # Create a new transient non-db object
    pc = d.Desktop(**yaml2json('pc-components.db')['device'],
                   tags=OrderedSet([Tag(id='foo')]))
    returned_pc = Sync().execute_register(pc)
    assert returned_pc == pc
    assert tag.device == pc, 'Tag has to be linked'
    assert d.Desktop.query.one() == pc, 'd.Desktop had to be set to db'