Beispiel #1
0
 def test_complex_rule_serialization_with_weekday_instance(self):
     rule = recurrence.Rule(
         recurrence.WEEKLY,
         interval=17,
         wkst=recurrence.to_weekday(1),
         count=7,
         byday=[recurrence.to_weekday('-1MO'),
                recurrence.to_weekday('TU')],
         bymonth=[1, 3])
     vrecurr = utils.build_rrule_from_recurrences_rrule(rule)
     assert vRecur(vrecurr).to_ical().decode(
     ) == 'FREQ=WEEKLY;COUNT=7;INTERVAL=17;BYDAY=-1MO,TU;BYMONTH=1,3;WKST=TU'
def test_complex_rule_serialization_with_weekday_instance():
    rule = Rule(
        recurrence.WEEKLY,
        interval=17,
        wkst=recurrence.to_weekday(1),
        count=7,
        byday=[recurrence.to_weekday('-1MO'),
               recurrence.to_weekday('TU')],
        bymonth=[1, 3])

    serialized = recurrence.serialize(rule)
    assert ('RRULE:FREQ=WEEKLY;INTERVAL=17;WKST=TU;'
            'COUNT=7;BYDAY=-1MO,TU;BYMONTH=1,3') == serialized
    assert recurrence.deserialize(serialized) == Recurrence(rrules=[rule])
 def test_complex_rule_serialization_with_weekday_instance(self):
     rule = recurrence.Rule(
         recurrence.WEEKLY,
         interval=17,
         wkst=recurrence.to_weekday(1),
         count=7,
         byday=[
             recurrence.to_weekday('-1MO'),
             recurrence.to_weekday('TU')
         ],
         bymonth=[1, 3]
     )
     vrecurr = utils.build_rrule_from_recurrences_rrule(rule)
     assert vRecur(vrecurr).to_ical(
     ).decode() == 'FREQ=WEEKLY;COUNT=7;INTERVAL=17;BYDAY=-1MO,TU;BYMONTH=1,3;WKST=TU'
 def test_complex_rule_serialization(self):
     rule = recurrence.Rule(
         recurrence.WEEKLY,
         interval=17,
         wkst=1,
         count=7,
         byday=[recurrence.to_weekday("-1MO"),
                recurrence.to_weekday("TU")],
         bymonth=[1, 3],
     )
     vrecurr = utils.build_rrule_from_recurrences_rrule(rule)
     assert (
         vRecur(vrecurr).to_ical().decode() ==
         "FREQ=WEEKLY;COUNT=7;INTERVAL=17;BYDAY=-1MO,TU;BYMONTH=1,3;WKST=TU"
     )
Beispiel #5
0
    def create_from_rule_object(self, mode, rule_obj, recurrence_model):
        until = rule_obj.until
        if until:
            if until.tzinfo:
                until = until.tzinfo.astimezone(pytz.utc)
            else:
                until = pytz.utc.localize(until)

        rule_model = self.create(recurrence=recurrence_model,
                                 mode=mode,
                                 freq=rule_obj.freq,
                                 interval=rule_obj.interval,
                                 wkst=rule_obj.wkst,
                                 count=rule_obj.count,
                                 until=until)

        for param in recurrence.Rule.byparams:
            value_list = getattr(rule_obj, param, None)
            if not value_list:
                continue
            if not hasattr(value_list, '__iter__'):
                value_list = [value_list]
            for value in value_list:
                if param == 'byday':
                    # see recurrence.base docstrings about byday handling
                    weekday = recurrence.to_weekday(value)
                    rule_model.params.create(param=param,
                                             value=weekday.number,
                                             index=weekday.index)
                else:
                    rule_model.params.create(param=param, value=value)

        return rule_model
Beispiel #6
0
    def create_from_rule_object(self, mode, rule_obj, recurrence_model):
        until = rule_obj.until
        if until:
            if until.tzinfo:
                until = until.tzinfo.astimezone(pytz.utc)
            else:
                until = pytz.utc.localize(until)

        rule_model = self.create(
            recurrence=recurrence_model, mode=mode,
            freq=rule_obj.freq, interval=rule_obj.interval, wkst=rule_obj.wkst,
            count=rule_obj.count, until=until)

        for param in recurrence.Rule.byparams:
            value_list = getattr(rule_obj, param, None)
            if not value_list:
                continue
            if not hasattr(value_list, '__iter__'):
                value_list = [value_list]
            for value in value_list:
                if param == 'byday':
                    # see recurrence.base docstrings about byday handling
                    weekday = recurrence.to_weekday(value)
                    rule_model.params.create(
                        param=param, value=weekday.number, index=weekday.index)
                else:
                    rule_model.params.create(param=param, value=value)

        return rule_model
def test_complex_rule_serialization_with_weekday_instance():
    rule = Rule(
        recurrence.WEEKLY,
        interval=17,
        wkst=recurrence.to_weekday(1),
        count=7,
        byday=[
            recurrence.to_weekday('-1MO'),
            recurrence.to_weekday('TU')
        ],
        bymonth=[1, 3]
    )

    serialized = recurrence.serialize(rule)
    assert ('RRULE:FREQ=WEEKLY;INTERVAL=17;WKST=TU;'
            'COUNT=7;BYDAY=-1MO,TU;BYMONTH=1,3') == serialized
    assert recurrence.deserialize(serialized) == Recurrence(rrules=[rule])
def test_to_weekday_from_weekday():
    day = recurrence.Weekday(4)

    assert recurrence.to_weekday(day) == day
def test_to_weekday_from_string():
    assert recurrence.to_weekday("3") == recurrence.Weekday(3)

    with pytest.raises(ValueError):
        recurrence.to_weekday("7")

    assert recurrence.to_weekday("MO") == recurrence.Weekday(0)
    assert recurrence.to_weekday("mo") == recurrence.Weekday(0)
    assert recurrence.to_weekday("TU") == recurrence.Weekday(1)
    assert recurrence.to_weekday("Tu") == recurrence.Weekday(1)

    with pytest.raises(ValueError):
        recurrence.to_weekday("FOO")

    assert recurrence.to_weekday("-2TU") == recurrence.Weekday(1, -2)

    # We don't do any validation of the index
    assert recurrence.to_weekday("-7SU") == recurrence.Weekday(6, -7)
def test_to_weekday_from_nonelike():
    with pytest.raises(ValueError):
        recurrence.to_weekday(None)

    with pytest.raises(ValueError):
        recurrence.to_weekday("")
def test_to_weekday_from_int():
    assert recurrence.to_weekday(1) == recurrence.Weekday(1)

    with pytest.raises(ValueError):
        recurrence.to_weekday(7)
def test_to_weekday_from_dateutil_weekday():
    day = weekday(1)

    assert recurrence.to_weekday(day) == recurrence.Weekday(1)