Пример #1
0
def inventory_query_dummy(app: Devicehub):
    with app.app_context():
        db.session.add_all((  # The order matters ;-)
            Desktop(serial_number='s1', model='ml1', manufacturer='mr1'),
            Laptop(serial_number='s3', model='ml3', manufacturer='mr3'),
            Microtower(serial_number='s2', model='ml2', manufacturer='mr2'),
            SolidStateDrive(serial_number='s4',
                            model='ml4',
                            manufacturer='mr4')))
        db.session.commit()
Пример #2
0
def test_workbench_rate():
    rate = WorkbenchRate(processor=0.1,
                         ram=1.0,
                         bios=Bios.A,
                         labelling=False,
                         graphic_card=0.1,
                         data_storage=4.1,
                         algorithm_software=RatingSoftware.Ereuse,
                         algorithm_version=StrictVersion('1.0'),
                         device=Microtower(serial_number='24'))
    db.session.add(rate)
    db.session.commit()
Пример #3
0
def test_photobox_rate():
    pc = Microtower(serial_number='24')
    image = Image(name='foo',
                  content=b'123',
                  file_format=ImageMimeTypes.jpg,
                  orientation=Orientation.Horizontal,
                  image_list=ImageList(device=pc))
    rate = PhotoboxRate(image=image,
                        algorithm_software=RatingSoftware.Ereuse,
                        algorithm_version=StrictVersion('1.0'),
                        device=pc)
    db.session.add(rate)
    db.session.commit()
Пример #4
0
def test_update_parent():
    computer = Microtower(serial_number='sn1', model='ml1', manufacturer='mr1')
    hdd = HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar')
    computer.components.add(hdd)

    # Add
    benchmark = BenchmarkDataStorage()
    benchmark.device = hdd
    assert benchmark.parent == computer
    assert not benchmark.components

    # Remove
    benchmark.device = None
    assert not benchmark.parent
Пример #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')
Пример #6
0
def test_snapshot_model():
    """
    Tests creating a Snapshot with its relationships ensuring correct
    DB mapping.
    """
    device = Microtower(serial_number='a1')
    # noinspection PyArgumentList
    snapshot = Snapshot(uuid=uuid4(),
                        date=datetime.now(),
                        version='1.0',
                        software=SnapshotSoftware.DesktopApp,
                        elapsed=timedelta(seconds=25))
    snapshot.device = device
    snapshot.request = SnapshotRequest(request={'foo': 'bar'})
    snapshot.events.add(
        WorkbenchRate(processor=0.1,
                      ram=1.0,
                      bios=Bios.A,
                      labelling=False,
                      graphic_card=0.1,
                      data_storage=4.1,
                      algorithm_software=RatingSoftware.Ereuse,
                      algorithm_version=StrictVersion('1.0'),
                      device=device))
    db.session.add(snapshot)
    db.session.commit()
    device = Microtower.query.one()  # type: Microtower
    e1, e2 = device.events
    assert isinstance(
        e1, Snapshot), 'Creation order must be preserved: 1. snapshot, 2. WR'
    assert isinstance(e2, WorkbenchRate)
    db.session.delete(device)
    db.session.commit()
    assert Snapshot.query.one_or_none() is None
    assert SnapshotRequest.query.one_or_none() is None
    assert User.query.one() is not None
    assert Microtower.query.one_or_none() is None
    assert Device.query.one_or_none() is None
Пример #7
0
def test_update_components_event_multiple():
    computer = Microtower(serial_number='sn1', model='ml1', manufacturer='mr1')
    hdd = HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar')
    computer.components.add(hdd)

    ready = Ready()
    assert not ready.devices
    assert not ready.components

    # Add
    computer.events_multiple.add(ready)
    assert ready.devices == OrderedSet([computer])
    assert next(iter(ready.components)) == hdd

    # Remove
    computer.events_multiple.remove(ready)
    assert not ready.devices
    assert not ready.components

    # init / replace collection
    ready.devices = OrderedSet([computer])
    assert ready.devices
    assert ready.components
Пример #8
0
def test_update_components_event_one():
    computer = Microtower(serial_number='sn1', model='ml1', manufacturer='mr1')
    hdd = HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar')
    computer.components.add(hdd)

    # Add event
    test = StressTest(elapsed=timedelta(seconds=1))
    computer.events_one.add(test)
    assert test.device == computer
    assert next(iter(
        test.components)) == hdd, 'Event has to have new components'

    # Remove event
    computer.events_one.clear()
    assert not test.device
    assert not test.components, 'Event has to loose the components'

    # If we add a component to a device AFTER assigning the event
    # to the device, the event doesn't get the new component
    computer.events_one.add(test)
    ram = RamModule()
    computer.components.add(ram)
    assert len(test.components) == 1