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()
def runTest(self): "Test period field options - unique types (sequenced, current and nonsequenced)" period = Period(lower=datetime.datetime(1996,10,1), upper=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)' with _fail_atomic(): i.save() # Test current unique. i.valid_time = '[1996-05-01 00:00:00.000000+0000,9999-12-30 00:00:00.000000+0000)' with _fail_atomic(): i.save() # Test nonsequenced unique. i1 = CategoryToo(cat=120033, valid_time=period) i1.save() i2 = CategoryToo(cat=120033, valid_time=period) with _fail_atomic(): i2.save() i2.cat = 100100 # Saves okay. i2.save() i1.delete() i2.delete()
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()