def test_handle_extra_options(session, handlers): handlers.register('LTD', LimitingHandler) collection = TicketCollection(session) collection.handlers = handlers collection.open_ticket(handler_id='1', handler_code='LTD') collection.open_ticket(handler_id='2', handler_code='LTD') collection.open_ticket(handler_id='3', handler_code='LTD') assert collection.subset().count() == 3 collection.extra_parameters = {'limit': 1} assert collection.subset().count() == 3 collection.handler = 'LTD' assert collection.subset().count() == 1 collection.extra_parameters = {'limit': 2} assert collection.subset().count() == 2
def test_snapshot_ticket(session, handlers): @handlers.registered_handler('FOO') class FooHandler(Handler): @property def deleted(self): return False @property def title(self): return 'Foo' @property def subtitle(self): return '0xdeadbeef' @property def group(self): return 'Bar' @property def handler_id(self): return 1 @property def handler_data(self): return {} @property def email(self): return '*****@*****.**' def get_summary(self, request): return 'foobar' collection = TicketCollection(session) ticket = collection.open_ticket( handler_id='1', handler_code='FOO' ) ticket.create_snapshot(request=object()) assert ticket.snapshot['email'] == '*****@*****.**' assert ticket.snapshot['summary'] == 'foobar'
def test_open_ticket(session, handlers): handlers.register('ECO', EchoHandler) collection = TicketCollection(session) ticket = collection.open_ticket( handler_id='1', handler_code='ECO', title="Title", subtitle="Subtitle", group="Group", summary="Summary", links=[("Link", '#')], email="*****@*****.**" ) assert ticket.number.startswith('ECO-') assert ticket.title == "Title" assert ticket.group == "Group" assert ticket.handler_id == '1' assert ticket.handler_code == 'ECO' assert ticket.handler_data == { 'title': "Title", 'subtitle': "Subtitle", 'group': "Group", 'summary': "Summary", 'links': [("Link", '#')], 'email': "*****@*****.**" } assert ticket.handler.get_summary(request=object()) == "Summary" assert ticket.handler.get_links(request=object()) == [("Link", '#')] ticket.handler_data['title'] = "Test" assert ticket.title == "Title" ticket.handler.refresh() assert ticket.title == "Test" assert len(collection.by_handler_code("ECO")) == 1 assert collection.by_id(ticket.id) assert collection.by_id(ticket.id, ensure_handler_code='FOO') is None assert collection.by_handler_id('1') is not None
def test_ticket_statistics(town_app, smtp, handlers): register_echo_handler(handlers) client = Client(town_app) job = get_cronjob_by_name(town_app, 'ticket_statistics') job.app = town_app url = get_cronjob_url(job) tz = ensure_timezone('Europe/Zurich') assert len(smtp.outbox) == 0 # do not run on the weekends with freeze_time(datetime(2016, 1, 2, tzinfo=tz)): client.get(url) with freeze_time(datetime(2016, 1, 3, tzinfo=tz)): client.get(url) assert len(smtp.outbox) == 0 session = town_app.session() collection = TicketCollection(session) tickets = [ collection.open_ticket( handler_id='1', handler_code='ECO', title="Title", group="Group", email="*****@*****.**", created=datetime(2016, 1, 2, 10, tzinfo=tz), ), collection.open_ticket( handler_id='2', handler_code='ECO', title="Title", group="Group", email="*****@*****.**", created=datetime(2016, 1, 2, 10, tzinfo=tz) ), collection.open_ticket( handler_id='3', handler_code='ECO', title="Title", group="Group", email="*****@*****.**", created=datetime(2016, 1, 2, 10, tzinfo=tz) ), collection.open_ticket( handler_id='4', handler_code='ECO', title="Title", group="Group", email="*****@*****.**", created=datetime(2016, 1, 2, 10, tzinfo=tz) ), collection.open_ticket( handler_id='5', handler_code='ECO', title="Title", group="Group", email="*****@*****.**", created=datetime(2016, 1, 2, 10, tzinfo=tz) ), collection.open_ticket( handler_id='6', handler_code='ECO', title="Title", group="Group", email="*****@*****.**", created=datetime(2016, 1, 2, 10, tzinfo=tz) ) ] users = UserCollection(session).query().all() user = users[0] users[1].data = {'daily_ticket_statistics': False} for ticket in tickets: ticket.created = datetime(2016, 1, 2, 10, tzinfo=tz) for pending in tickets[1:3]: pending.accept_ticket(user) pending.modified = datetime(2016, 1, 2, 10, tzinfo=tz) for closed in tickets[3:6]: closed.accept_ticket(user) closed.close_ticket() closed.modified = datetime(2016, 1, 2, 10, tzinfo=tz) transaction.commit() with freeze_time(datetime(2016, 1, 4, tzinfo=tz)): client.get(url) assert len(smtp.outbox) == 1 message = get_mail(smtp.outbox, 0) assert message['subject'] == 'Govikon OneGov Cloud Status' txt = message['text'] assert "Folgendes ist während des Wochenendes auf der Govikon" in txt assert "6 Tickets wurden eröffnet." in txt assert "2 Tickets wurden angenommen." in txt assert "3 Tickets wurden geschlossen." in txt assert "Zur Zeit ist 1 Ticket offen" in txt assert "2 Tickets sind in Bearbeitung" in txt assert "Wir wünschen Ihnen eine schöne Woche!" in txt assert "Das OneGov Cloud Team" in txt assert "über das Benutzerprofil abbestellen" in txt