Beispiel #1
0
def test_seminar_events_seminars_error():
    """
    This test checks Seminar Utilities correctly handles the ITEE website being unavailable.
    The correct behaviour is to throw an exception.
    """
    try:
        get_seminars()
        assert False
    except HttpException as e:
        assert e.url == "SEMINAR-URL"
        assert e.status_code == 500
Beispiel #2
0
def test_seminars_events_no_results():
    """
    This test checks Seminar Utilities correctly handles
    no seminars being listed on the ITEE website.
    """
    summaries = get_seminars()
    assert len(summaries) == 0
Beispiel #3
0
def test_seminars_events_partial_results():
    """
    This test checks Seminar Utilities correctly provides partial seminar information when the
    seminar listings page is available on the ITEE website, but not all of the details pages.
    """
    summaries = get_seminars()
    brisbaneTime = timezone('Australia/Brisbane')
    expectedDate1 = datetime(2019, 5, 28, 12, 0, 0, tzinfo=brisbaneTime)
    expectedDate2 = datetime(2019, 5, 29, 13, 0, 0, tzinfo=brisbaneTime)

    assert len(summaries) == 2
    assert summaries[0] == (
        'Introduction to functional programming',
        'https://www.itee.uq.edu.au/introduction-functional-programming',
        expectedDate1, '78-420')
    assert summaries[1] == (
        'Performance Enhancement of Software Defined Cellular 5G &' +
        ' Internet-of-Things Networks - Furqan Khan',
        'https://www.itee.uq.edu.au/performance-enhancement-software' +
        '-defined-cellular-5g-and-internet-things-networks', expectedDate2,
        '78-430')
Beispiel #4
0
def test_seminars_events_typical():
    """
    This test checks Seminar Utilities correctly provides seminar information
    when all ITEE website pages are available and correctly formatted.
    """
    summaries = get_seminars()
    brisbaneTime = timezone('Australia/Brisbane')
    expectedDate1 = datetime(2019, 5, 28, 12, 0, 0, tzinfo=brisbaneTime)
    expectedDate2 = datetime(2019, 5, 29, 13, 0, 0, tzinfo=brisbaneTime)

    assert len(summaries) == 2
    assert summaries[0] == (
        'Introduction to functional programming - Tony Morris, Software' +
        ' Engineer at Data61',
        'https://www.itee.uq.edu.au/introduction-functional-programming',
        expectedDate1, '78-420')
    assert summaries[1] == (
        'Performance Enhancement of Software Defined Cellular 5G &' +
        ' Internet-of-Things Networks - Furqan Khan',
        'https://www.itee.uq.edu.au/performance-enhancement-software' +
        '-defined-cellular-5g-and-internet-things-networks', expectedDate2,
        '78-430')
Beispiel #5
0
def handle_events(command: Command):
    """
    `!events [full|all|NUM EVENTS|<NUM WEEKS> weeks] [uqcs|itee]`
    - Lists all the UQCS and/or  ITEE events that are
    scheduled to occur within the given filter.
    If unspecified, will return the next 2 weeks of events.
    """

    argument = command.arg if command.has_arg() else ""

    source_get = {"uqcs": False, "itee": False}
    for k in source_get:
        if k in argument:
            source_get[k] = True
            argument = argument.replace(k, "")
    argument = argument.strip()
    if not any(source_get.values()):
        source_get = dict.fromkeys(source_get, True)

    event_filter = EventFilter.from_argument(argument)
    if not event_filter.is_valid:
        raise UsageSyntaxException()

    cal = Calendar.from_ical(get_calendar_file())
    current_time = get_current_time()

    events = []
    # subcomponents are how icalendar returns the list of things in the calendar
    if source_get["uqcs"]:
        for c in cal.subcomponents:
            # TODO: support recurring events
            # we are only interested in ones with the name VEVENT as they
            # are events we also currently filter out recurring events
            if c.name != 'VEVENT' or c.get('RRULE') is not None:
                continue

            # we convert it to our own event class
            event = Event.from_cal_event(c)
            # then we want to filter out any events that are not after the current time
            if event.start > current_time:
                events.append(event)

    if source_get["itee"]:
        try:
            # Try to include events from the ITEE seminars page
            seminars = get_seminars()
            for seminar in seminars:
                # The ITEE website only lists current events.
                event = Event.from_seminar(seminar)
                events.append(event)
        except (HttpException, InvalidFormatException) as e:
            bot.logger.error(e.message)

    # then we apply our event filter as generated earlier
    events = event_filter.filter_events(events, current_time)
    # then, we sort the events by date
    events = sorted(events, key=lambda event_: event_.start)

    attachments = []
    if not events:
        message_text = f"_{event_filter.get_no_result_msg()}_\n" \
                       f"For a full list of events, visit: " \
                       f"https://uqcs.org.au/calendar.html " \
                       f"and https://www.itee.uq.edu.au/seminar-list"

    else:
        for event in events:
            color = "#5297D1" if event.source == "UQCS" else "#51237A"
            attachments.append(
                Attachment(SectionBlock(str(event)), color=color))
        message_text = f"_{event_filter.get_header()}_"

    bot.post_message(
        command.channel_id,
        text=message_text,
        attachments=[attachment._resolve() for attachment in attachments])