Esempio n. 1
0
def test_ticket_registered(c):
    with c.application.app_context():
        touch_screen_settings = Touch_store.get()
        touch_screen_settings.n = True
        db.session.commit()

    printer_value = 1
    response = c.post('/ticket',
                      data={'value': printer_value},
                      follow_redirects=True)

    assert response.status == '200 OK'
    assert Printer.get().value == printer_value
    assert Printer.get().active is False
    assert Touch_store.get().n is True
Esempio n. 2
0
def test_touch_screen_customization(c):
    properties = {
        'title': 'testing',
        'hsize': '500%',
        'hcolor': 'testing',
        'hbg': 'testing',
        'mbg': 'testing',
        'tsize': '200%',
        'tcolor': 'btn-info',
        'msize': '300%',
        'mcolor': 'testing',
        'mduration': '1000',
        'hfont': 'testing',
        'tfont': 'testing',
        'mfont': 'testing',
        'message': 'testing',
    }

    data = {'touch': 2, 'background': 0, 'naudio': 0, **properties}

    response = c.post('/touchscreen_c/1', data=data, follow_redirects=True)

    assert response.status == '200 OK'
    for key, value in properties.items():
        assert getattr(Touch_store.get(), key, None) == value
Esempio n. 3
0
def test_new_printed_ticket_arabic(c, monkeypatch):
    last_ticket = None
    mock_printer = MagicMock()
    image_path = os.path.join(os.getcwd(), 'dummy.jpg')
    monkeypatch.setattr(escpos.printer, 'Usb', mock_printer)

    printer_settings = Printer.get()
    touch_screen_settings = Touch_store.get()
    touch_screen_settings.n = False
    printer_settings.vendor = 150
    printer_settings.product = 3
    printer_settings.in_ep = 170
    printer_settings.out_ep = 170
    printer_settings.langu = 'ar'
    db.session.commit()
    task = choice(Task.query.all())
    last_ticket = Serial.query.filter_by(task_id=task.id)\
                              .order_by(Serial.number.desc()).first()

    name = 'TESTING PRINTED TICKET'
    response = c.post(f'/serial/{task.id}', data={
        'name': name
    }, follow_redirects=True)
    new_ticket = Serial.query.filter_by(task_id=task.id)\
                             .order_by(Serial.number.desc()).first()

    assert response.status == '200 OK'
    assert last_ticket.number != new_ticket.number
    assert new_ticket.name == name
    assert mock_printer().text.call_count == 1
    mock_printer().cut.assert_called_once()
    mock_printer().close.assert_called_once()
    mock_printer().image.assert_called_once_with(image_path,
                                                 fragment_height=580,
                                                 high_density_vertical=True)
Esempio n. 4
0
def test_new_printed_ticket(c, monkeypatch):
    last_ticket = None
    mock_printer = MagicMock()
    monkeypatch.setattr(escpos.printer, 'Usb', mock_printer)

    # NOTE: set ticket setting to printed
    printer_settings = Printer.get()
    touch_screen_settings = Touch_store.get()
    touch_screen_settings.n = False
    printer_settings.vendor = 150
    printer_settings.product = 3
    printer_settings.in_ep = 170
    printer_settings.out_ep = 170
    db.session.commit()
    task = choice(Task.query.all())
    last_ticket = Serial.query.filter_by(task_id=task.id)\
                              .order_by(Serial.number.desc()).first()

    name = 'TESTING PRINTED TICKET'
    response = c.post(f'/serial/{task.id}', data={
        'name': name
    }, follow_redirects=True)
    new_ticket = Serial.query.filter_by(task_id=task.id)\
                             .order_by(Serial.number.desc()).first()

    assert response.status == '200 OK'
    assert last_ticket.number != new_ticket.number
    assert new_ticket.name == name
    assert mock_printer().text.call_count == 12
    assert mock_printer().set.call_count == 7
    mock_printer().set.assert_called_with(align='left', height=1, width=1)
    mock_printer().cut.assert_called_once()
Esempio n. 5
0
def test_ticket_printed(c, monkeypatch):
    vendor = 50
    product = 3
    in_ep = 130
    out_ep = 170
    in_config = namedtuple('in_config', ['bEndpointAddress'])
    usb_device = namedtuple(
        'usb', ['get_active_configuration', 'idVendor', 'idProduct'])
    mock_usb_find = MagicMock(return_value=[
        usb_device(lambda: {(0, 0): [in_config(in_ep),
                                     in_config(out_ep)]}, vendor, product)
    ])
    monkeypatch.setattr(usb.core, 'find', mock_usb_find)

    with c.application.app_context():
        # NOTE: set ticket setting to printed
        touch_screen_settings = Touch_store.get()
        touch_screen_settings.n = False
        db.session.commit()

    printer_value = 1
    kind = 2  # NOTE: Printed
    lang = 'en'
    printers = f'{vendor}_{product}_{in_ep}_{out_ep}'
    scale = 2
    response = c.post('/ticket',
                      data={
                          'value': printer_value,
                          'kind': kind,
                          'langu': lang,
                          'printers': printers,
                          'scale': scale
                      },
                      follow_redirects=True)

    assert response.status == '200 OK'
    assert Touch_store.get().n is False
    assert Printer.get().active is True
    assert Printer.get().value == printer_value
    assert Printer.get().langu == lang
    assert Printer.get().scale == scale
    assert Printer.get().in_ep == in_ep
    assert Printer.get().out_ep == out_ep
    assert Printer.get().vendor == vendor
    assert Printer.get().product == product
    assert mock_usb_find.call_count == 2
Esempio n. 6
0
def test_ticket_printed_lp(c, monkeypatch):
    name = 'testing_printer'
    secondName = 'testing_second_printer'
    printers = [
        f'{name} description stuff testing',
        f'{secondName} description stuff testing'
    ]
    mock_execute = MagicMock(return_value=printers)
    mock_os = MagicMock()
    mock_os.name = 'linux'
    monkeypatch.setattr(app.printer, 'execute', mock_execute)
    monkeypatch.setattr(app.views.customize, 'os', mock_os)
    monkeypatch.setattr(app.forms, 'name', 'nt')

    with c.application.app_context():
        # NOTE: set ticket setting to printed
        settings = Settings.get()
        touch_screen_settings = Touch_store.get()
        touch_screen_settings.n = False
        settings.lp_printing = True
        db.session.commit()

    printer_value = 1
    kind = 2  # NOTE: Printed
    lang = 'en'
    scale = 2
    response = c.post('/ticket',
                      data={
                          'value': printer_value,
                          'kind': kind,
                          'langu': lang,
                          'printers': secondName,
                          'scale': scale
                      },
                      follow_redirects=True)

    assert response.status == '200 OK'
    assert Touch_store.get().n is False
    assert Printer.get().active is True
    assert Printer.get().value == printer_value
    assert Printer.get().langu == lang
    assert Printer.get().scale == scale
    assert Printer.get().name == secondName
    assert mock_execute.call_count == 2
    mock_execute.assert_called_with('lpstat -a', parser='\n')
Esempio n. 7
0
def test_new_printed_ticket_with_aliases(c, monkeypatch):
    last_ticket = None
    mock_printer = MagicMock()
    monkeypatch.setattr(escpos.printer, 'Usb', mock_printer)

    # NOTE: set ticket setting to printed
    printer_settings = Printer.get()
    touch_screen_settings = Touch_store.get()
    touch_screen_settings.n = False
    printer_settings.vendor = 150
    printer_settings.product = 3
    printer_settings.in_ep = 170
    printer_settings.out_ep = 170
    # NOTE: setting aliases
    office_alt = 'Department'
    task_alt = 'Mission'
    ticket_alt = 'Token'
    aliases = Aliases.get()
    aliases.office = office_alt
    aliases.task = task_alt
    aliases.ticket = ticket_alt
    db.session.commit()
    task = choice(Task.query.all())
    last_ticket = Serial.query.filter_by(task_id=task.id)\
                              .order_by(Serial.number.desc()).first()

    name = 'TESTING PRINTED TICKET'
    response = c.post(f'/serial/{task.id}',
                      data={'name': name},
                      follow_redirects=True)
    new_ticket = Serial.query.filter_by(task_id=task.id)\
                             .order_by(Serial.number.desc()).first()
    office = new_ticket.office
    tickets = Serial.all_office_tickets(office.id, desc=False)\
                    .filter(Serial.number != new_ticket.number)
    cur_ticket = tickets.first()

    assert response.status == '200 OK'
    assert last_ticket.number != new_ticket.number
    assert new_ticket.name == name
    assert mock_printer().text.call_count == 12
    assert mock_printer().set.call_count == 7
    mock_printer().set.assert_called_with(align='left', height=1, width=1)
    mock_printer().cut.assert_called_once()
    mock_printer().text.assert_any_call(
        f'\n{office_alt} : {office.prefix}{office.name}\n')
    mock_printer().text.assert_any_call(
        f'\n{office.prefix}.{new_ticket.number}\n')
    mock_printer().text.assert_any_call(
        f'\n{ticket_alt}s ahead : {tickets.count()}\n')
    mock_printer().text.assert_any_call(
        f'\n{task_alt} : {new_ticket.task.name}\n')
    mock_printer().text.assert_any_call(
        f'\nCurrent {ticket_alt.lower()} : {office.prefix}.{cur_ticket and cur_ticket.number}\n'
    )
Esempio n. 8
0
def test_ticket_printed_windows(c, monkeypatch):
    name = 'testing_printer'
    secondName = 'second_testing_printer'
    printers = ['', name, secondName]
    mock_execute = MagicMock(return_value=printers)
    mock_os = MagicMock()
    mock_os.name = 'nt'
    monkeypatch.setattr(app.printer, 'execute', mock_execute)
    monkeypatch.setattr(app.views.customize, 'os', mock_os)
    monkeypatch.setattr(app.forms.customize, 'os', mock_os)

    touch_screen_settings = Touch_store.get()
    touch_screen_settings.n = False
    db.session.commit()

    printer_value = 1
    kind = 2  # NOTE: Printed
    lang = 'en'
    scale = 2
    response = c.post('/ticket',
                      data={
                          'value': printer_value,
                          'kind': kind,
                          'langu': lang,
                          'printers': name,
                          'scale': scale
                      },
                      follow_redirects=True)

    assert response.status == '200 OK'
    assert Touch_store.get().n is False
    assert Printer.get().active is True
    assert Printer.get().value == printer_value
    assert Printer.get().langu == lang
    assert Printer.get().scale == scale
    assert Printer.get().name == name
    assert mock_execute.call_count == 2
    mock_execute.assert_called_with('wmic printer get sharename',
                                    parser='\n',
                                    encoding='utf-16')
Esempio n. 9
0
def test_new_printed_ticket_lp_arabic(c, monkeypatch):
    last_ticket = None
    printer_name = 'testing_printer'
    printer_path = 'testing_path'
    printer_full_path = os.path.join(os.getcwd(), f'{printer_path}.txt')
    mock_uuid = MagicMock()
    mock_uuid.uuid4 = MagicMock(return_value=printer_path)
    mock_os = MagicMock()
    mock_os.name = 'linux'
    mock_system = MagicMock()
    mock_pil = MagicMock()
    mock_pil.truetype().getsize.return_value = (0, 0)
    mock_pos = MagicMock()
    mock_pos().output = b''
    monkeypatch.setattr(app.views.core, 'os', mock_os)
    monkeypatch.setattr(app.printer, 'name', 'linux')
    monkeypatch.setattr(app.printer, 'uuid', mock_uuid)
    monkeypatch.setattr(app.printer, 'system', mock_system)
    monkeypatch.setattr(app.printer, 'ImageDraw', mock_pil)
    monkeypatch.setattr(app.printer, 'Image', mock_pil)
    monkeypatch.setattr(app.printer, 'ImageFont', mock_pil)
    monkeypatch.setattr(app.printer, 'Dummy', mock_pos)

    settings = Settings.get()
    printer_settings = Printer.get()
    touch_screen_settings = Touch_store.get()
    settings.lp_printing = True
    touch_screen_settings.n = False
    printer_settings.name = printer_name
    printer_settings.langu = 'ar'
    db.session.commit()
    task = choice(Task.query.all())
    last_ticket = Serial.query.filter_by(task_id=task.id)\
                              .order_by(Serial.number.desc()).first()

    name = 'TESTING PRINTED TICKET'
    response = c.post(f'/serial/{task.id}',
                      data={'name': name},
                      follow_redirects=True)
    new_ticket = Serial.query.filter_by(task_id=task.id)\
                             .order_by(Serial.number.desc()).first()

    assert response.status == '200 OK'
    assert last_ticket.number != new_ticket.number
    assert new_ticket.name == name
    mock_system.assert_called_once_with(
        f'lp -d "{printer_name}" -o raw "{printer_full_path}"')
Esempio n. 10
0
def test_new_printed_ticket_windows_arabic(c, monkeypatch):
    last_ticket = None
    printer_name = 'testing_printer'
    printer_path = 'testing_path'
    printer_full_path = os.path.join(os.getcwd(), f'{printer_path}.txt')
    mock_uuid = MagicMock()
    mock_uuid.uuid4 = MagicMock(return_value=printer_path)
    mock_os = MagicMock()
    mock_os.name = 'nt'
    mock_system = MagicMock()
    monkeypatch.setattr(app.views.core, 'os', mock_os)
    monkeypatch.setattr(app.printer, 'name', 'nt')
    monkeypatch.setattr(app.printer, 'uuid', mock_uuid)
    monkeypatch.setattr(app.printer, 'system', mock_system)

    with c.application.app_context():
        # NOTE: set ticket setting to printed
        printer_settings = Printer.get()
        touch_screen_settings = Touch_store.get()
        touch_screen_settings.n = False
        printer_settings.name = printer_name
        printer_settings.langu = 'ar'
        db.session.commit()

        task = choice(Task.query.all())
        last_ticket = Serial.query.filter_by(task_id=task.id)\
                                  .order_by(Serial.number.desc()).first()

    name = 'TESTING PRINTED TICKET'
    response = c.post(f'/serial/{task.id}',
                      data={'name': name},
                      follow_redirects=True)
    new_ticket = Serial.query.filter_by(task_id=task.id)\
                             .order_by(Serial.number.desc()).first()

    assert response.status == '200 OK'
    assert last_ticket.number != new_ticket.number
    assert new_ticket.name == name
    mock_system.assert_called_once_with(
        f'print /D:\\\localhost\\"{printer_name}" "{printer_full_path}"'
    )  # noqa