def test_show(self, get_serial_devices, get_usb):
        get_serial_devices.return_value = [
            _Device('/dev/ttyS0'),
            _Device('/dev/ttyS1')
        ]
        get_usb.return_value = [
            # Without manufacturer and product
            Settable(idProduct=1234, idVendor=9999),
            # Without manufacturer
            Settable(idProduct=0x1234,
                     idVendor=0x9876,
                     manufacturer=None,
                     product='Printer'),
            # Complete
            Settable(idProduct=0x1234,
                     idVendor=0x9876,
                     manufacturer='USB',
                     product='Printer')
        ]

        station = self.create_station()
        settings = DeviceSettings(store=self.store,
                                  type=DeviceSettings.SCALE_DEVICE)
        editor = DeviceSettingsEditor(self.store,
                                      model=settings,
                                      station=station)
        self.check_editor(editor, 'editor-devicesetting-show')
Esempio n. 2
0
 def test_get_description(self):
     device = DeviceSettings(store=self.store,
                             brand=u'Brand',
                             model=u'XX',
                             type=DeviceSettings.CHEQUE_PRINTER_DEVICE)
     str = device.get_description()
     self.assertEquals(str, u'Brand XX')
Esempio n. 3
0
    def test_get_interface(self, Scale, ChequePrinter, SerialPort):
        port = SerialPort()
        SerialPort.return_value = port
        device = DeviceSettings(store=self.store,
                                device_name=u'/dev/ttyS0',
                                type=DeviceSettings.CHEQUE_PRINTER_DEVICE)

        obj = object()
        ChequePrinter.return_value = obj
        self.assertIs(device.get_interface(), obj)
        ChequePrinter.assert_called_with(brand=device.brand,
                                         model=device.model,
                                         port=port)

        obj = object()
        device.type = DeviceSettings.SCALE_DEVICE
        Scale.return_value = obj
        self.assertIs(device.get_interface(), obj)
        ChequePrinter.assert_called_with(brand=device.brand,
                                         model=device.model,
                                         port=port)
        device.type = None
        with self.assertRaises(DatabaseInconsistency) as error:
            device.get_interface()
        expected = "The device type referred by this record" \
                   " (%r) is invalid, given None." % device
        self.assertEqual(str(error.exception), expected)
Esempio n. 4
0
 def create_model(self, store):
     return DeviceSettings(device_name=None,
                           station=api.get_current_station(store),
                           brand=None,
                           model=None,
                           type=None,
                           store=store)
Esempio n. 5
0
 def test_get_scale_settings(self):
     device = DeviceSettings(store=self.store,
                             station=None,
                             type=DeviceSettings.SCALE_DEVICE)
     self.assertIsNone(
         device.get_scale_settings(store=self.store,
                                   station=self.current_station))
Esempio n. 6
0
 def test_get_by_station_and_type(self):
     station = self.create_station()
     type = DeviceSettings.SCALE_DEVICE
     device = DeviceSettings(store=self.store, station=station, type=type)
     results = device.get_by_station_and_type(store=self.store,
                                              station=station,
                                              type=type)
     self.assertEqual(results, device)
Esempio n. 7
0
 def test_get_interface_virtual(self):
     device = DeviceSettings(store=self.store,
                             brand=u'virtual',
                             model=u'Simple',
                             device_name=u'/dev/null',
                             type=DeviceSettings.NON_FISCAL_PRINTER_DEVICE)
     interface = device.get_interface()
     self.assertIsInstance(interface._port, VirtualPort)
Esempio n. 8
0
    def test_properties(self):
        station = self.create_station()
        device = DeviceSettings(store=self.store, brand=u'Brand', model=u'XX',
                                type=DeviceSettings.CHEQUE_PRINTER_DEVICE,
                                station=station)

        self.assertEqual(device.description, u'Brand XX')
        self.assertEqual(device.station_name, u'station')
        self.assertEqual(device.device_type_name, u'Cheque Printer')
Esempio n. 9
0
    def test_get_interface_usb(self, NonFiscalPrinter):
        device = DeviceSettings(store=self.store,
                                device_name=u'usb:0xa:0x1',
                                type=DeviceSettings.NON_FISCAL_PRINTER_DEVICE)

        obj = object()
        NonFiscalPrinter.return_value = obj
        self.assertIs(device.get_interface(), obj)
        NonFiscalPrinter.assert_called_with(brand=None, model=None, port=None,
                                            product_id=1, vendor_id=10,
                                            interface='usb')
Esempio n. 10
0
 def test_show(self, get_serial_devices):
     get_serial_devices.return_value = [
         _Device('/dev/ttyS0'),
         _Device('/dev/ttyS1')
     ]
     station = self.create_station()
     settings = DeviceSettings(store=self.store,
                               type=DeviceSettings.SCALE_DEVICE)
     editor = DeviceSettingsEditor(self.store,
                                   model=settings,
                                   station=station)
     self.check_editor(editor, 'editor-devicesetting-show')
Esempio n. 11
0
def test_device_settings_is_valid(store, current_station):
    device = DeviceSettings(store=store,
                            device_name=u'usb:0xa:0x1',
                            type=DeviceSettings.NON_FISCAL_PRINTER_DEVICE,
                            station=current_station)

    assert device.is_valid() is False

    device.model = "foo"
    device.brand = "bar"

    assert device.is_valid() is True
Esempio n. 12
0
    def test_get_interface_ethernet(self, NonFiscalPrinter):
        device = DeviceSettings(store=self.store,
                                device_name=u'ethernet:127.0.0.1:9100',
                                type=DeviceSettings.NON_FISCAL_PRINTER_DEVICE)

        obj = object()
        NonFiscalPrinter.return_value = obj
        self.assertIs(device.get_interface(), obj)
        NonFiscalPrinter.assert_called_with(
            brand=None,
            model=None,
            port=None,
            product_id=None,
            vendor_id=None,
            interface='ethernet',
            device_name='ethernet:127.0.0.1:9100')
Esempio n. 13
0
    def test_get_interface_serial(self, SerialPort, NonFiscalPrinter):
        device = DeviceSettings(store=self.store,
                                device_name=u'/dev/ttyUSB0',
                                type=DeviceSettings.NON_FISCAL_PRINTER_DEVICE)
        port0 = SerialPort(device=device.device_name)
        port1 = SerialPort(device=u'/dev/ttyUSB1')
        SerialPort.side_effect = [port0, SerialException, port1]
        obj = object()
        NonFiscalPrinter.return_value = obj
        self.assertIs(device.get_interface(), obj)
        SerialPort.assert_called_with(baudrate=9600, device=device.device_name)
        NonFiscalPrinter.assert_called_with(brand=None,
                                            model=None,
                                            port=port0,
                                            product_id=None,
                                            vendor_id=None,
                                            interface='serial',
                                            device_name='/dev/ttyUSB0')
        with mock.patch('os.path.exists') as mock_os:
            # Raising the SerialException because the device port has changed names.
            mock_os.side_effect = [False, True]
            SerialPort.assert_called_with(baudrate=9600,
                                          device=u'/dev/ttyUSB0')
            device.device_name = u'/dev/ttyUSB1'
            self.assertIs(device.get_interface(), obj)
            NonFiscalPrinter.assert_called_with(brand=None,
                                                model=None,
                                                port=port1,
                                                product_id=None,
                                                vendor_id=None,
                                                interface='serial',
                                                device_name='/dev/ttyUSB1')

        with mock.patch('os.path.exists') as mock_os:
            with self.assertRaises(SerialException):
                # SerialException, but the port is correct or OS is not Linux.
                mock_os.return_value = True
                SerialPort.side_effect = SerialException
                device.get_interface()

        with mock.patch('os.path.exists') as mock_os:
            with self.assertRaises(SerialException):
                # Device not in any ports we search.
                mock_os.return_value = False
                SerialPort.side_effect = SerialException
                device.get_interface()
Esempio n. 14
0
 def test_get_status_string(self):
     device = DeviceSettings(store=self.store)
     self.assertEqual(device.get_status_string(), _(u'Active'))
     device.inactivate()
     self.assertEqual(device.get_status_string(), _(u'Inactive'))
Esempio n. 15
0
 def test_activate(self):
     device = DeviceSettings(store=self.store, is_active=False)
     self.assertFalse(device.is_active)
     device.activate()
     self.assertTrue(device.is_active)
Esempio n. 16
0
 def test_is_a_printer(self):
     device = DeviceSettings(store=self.store,
                             type=DeviceSettings.CHEQUE_PRINTER_DEVICE)
     self.assertEquals(device.is_a_printer(), True)
     device.type = DeviceSettings.SCALE_DEVICE
     self.assertEquals(device.is_a_printer(), False)
Esempio n. 17
0
 def test_get_scale_settings(self):
     device = DeviceSettings(store=self.store,
                             type=DeviceSettings.SCALE_DEVICE)
     self.assertIsNone(device.get_scale_settings(store=self.store))