def test_hydrate(self): # note = Note.objects.get(pk=1) bundle_1 = Bundle(data={ 'date': '2010-05-12', }) field_1 = DateField(attribute='created') field_1.instance_name = 'date' self.assertEqual(field_1.hydrate(bundle_1), datetime.date(2010, 5, 12)) bundle_2 = Bundle() field_2 = DateField(default=datetime.date(2010, 4, 1)) field_2.instance_name = 'date' self.assertEqual(field_2.hydrate(bundle_2), datetime.date(2010, 4, 1)) bundle_3 = Bundle(data={ 'date': 'Wednesday, May 12, 2010', }) field_3 = DateField(attribute='created_string') field_3.instance_name = 'date' self.assertEqual(field_3.hydrate(bundle_3), datetime.date(2010, 5, 12)) bundle_4 = Bundle(data={ 'date': '5 Apr 2010', }) field_4 = DateField(attribute='created') field_4.instance_name = 'date' self.assertEqual(field_4.hydrate(bundle_4), datetime.date(2010, 4, 5)) bundle_5 = Bundle(data={ 'date': None, }) field_5 = DateField(attribute='created', null=True) field_5.instance_name = 'date' self.assertEqual(field_5.hydrate(bundle_5), None)
def test_hydrate(self): # note = Note.objects.get(pk=1) bundle_1 = Bundle(data={ 'datetime': '2010-05-12 10:36:28', }) field_1 = DateTimeField(attribute='created') field_1.instance_name = 'datetime' self.assertEqual(field_1.hydrate(bundle_1), aware_datetime(2010, 5, 12, 10, 36, 28)) bundle_2 = Bundle() field_2 = DateTimeField(default=aware_datetime(2010, 4, 1, 2, 0)) field_2.instance_name = 'datetime' self.assertEqual(field_2.hydrate(bundle_2), aware_datetime(2010, 4, 1, 2, 0)) bundle_3 = Bundle(data={ 'datetime': 'Tue, 30 Mar 2010 20:05:00 -0500', }) field_3 = DateTimeField(attribute='created_string') field_3.instance_name = 'datetime' self.assertEqual(field_3.hydrate(bundle_3), aware_datetime(2010, 3, 30, 20, 5, tzinfo=tzoffset(None, -18000))) bundle_4 = Bundle(data={ 'datetime': None, }) field_4 = DateField(attribute='created', null=True) field_4.instance_name = 'datetime' self.assertEqual(field_4.hydrate(bundle_4), None)