Esempio n. 1
0
def test_align_date_to_month():
    date = datetime(2012, 2, 26, 15, tzinfo=UTC)

    assert sedate.align_date_to_month(date, 'UTC', 'down')\
        == datetime(2012, 2, 1, tzinfo=UTC)

    assert sedate.align_date_to_month(date, 'UTC', 'up')\
        == datetime(2012, 2, 29, 23, 59, 59, 999999, tzinfo=UTC)

    # Ensure that daylight-savings time is taken into account
    timezone = sedate.ensure_timezone('Europe/Zurich')

    # The beginning of this month is part of DST
    date = datetime(2020, 10, 30, tzinfo=timezone)
    assert not date.dst()
    assert sedate.align_date_to_month(date, 'Europe/Zurich', 'down').dst()

    # The end of this month is not part of DST
    date = datetime(2020, 10, 1, tzinfo=timezone)
    assert date.dst()
    assert not sedate.align_date_to_month(date, 'Europe/Zurich', 'up').dst()
Esempio n. 2
0
def test_ensure_timezone():
    assert sedate.ensure_timezone('Europe/Zurich') \
        == pytz.timezone('Europe/Zurich')

    assert sedate.ensure_timezone(pytz.timezone('Europe/Zurich')) \
        == pytz.timezone('Europe/Zurich')
Esempio n. 3
0
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