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)
class AnalysisModuleResource(FootprintResource): config_entity = ToOneField( 'footprint.main.resources.config_entity_resources.ConfigEntityResource', attribute='config_entity', full=False, null=False, readonly=True) analysis_tools = ToManyField(AnalysisToolResource, attribute='analysis_tools') started = DateField(readonly=True) completed = DateField(readonly=True) failed = DateField(readonly=True) class Meta(FootprintResource.Meta): always_return_data = True, excludes = ('creator', 'updater') filtering = {"config_entity": ALL_WITH_RELATIONS} queryset = AnalysisModule.objects.all() resource_name = 'analysis_module' def hydrate(self, bundle): if not bundle.obj.id: bundle.obj.creator = self.resolve_user(bundle.request.GET) bundle.obj.updater = self.resolve_user(bundle.request.GET) return bundle
def test_dehydrate(self): note = Note.objects.get(pk=1) bundle = Bundle(obj=note) field_1 = DateField(attribute='created') self.assertEqual(field_1.dehydrate(bundle), aware_datetime(2010, 3, 30, 20, 5)) field_2 = DateField(default=datetime.date(2010, 4, 1)) self.assertEqual(field_2.dehydrate(bundle), datetime.date(2010, 4, 1)) note.created_string = '2010-04-02' field_3 = DateField(attribute='created_string') self.assertEqual(field_3.dehydrate(bundle), datetime.date(2010, 4, 2))
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)