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


Python Category.valid_time方法代码示例

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


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

示例1: runTest

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import valid_time [as 别名]
 def runTest(self):
     period = Period(lower=datetime.datetime(1996,10,1), upper=datetime.datetime(1997,1,1))
     i = Category(cat=120033, valid_time=period)
     i.save()
     
     for bad in [5, 2.0, 'foo', (10, 20)]:
         try:
             i.valid_time = bad
         except TypeError:
             pass
         else:
             self.fail('Should throw a TypeError')
     
     newstr = '[1996-01-01 00:00:00.000000+0000,1996-06-01 00:00:00.000000+0000)'
     new = Period(newstr)
     
     for good in (new, newstr):
         i.valid_time = good
     
     self.assertEqual(i.valid_time, new)
     i.save()
     self.assertNotEqual(i.pk, None)
     self.assertEqual(new, Category.objects.get(pk=i.pk).valid_time)
     
     i.delete()
开发者ID:zejn,项目名称:django_temporal,代码行数:27,代码来源:tests.py

示例2: runTest

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import valid_time [as 别名]
 def runTest(self):
     "Test period field options - unique types (sequenced, current and nonsequenced)"
     period = Period(start=datetime.datetime(1996,10,1), end=datetime.datetime(1997,1,1))
     i = Category(cat=120033, valid_time=period)
     
     # Test overlapping periods - sequenced unique.
     i.valid_time = '[1996-05-01 00:00:00.000000+0000,1996-07-01 00:00:00.000000+0000)'
     try:
         i.save()
     except IntegrityError:
         connection.connection.rollback()
     else:
         self.fail('Should throw an IntegrityError')
     
     # Test current unique.
     i.valid_time = '[1996-05-01 00:00:00.000000+0000,9999-12-31 23:59:59.999999+0000)'
     try:
         i.save()
     except IntegrityError:
         connection.connection.rollback()
     else:
         self.fail('Should throw an IntegrityError')
     
     # Test nonsequenced unique.
     i1 = CategoryToo(cat=120033, valid_time=period)
     i1.save()
     
     i2 = CategoryToo(cat=120033, valid_time=period)
     try:
         i2.save()
     except IntegrityError:
         connection.connection.rollback()
     else:
         self.fail('Should throw and IntegrityError')
     
     i2.cat = 100100
     # Saves okay.
     i2.save()
     
     i1.delete()
     i2.delete()
开发者ID:aarcro,项目名称:django_temporal,代码行数:43,代码来源:tests.py


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