Exemplo n.º 1
0
def test_filter_calendar_by_date_and_re_pattern():
    filtered_calendar = CalendarFilter(
        input_file=Path(CURR_DIR / "data" / "ics" / "urlab.ics"),
        re_pattern="workshop",
        start_date="2020-02-04",
        end_date="2020-05-04",
    )
    filtered_calendar.filter_calendars()
    result = filtered_calendar.result
    assert result == [
        {
            "name": "Workshop réseaux de neurones",
            "start": "2020-02-17",
            "duration": 16200.0,
        },
        {
            "name": "Workshop Make no2",
            "start": "2020-03-12",
            "duration": 7200.0
        },
        {
            "name": "Workshop Make no1",
            "start": "2020-03-10",
            "duration": 7201.0
        },
    ]
Exemplo n.º 2
0
 def read_ics(file_path: Path) -> List[Dict]:
     with open(file_path, "rt") as in_f:
         cals = Calendar.parse_multiple(in_f.read())
     result = []
     for c in cals:
         for e in c.events:
             CalendarFilter.add_result(result=result, event=e)
     return result
Exemplo n.º 3
0
def test_filter_calendar_without_any_filter():
    filtered_calendar = CalendarFilter(input_file=Path(
        CURR_DIR / "data" / "ics" / "02-04_05-05-2020_urlab.ics"), )
    filtered_calendar.filter_calendars()
    result = filtered_calendar.result
    expected_result = [
        {
            "name": "SmartMonday de Mai 2020",
            "start": "2020-05-04",
            "duration": 9000.0
        },
        {
            "name": "Mardi C'est root-me",
            "start": "2020-02-18",
            "duration": 7200.0
        },
        {
            "name": "Workshop Make no1",
            "start": "2020-03-10",
            "duration": 7201.0
        },
        {
            "name": "VenDreDDi",
            "start": "2020-02-07",
            "duration": 18000.0
        },
        {
            "name": "La première réunion du quadri",
            "start": "2020-02-04",
            "duration": 5400.0,
        },
        {
            "name": "Réunion débat timent",
            "start": "2020-02-25",
            "duration": 5400.0
        },
        {
            "name": "SmartMonday de Mars 2020",
            "start": "2020-03-09",
            "duration": 12600.0,
        },
        {
            "name": "Workshop Make no2",
            "start": "2020-03-12",
            "duration": 7200.0
        },
        {
            "name": "Workshop réseaux de neurones",
            "start": "2020-02-17",
            "duration": 16200.0,
        },
        {
            "name": "« Et demain ? »",
            "start": "2020-02-13",
            "duration": 7200.0
        },
    ]
    assert result == expected_result
Exemplo n.º 4
0
def test_filter_calendar_to_output_ics():
    filtered_calendar = CalendarFilter(
        input_file=CURR_DIR / "data" / "ics" / "urlab.ics",
        start_date="2020-02-04",
        end_date="2020-05-05",
        output_format="ics",
    )
    filtered_calendar.filter_calendars()
    result = filtered_calendar.result
    assert isinstance(result, Calendar)
    with open(Path(CURR_DIR / "data" / "ics" /
                   "02-04_05-05-2020_urlab.ics")) as in_f:
        expected_cal = Calendar(in_f.read())
    assert result.events == expected_cal.events
Exemplo n.º 5
0
def test_calendar_filter_with_no_end_date():
    date_format = "%Y-%m-%d"
    cal = CalendarFilter(input_file="foo",
                         start_date="2020-01-01",
                         end_date=None)
    expected_end_date = arrow.now().strftime(date_format)
    assert cal.end_date.strftime(date_format) == expected_end_date
Exemplo n.º 6
0
def filter_calendar(input_file, re_pattern, start_date, end_date,
                    output_format, output_file):
    """
    Filter ics-format calendar
    """
    from calh.filter import CalendarFilter

    with click_spinner.spinner():
        CalendarFilter.filter(
            input_file=input_file,
            re_pattern=re_pattern,
            start_date=start_date,
            end_date=end_date,
            output_format=output_format,
            output_file=output_file,
        )

    click.echo(f"Your filtered calendar is ready: {output_file}")
Exemplo n.º 7
0
def test_calendar_filter_with_no_start_date():
    with pytest.raises(ValueError) as e:
        cal = CalendarFilter(input_file="foo",
                             start_date=None,
                             end_date="2020-01-01")
    assert 'start_date is required' in str(e)