Beispiel #1
0
def test_single_row_restrictions_enabled(c):
    task = Task.get()
    office = task.offices[0]

    if not Settings.get().single_row:
        c.get('/settings/single_row', follow_redirects=True)

    assert Settings.get().single_row is True

    message = f'flag setting single_row must be disabled'
    contains_message = lambda p: message in c\
        .get(p, follow_redirects=True)\
        .data.decode('utf-8')

    assert contains_message(f'/serial/{task.id}') is True
    assert contains_message('/serial_ra') is True
    assert contains_message(f'/serial_rt/{task.id}') is True
    assert contains_message(f'/pull_unordered/1/test') is True
    assert contains_message(f'/on_hold/1/test') is True
    assert contains_message(f'/touch/1') is True
    assert contains_message(f'/offices/{office.id}') is True
    assert contains_message(f'/office_a') is True
    assert contains_message(f'/office_d/{office.id}') is True
    assert contains_message(f'/office_da') is True
    assert contains_message(f'/task/{task.id}') is True
    assert contains_message(f'/task_d/{task.id}') is True
    assert contains_message(f'/common_task_a') is True
    assert contains_message(f'/task_a/{office.id}') is True
Beispiel #2
0
def test_toggle_setting(c):
    with c.application.app_context():
        setting = 'visual_effects'
        setting_value = getattr(Settings.get(), setting)

    c.get(f'/settings/{setting}/testing')
    assert getattr(Settings.get(), setting) == (not setting_value)
Beispiel #3
0
def test_single_row_restrictions_disabled(c):
    with c.application.app_context():
        task = Task.get()
        office = task.offices[0]

        if Settings.get().single_row:
            c.get('/settings/single_row', follow_redirects=True)

        assert Settings.get().single_row is False

    message = f'flag setting single_row must be disabled'
    contains_message = lambda p: message in c\
        .get(p, follow_redirects=True)\
        .data.decode('utf-8')

    assert contains_message(f'/serial/{task.id}') is False
    assert contains_message('/serial_ra') is False
    assert contains_message(f'/serial_rt/{task.id}') is False
    assert contains_message(f'/touch/1') is False
    assert contains_message(f'/offices/{office.id}') is False
    assert contains_message(f'/office_a') is False
    assert contains_message(f'/office_d/{office.id}') is False
    assert contains_message(f'/office_da') is False
    assert contains_message(f'/task/{task.id}') is False
    assert contains_message(f'/task_d/{task.id}') is False
    assert contains_message(f'/common_task_a') is False
    assert contains_message(f'/task_a/{office.id}') is False
Beispiel #4
0
    def format_announcement_text(self, ticket, aliases, language, show_prefix):
        ''' Helper to format text-to-speech text.

        Parameters
        ----------
            ticket: Serial record
            aliases: Aliases record
            language: str
                language of text-to-speech to produce
            show_prefix: bool
                include the office prefix in the announcement

        Returns
        -------
            String of formated text-to-speech text ready to use.
        '''
        with self.app.app_context():
            single_row_queuing = Settings.get().single_row
            office_text = ''
            tts_text = ''

            if not single_row_queuing:
                office = ticket.office
                prefix = office.prefix if show_prefix else ''
                office_text = f'{prefix}{getattr(office, "name", "")}'
                tts_text = get_tts_safely().get(language, {})\
                                           .get('message')

                if language.startswith('en'):
                    tts_text = tts_text.format(aliases.office)

            return ticket.display_text if single_row_queuing\
                else f'{ticket.display_text}{tts_text}{office_text}'
Beispiel #5
0
    def inject_vars():
        ''' Injecting default variables to all templates. '''
        ar = session.get('lang') == 'AR'  # adding language support var

        # modifying side bar spacing for specific paths
        path = request.path
        admin_routes = [
            '/users', '/user_a', '/admin_u', '/user_u', '/csv', '/settings'
        ]
        admin_route = any([
            path in admin_routes, path[:7] in admin_routes, path[:5]
            in admin_routes
        ])

        return dict(path=path,
                    adme=admin_route,
                    brp=Markup('<br>'),
                    ar=ar,
                    version=VERSION,
                    str=str,
                    defLang=session.get('lang'),
                    getattr=getattr,
                    settings=Settings.get(),
                    Serial=Serial,
                    checkId=lambda id, records: id in [i.id for i in records],
                    offices=Office.query.all(),
                    moment_wrapper=moment_wrapper,
                    current_path=quote(request.path, safe=''),
                    windows=os.name == 'nt',
                    unix=os.name != 'nt')
Beispiel #6
0
def test_pull_tickets_from_common_task(_, c):
    with c.application.app_context():
        # NOTE: Disabling strict pulling
        settings = Settings.get()
        settings.strict_pulling = False
        db.session.commit()

        task = Task.get_first_common()
        office = choice(task.offices)
        ticket_to_be_pulled = Serial.query.order_by(Serial.number)\
                                          .filter(Serial.number != 100, Serial.p != True,
                                                  Serial.task_id == task.id)\
                                          .first()

    response = c.get(f'/pull/{task.id}/{office.id}', follow_redirects=True)
    pulled_ticket = Serial.query.filter_by(number=ticket_to_be_pulled.number,
                                           office_id=office.id,
                                           task_id=task.id,
                                           p=True)\
                                .order_by(Serial.number)\
                                .first()

    assert response.status == '200 OK'
    assert ticket_to_be_pulled is not None
    assert ticket_to_be_pulled.p is False
    assert pulled_ticket is not None
    assert pulled_ticket.task_id == task.id
    assert pulled_ticket.office_id == office.id
Beispiel #7
0
def test_single_row_pulling(_, c):
    if not Settings.get().single_row:
        c.get('/settings/single_row', follow_redirects=True)

    assert Settings.get().single_row is True

    office = Office.get(0)
    tickets_length = office.tickets.count()
    last_number = getattr(
        office.tickets.order_by(Serial.timestamp.desc()).first(), 'number',
        100)

    response = c.get(f'/pull', follow_redirects=True)

    assert response.status == '200 OK'
    assert Office.get(0).tickets.count() - 1 == tickets_length
    assert Office.get(0).tickets.first().number - 1 == last_number
    assert Office.get(0).tickets.first().p is True
Beispiel #8
0
def test_single_row_feed(_, c):
    if not Settings.get().single_row:
        c.get('/settings/single_row', follow_redirects=True)

    assert Settings.get().single_row is True

    c.get(f'/pull', follow_redirects=True)

    current_ticket = Serial.get_last_pulled_ticket(0)
    expected_parameters = {
        f'w{_index + 1}': f'{_index + 1}. {number}'
        for _index, number in enumerate(
            range(current_ticket.number + 1, current_ticket.number + 9))
    }

    response = c.get('/feed')

    for key, value in expected_parameters.items():
        assert response.json.get(key) == value
Beispiel #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}"')
Beispiel #10
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')
Beispiel #11
0
def test_pull_tickets_from_common_task(_, c):
    settings = Settings.get()
    settings.strict_pulling = False
    db.session.commit()
    task = Task.get_first_common()
    office = choice(task.offices)
    ticket_to_be_pulled = do_until_truthy(
        fill_tickets, lambda: Serial.query.order_by(Serial.number).filter(
            Serial.number != 100, Serial.p != True, Serial.task_id == task.id).
        first())

    response = c.get(f'/pull/{task.id}/{office.id}', follow_redirects=True)
    pulled_ticket = Serial.get(ticket_to_be_pulled.id)

    assert response.status == '200 OK'
    assert ticket_to_be_pulled is not None
    assert ticket_to_be_pulled.p is False
    assert pulled_ticket is not None
    assert pulled_ticket.task_id == task.id
    assert pulled_ticket.office_id == office.id
Beispiel #12
0
def test_new_printed_ticket_lp(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()
    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)

    with c.application.app_context():
        # NOTE: set ticket setting to printed and enable lp
        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
        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}"')
Beispiel #13
0
    def inject_vars():
        ''' Injecting default variables to all templates. '''
        ar = session.get('lang') == 'AR'  # adding language support var
        path = request.path or ''

        return dict(
            brp=Markup('<br>'),
            ar=ar,
            version=VERSION,
            str=str,
            defLang=session.get('lang'),
            getattr=getattr,
            settings=Settings.get(),
            Serial=Serial,
            next=next,
            it=iter,
            checkId=lambda id, records: id in [i.id for i in records],
            offices=Office.query.all(),
            moment_wrapper=moment_wrapper,
            current_path=quote(path, safe=''),
            windows=os.name == 'nt',
            unix=os.name != 'nt',
            setattr=lambda *args, **kwargs: setattr(*args, **kwargs) or '',
            adme=path in get_bp_endpoints(administrate))
Beispiel #14
0
def test_toggle_setting(c):
    setting = 'visual_effects'
    setting_value = getattr(Settings.get(), setting)

    c.get(f'/settings/{setting}/testing')
    assert getattr(Settings.get(), setting) == (not setting_value)