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' )
def test_aliases(c): data = { 'office': 't_office', 'task': 't_task', 'ticket': 't_ticket', 'name': 't_name', 'number': 't_number', } response = c.post('/alias', data=data, follow_redirects=True) assert response.status == '200 OK' for key, value in data.items(): assert getattr(Aliases.get(), key, None) == value
def test_get_with_alias(c, monkeypatch): office = 't_office' task = 't_task' ticket = 't_ticket' aliases = Aliases.get() aliases.office = office aliases.task = task aliases.ticket = ticket db.session.commit() alt_aliases = get_with_alias(DB_NAME) assert office in alt_aliases.get('\nOffice : ') assert ticket in alt_aliases.get('\nCurrent ticket : ') assert task in alt_aliases.get('\nTask : ')
def main(): display_settings = Display_store.get() if display_settings.announce != 'false': aliases = Aliases.get() languages = display_settings.announce.split(',') tickets_to_remove = Serial.query.filter(Serial.p == True, Serial.number.in_(self.cached)) tickets_to_cache = Serial.query.filter(Serial.p == False, Serial.number != 100, not_(Serial.number.in_(self.cached)))\ .order_by(Serial.timestamp)\ .limit(self.limit) @self.none_blocking_loop(tickets_to_cache) def cache_tickets(ticket): successes = [] @self.none_blocking_loop(languages) def loop_languages(language): try: gTTs.say(language, self.format_announcement_text(ticket, aliases, language, display_settings.prefix)) successes.append(language) except Exception as exception: log_error(exception, quiet=self.quiet) self.log(exception, error=True) if successes: self.cached.append(ticket.number) self.log(f'Cached TTS {ticket.number}') @self.none_blocking_loop(tickets_to_remove) def remove_processed_tickets_from_cache(ticket): self.cached.remove(ticket.number) # NOTE: cache stack is adhereing to the limit to avoid overflow self.cached = self.cached[:self.limit]