本文整理汇总了Python中subscription_manager.validity.ValidProductDateRangeCalculator._get_entitlements_spanning_now方法的典型用法代码示例。如果您正苦于以下问题:Python ValidProductDateRangeCalculator._get_entitlements_spanning_now方法的具体用法?Python ValidProductDateRangeCalculator._get_entitlements_spanning_now怎么用?Python ValidProductDateRangeCalculator._get_entitlements_spanning_now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subscription_manager.validity.ValidProductDateRangeCalculator
的用法示例。
在下文中一共展示了ValidProductDateRangeCalculator._get_entitlements_spanning_now方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_range_grouping_overlapping_today
# 需要导入模块: from subscription_manager.validity import ValidProductDateRangeCalculator [as 别名]
# 或者: from subscription_manager.validity.ValidProductDateRangeCalculator import _get_entitlements_spanning_now [as 别名]
def test_get_range_grouping_overlapping_today(self):
start1 = self.NOW - (self.YEAR * 3)
end1 = start1 + self.THREE_MONTHS
# Gap b/w 1 and 2
start2 = end1 + self.THREE_MONTHS
end2 = start2 + self.ONE_MONTH
start3 = start2
end3 = end2
# Gap b/w 3 and 4
start4 = end3 + self.YEAR
end4 = start4 + self.THREE_MONTHS
start5 = end4 - self.ONE_MONTH
end5 = start5 + self.THREE_MONTHS
start6 = end5 - self.TEN_DAYS
end6 = self.NOW + self.THREE_MONTHS
# 6 will cover 7 completely
start7 = start6 + self.TEN_DAYS
end7 = start7 + self.TEN_DAYS
# 8 is completely covered by 6, but creates a gap b/w 7.
start8 = self.NOW + self.ONE_MONTH
end8 = start8 + self.TEN_DAYS
# Gap here.
start9 = end8 + self.YEAR
end9 = start9 + self.ONE_MONTH
ent_dates = [
(start1, end1),
(start2, end2),
(start3, end3),
(start4, end4),
(start5, end5),
(start6, end6),
(start7, end7),
(start8, end8),
(start9, end9)
]
expected_dates = [
(start4.replace(tzinfo=GMT()), end4.replace(tzinfo=GMT())),
(start5.replace(tzinfo=GMT()), end5.replace(tzinfo=GMT())),
(start6.replace(tzinfo=GMT()), end6.replace(tzinfo=GMT())),
(start7.replace(tzinfo=GMT()), end7.replace(tzinfo=GMT())),
(start8.replace(tzinfo=GMT()), end8.replace(tzinfo=GMT()))
]
installed = create_prod_cert(self.INST_PID_1)
ents = [self._create_entitlement(self.INST_PID_1, start, end) \
for start, end in ent_dates]
sorter = create_cert_sorter([installed], ents)
calculator = ValidProductDateRangeCalculator(sorter)
group = calculator._get_entitlements_spanning_now(ents)
self.assertTrue(group)
self.assertEqual(len(expected_dates), len(group))
for ent in group:
ent_range = ent.valid_range
check = (ent_range.begin(), ent_range.end())
self.assertTrue(check in expected_dates)