当前位置: 首页>>代码示例>>Python>>正文


Python Period.has_occurrences方法代码示例

本文整理汇总了Python中schedule.periods.Period.has_occurrences方法的典型用法代码示例。如果您正苦于以下问题:Python Period.has_occurrences方法的具体用法?Python Period.has_occurrences怎么用?Python Period.has_occurrences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在schedule.periods.Period的用法示例。


在下文中一共展示了Period.has_occurrences方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_moved_occurrences

# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import has_occurrences [as 别名]
 def test_moved_occurrences(self):
     occurrences = self.recurring_event.get_occurrences(start=self.start,
                                 end=self.end)
     moved_occurrence = occurrences[1]
     span_pre = (moved_occurrence.start, moved_occurrence.end)
     span_post = [x + datetime.timedelta(hours=2) for x in span_pre]
     # check has_occurrence on both periods
     period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
     period_post = Period([self.recurring_event], span_post[0], span_post[1])
     self.assertTrue(period_pre.has_occurrences())
     self.assertFalse(period_post.has_occurrences())
     # move occurrence
     moved_occurrence.move(moved_occurrence.start+datetime.timedelta(hours=2),
                           moved_occurrence.end+datetime.timedelta(hours=2))
     occurrences = self.recurring_event.get_occurrences(start=self.start,
                                 end=self.end)
     self.assertTrue(occurrences[1].moved)
     # check has_occurrence on both periods (the result should be reversed)
     period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
     period_post = Period([self.recurring_event], span_post[0], span_post[1])
     self.assertFalse(period_pre.has_occurrences())
     self.assertTrue(period_post.has_occurrences())
     # trigger bug discovered by gautamadude - modifying recurring event
     # breaks link between a persistent occurrence and the occurrence chain
     # leaving an "orphaned" occurrence
     occurrences = self.recurring_event.get_occurrences(start=self.start,
                                 end=self.end)
     self.assertTrue(len(occurrences) == 3)
     self.recurring_event.start = datetime.datetime(2008, 1, 5, 8, 15)
     self.recurring_event.save()
     occurrences_later = self.recurring_event.get_occurrences(start=self.start,
                                 end=self.end)
     self.assertEquals(len(occurrences_later), len(occurrences))
开发者ID:ATOM49,项目名称:django-voip,代码行数:35,代码来源:test_models.py

示例2: TestPeriod

# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import has_occurrences [as 别名]
class TestPeriod(TestCase):
    def setUp(self):
        rule = Rule.objects.create(frequency="WEEKLY")
        cal = Calendar.objects.create(name="MyCal")
        data = {
            'title': 'Recent Event',
            'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
            'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
            'rule': rule,
            'calendar': cal,
        }
        Event.objects.create(**data)
        self.period = Period(
            events=Event.objects.all(),
            start=datetime.datetime(2008, 1, 4, 7, 0, tzinfo=pytz.utc),
            end=datetime.datetime(2008, 1, 21, 7, 0, tzinfo=pytz.utc))

    def test_get_occurrences(self):
        occurrence_list = self.period.occurrences
        self.assertEqual(
            ["%s to %s" % (o.start, o.end) for o in occurrence_list],
            [
                '2008-01-05 08:00:00+00:00 to 2008-01-05 09:00:00+00:00',
                '2008-01-12 08:00:00+00:00 to 2008-01-12 09:00:00+00:00',
                '2008-01-19 08:00:00+00:00 to 2008-01-19 09:00:00+00:00',
            ]
        )

    def test_get_occurrence_partials(self):
        occurrence_dicts = self.period.get_occurrence_partials()
        self.assertEqual(
            [
                (occ_dict["class"], occ_dict["occurrence"].start, occ_dict["occurrence"].end)
                for occ_dict in occurrence_dicts
            ],
            [
                (1,
                 datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
                 datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc)),
                (1,
                 datetime.datetime(2008, 1, 12, 8, 0, tzinfo=pytz.utc),
                 datetime.datetime(2008, 1, 12, 9, 0, tzinfo=pytz.utc)),
                (1,
                 datetime.datetime(2008, 1, 19, 8, 0, tzinfo=pytz.utc),
                 datetime.datetime(2008, 1, 19, 9, 0, tzinfo=pytz.utc))
            ])

    def test_has_occurrence(self):
        self.assertTrue(self.period.has_occurrences())
        slot = self.period.get_time_slot(
            datetime.datetime(2008, 1, 4, 7, 0, tzinfo=pytz.utc),
            datetime.datetime(2008, 1, 4, 7, 12, tzinfo=pytz.utc))
        self.assertFalse(slot.has_occurrences())
开发者ID:drodger,项目名称:django-scheduler,代码行数:56,代码来源:test_periods.py

示例3: test_moved_occurrences

# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import has_occurrences [as 别名]
 def test_moved_occurrences(self):
     occurrences = self.recurring_event.get_occurrences(start=self.start, end=self.end)
     moved_occurrence = occurrences[1]
     span_pre = (moved_occurrence.start, moved_occurrence.end)
     span_post = [x + datetime.timedelta(hours=2) for x in span_pre]
     # check has_occurrence on both periods
     period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
     period_post = Period([self.recurring_event], span_post[0], span_post[1])
     self.assertTrue(period_pre.has_occurrences())
     self.assertFalse(period_post.has_occurrences())
     # move occurrence
     moved_occurrence.move(moved_occurrence.start + datetime.timedelta(hours=2),
                           moved_occurrence.end + datetime.timedelta(hours=2))
     occurrences = self.recurring_event.get_occurrences(start=self.start, end=self.end)
     self.assertTrue(occurrences[1].moved)
     # check has_occurrence on both periods (the result should be reversed)
     period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
     period_post = Period([self.recurring_event], span_post[0], span_post[1])
     self.assertFalse(period_pre.has_occurrences())
     self.assertTrue(period_post.has_occurrences())
开发者ID:jrutila,项目名称:django-schedule,代码行数:22,代码来源:test_occurrence.py

示例4: TestPeriod

# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import has_occurrences [as 别名]
class TestPeriod(TestCase):
    def setUp(self):
        rule = Rule(frequency="WEEKLY")
        rule.save()
        cal = Calendar(name="MyCal")
        cal.save()
        data = {
            'title': 'Recent Event',
            'start': datetime.datetime(2008, 1, 5, 8, 0),
            'end': datetime.datetime(2008, 1, 5, 9, 0),
            'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
            'rule': rule,
            'calendar': cal
        }
        recurring_event = Event(**data)
        recurring_event.save()
        self.period = Period(events=Event.objects.all(),
                             start=datetime.datetime(2008, 1, 4, 7, 0),
                             end=datetime.datetime(2008, 1, 21, 7, 0))

    def test_get_occurrences(self):
        occurrence_list = self.period.occurrences
        expected = [
            '2008-01-05 08:00:00 to 2008-01-05 09:00:00',
            '2008-01-12 08:00:00 to 2008-01-12 09:00:00',
            '2008-01-19 08:00:00 to 2008-01-19 09:00:00',
        ]
        self.assertEqual(["%s to %s" % (o.start, o.end) for o in occurrence_list], expected)

    def test_get_occurrence_partials(self):
        occurrence_dicts = self.period.get_occurrence_partials()
        self.assertEqual(
            [(occ_dict["class"],
            occ_dict["occurrence"].start,
            occ_dict["occurrence"].end)
            for occ_dict in occurrence_dicts],
            [
                (1,
                 datetime.datetime(2008, 1, 5, 8, 0),
                 datetime.datetime(2008, 1, 5, 9, 0)),
                (1,
                 datetime.datetime(2008, 1, 12, 8, 0),
                 datetime.datetime(2008, 1, 12, 9, 0)),
                (1,
                 datetime.datetime(2008, 1, 19, 8, 0),
                 datetime.datetime(2008, 1, 19, 9, 0))
            ])

    def test_has_occurrence(self):
        self.assert_(self.period.has_occurrences())
        slot = self.period.get_time_slot(datetime.datetime(2008, 1, 4, 7, 0),
                                         datetime.datetime(2008, 1, 4, 7, 12))
        self.failIf(slot.has_occurrences())
开发者ID:macanhhuy,项目名称:django-schedule,代码行数:55,代码来源:test_periods.py

示例5: TestPeriod

# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import has_occurrences [as 别名]
class TestPeriod(TestCase):
    def setUp(self):
        rule = Rule(frequency="WEEKLY")
        rule.save()
        cal = Room(name="MyCal")
        cal.save()
        data = {
            "title": "Recent Reservation",
            "start": datetime.datetime(2008, 1, 5, 8, 0),
            "end": datetime.datetime(2008, 1, 5, 9, 0),
            "end_recurring_period": datetime.datetime(2008, 5, 5, 0, 0),
            "rule": rule,
            "room": cal,
        }
        recurring_reservation = Reservation(**data)
        recurring_reservation.save()
        self.period = Period(
            reservations=Reservation.objects.all(),
            start=datetime.datetime(2008, 1, 4, 7, 0),
            end=datetime.datetime(2008, 1, 21, 7, 0),
        )

    def test_get_occurrences(self):
        occurrence_list = self.period.occurrences
        self.assertEqual(
            ["%s to %s" % (o.start, o.end) for o in occurrence_list],
            [
                "2008-01-05 08:00:00 to 2008-01-05 09:00:00",
                "2008-01-12 08:00:00 to 2008-01-12 09:00:00",
                "2008-01-19 08:00:00 to 2008-01-19 09:00:00",
            ],
        )

    def test_get_occurrence_partials(self):
        occurrence_dicts = self.period.get_occurrence_partials()
        self.assertEqual(
            [
                (occ_dict["class"], occ_dict["occurrence"].start, occ_dict["occurrence"].end)
                for occ_dict in occurrence_dicts
            ],
            [
                (1, datetime.datetime(2008, 1, 5, 8, 0), datetime.datetime(2008, 1, 5, 9, 0)),
                (1, datetime.datetime(2008, 1, 12, 8, 0), datetime.datetime(2008, 1, 12, 9, 0)),
                (1, datetime.datetime(2008, 1, 19, 8, 0), datetime.datetime(2008, 1, 19, 9, 0)),
            ],
        )

    def test_has_occurrence(self):
        self.assert_(self.period.has_occurrences())
        slot = self.period.get_time_slot(datetime.datetime(2008, 1, 4, 7, 0), datetime.datetime(2008, 1, 4, 7, 12))
        self.failIf(slot.has_occurrences())
开发者ID:bjdag1234,项目名称:django-schedule-rooms,代码行数:53,代码来源:test_periods.py


注:本文中的schedule.periods.Period.has_occurrences方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。