Beispiel #1
0
def test_lot_device_relationship():
    device = Desktop(serial_number='foo',
                     model='bar',
                     manufacturer='foobar',
                     chassis=ComputerChassis.Lunchbox)
    device.components.add(
        GraphicCard(serial_number='foo', model='bar1', manufacturer='baz'))
    child = Lot('child')
    child.devices.add(device)
    db.session.add(child)
    db.session.flush()

    lot_device = LotDevice.query.one()  # type: LotDevice
    assert lot_device.device_id == device.id
    assert lot_device.lot_id == child.id
    assert lot_device.created
    assert lot_device.author_id == g.user.id
    assert device.lots == {child}
    assert device in child
    assert device in child.all_devices

    graphic = GraphicCard(serial_number='foo', model='bar')
    device.components.add(graphic)
    db.session.flush()
    assert graphic in child

    parent = Lot('parent')
    db.session.add(parent)
    db.session.flush()
    parent.add_children(child)
    assert child in parent
Beispiel #2
0
def test_get_device(app: Devicehub, user: UserClient):
    """Checks GETting a Desktop with its components."""
    with app.app_context():
        pc = Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s')
        pc.components = OrderedSet([
            NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s'),
            GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500)
        ])
        db.session.add(pc)
        db.session.add(Test(device=pc,
                            elapsed=timedelta(seconds=4),
                            error=False,
                            author=User(email='*****@*****.**')))
        db.session.commit()
    pc, _ = user.get(res=Device, item=1)
    assert len(pc['events']) == 1
    assert pc['events'][0]['type'] == 'Test'
    assert pc['events'][0]['device'] == 1
    assert pc['events'][0]['elapsed'] == 4
    assert not pc['events'][0]['error']
    assert UUID(pc['events'][0]['author'])
    assert 'events_components' not in pc, 'events_components are internal use only'
    assert 'events_one' not in pc, 'they are internal use only'
    assert 'author' not in pc
    assert tuple(c['id'] for c in pc['components']) == (2, 3)
    assert pc['hid'] == 'p1ma-p1s-p1mo'
    assert pc['model'] == 'p1mo'
    assert pc['manufacturer'] == 'p1ma'
    assert pc['serialNumber'] == 'p1s'
    assert pc['type'] == 'Desktop'
Beispiel #3
0
def test_validate_device_data_storage():
    """Checks the validation for data-storage-only events works."""
    # We can't set a GraphicCard
    with pytest.raises(
            TypeError,
            message='EraseBasic.device must be a DataStorage '
            'but you passed <GraphicCard None model=\'foo-bar\' S/N=\'foo\'>'):
        models.EraseBasic(device=GraphicCard(serial_number='foo',
                                             manufacturer='bar',
                                             model='foo-bar'),
                          clean_with_zeros=True,
                          **conftest.T)
Beispiel #4
0
def test_validate_device_data_storage():
    """Checks the validation for data-storage-only events works."""
    # We can't set a GraphicCard
    with pytest.raises(
            TypeError,
            message='EraseBasic.device must be a DataStorage '
            'but you passed <GraphicCard None model=\'foo-bar\' S/N=\'foo\'>'):
        EraseBasic(device=GraphicCard(serial_number='foo',
                                      manufacturer='bar',
                                      model='foo-bar'),
                   clean_with_zeros=True,
                   start_time=datetime.now(),
                   end_time=datetime.now(),
                   secure_random_steps=25,
                   error=False)
Beispiel #5
0
def test_get_devices(app: Devicehub, user: UserClient):
    """Checks GETting multiple devices."""
    with app.app_context():
        pc = Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s')
        pc.components = OrderedSet([
            NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s'),
            GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500)
        ])
        pc1 = Microtower(model='p2mo', manufacturer='p2ma', serial_number='p2s')
        pc2 = Laptop(model='p3mo', manufacturer='p3ma', serial_number='p3s')
        db.session.add_all((pc, pc1, pc2))
        db.session.commit()
    devices, _ = user.get(res=Device)
    assert tuple(d['id'] for d in devices) == (1, 2, 3, 4, 5)
    assert tuple(d['type'] for d in devices) == ('Desktop', 'Microtower',
                                                 'Laptop', 'NetworkAdapter', 'GraphicCard')
def device_query_dummy(app: Devicehub):
    """
    3 computers, where:

    1. s1 Desktop with a Processor
    2. s2 Desktop with an SSD
    3. s3 Laptop
    4. s4 Server with another SSD

    :param app:
    :return:
    """
    with app.app_context():
        devices = (  # The order matters ;-)
            Desktop(serial_number='1',
                    model='ml1',
                    manufacturer='mr1',
                    chassis=ComputerChassis.Tower),
            Desktop(serial_number='2',
                    model='ml2',
                    manufacturer='mr2',
                    chassis=ComputerChassis.Microtower),
            Laptop(serial_number='3',
                   model='ml3',
                   manufacturer='mr3',
                   chassis=ComputerChassis.Detachable),
            Server(serial_number='4',
                   model='ml4',
                   manufacturer='mr4',
                   chassis=ComputerChassis.Tower),
        )
        devices[0].components.add(
            GraphicCard(serial_number='1-gc',
                        model='s1ml',
                        manufacturer='s1mr'))
        devices[1].components.add(
            SolidStateDrive(serial_number='2-ssd',
                            model='s2ml',
                            manufacturer='s2mr'))
        devices[-1].components.add(
            SolidStateDrive(serial_number='4-ssd',
                            model='s4ml',
                            manufacturer='s4mr'))
        db.session.add_all(devices)
        db.session.commit()
Beispiel #7
0
def test_device_model():
    """
    Tests that the correctness of the device model and its relationships.
    """
    pc = Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s')
    net = NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s')
    graphic = GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500)
    pc.components.add(net)
    pc.components.add(graphic)
    db.session.add(pc)
    db.session.commit()
    pc = Desktop.query.one()
    assert pc.serial_number == 'p1s'
    assert pc.components == OrderedSet([net, graphic])
    network_adapter = NetworkAdapter.query.one()
    assert network_adapter.parent == pc

    # Removing a component from pc doesn't delete the component
    pc.components.remove(net)
    db.session.commit()
    pc = Device.query.first()  # this is the same as querying for Desktop directly
    assert pc.components == {graphic}
    network_adapter = NetworkAdapter.query.one()
    assert network_adapter not in pc.components
    assert network_adapter.parent is None

    # Deleting the pc deletes everything
    gcard = GraphicCard.query.one()
    db.session.delete(pc)
    db.session.flush()
    assert pc.id == 1
    assert Desktop.query.first() is None
    db.session.commit()
    assert Desktop.query.first() is None
    assert network_adapter.id == 2
    assert 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 GraphicCard.query.first() is None, 'We should have deleted it –it was inside the pc'