Beispiel #1
0
 def get_pendrive(pen: usb.Device) -> dict:
     manufacturer = pen.manufacturer.strip() or str(pen.idVendor)
     model = pen.product.strip() or str(pen.idProduct)
     serial_number = pen.serial_number.strip()
     hid = Naming.hid(manufacturer, serial_number, model)
     return {
         '_id': hid,  # Make live easier to DeviceHubClient by using _id
         'hid': hid,
         '@type': 'USBFlashDrive',
         'serialNumber': serial_number,
         'model': model,
         'manufacturer': manufacturer,
         'vendorId': pen.idVendor,
         'productId': pen.idProduct
     }
Beispiel #2
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 = Computer(**file('pc-components.db')['device'])
    db.session.add(Tag(id='foo-1', device=pc1))
    pc2 = Computer(**file('pc-components.db')['device'])
    pc2.serial_number = 'pc2-serial'
    pc2.hid = Naming.hid(pc2.manufacturer, pc2.serial_number, pc2.model)
    db.session.add(Tag(id='foo-2', device=pc2))
    db.session.commit()

    pc1 = Computer(**file('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)
Beispiel #3
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 = Computer(**file('pc-components.db')['device'])
    db.session.add(Tag(id='foo-1', device=pc1))
    pc2 = Computer(**file('pc-components.db')['device'])
    pc2.serial_number = 'pc2-serial'
    pc2.hid = Naming.hid(pc2.manufacturer, pc2.serial_number, pc2.model)
    db.session.add(Tag(id='foo-2', device=pc2))
    db.session.commit()

    pc1 = Computer(**file('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)
Beispiel #4
0
 def resource(cls: Type['Schema']) -> str:
     """The resource name of this schema."""
     return Naming.resource(cls.t)
Beispiel #5
0
 def t(cls: Type['Schema']) -> str:
     """The type for this schema, auto-computed from its name."""
     name, *_ = cls.__name__.split('Schema')
     return Naming.new_type(name, cls.Meta.PREFIX)
Beispiel #6
0
 def resource(cls):
     return Naming.resource(cls.type)
Beispiel #7
0
 def __init__(self, **kw) -> None:
     super().__init__(**kw)
     with suppress(TypeError):
         self.hid = Naming.hid(self.type, self.manufacturer, self.model,
                               self.serial_number)