def _to_dict(self): """Return a json dictionary representing this model.""" _dict = {} if hasattr(self, 'name') and self.name is not None: _dict['name'] = self.name if hasattr(self, 'crn') and self.crn is not None: _dict['crn'] = self.crn if hasattr(self, 'service_instance_id' ) and self.service_instance_id is not None: _dict['service_instance_id'] = self.service_instance_id if hasattr(self, 'service_instance_crn' ) and self.service_instance_crn is not None: _dict['service_instance_crn'] = self.service_instance_crn if hasattr(self, 'time_created') and self.time_created is not None: _dict['time_created'] = datetime_to_string(self.time_created) if hasattr(self, 'time_updated') and self.time_updated is not None: _dict['time_updated'] = datetime_to_string(self.time_updated) if hasattr(self, 'object_count') and self.object_count is not None: _dict['object_count'] = self.object_count if hasattr(self, 'bytes_used') and self.bytes_used is not None: _dict['bytes_used'] = self.bytes_used if hasattr(self, 'firewall') and self.firewall is not None: _dict['firewall'] = self.firewall._to_dict() if hasattr(self, 'activity_tracking') and self.activity_tracking is not None: _dict['activity_tracking'] = self.activity_tracking._to_dict() return _dict
def test_datetime_to_string(): # If specified date is None, return None assert datetime_to_string(None) is None # If the specified date is "naive", it is interpreted as a UTC date date = datetime.datetime(2017, 3, 6, 16, 0, 4, 159338) res = datetime_to_string(date) assert res == '2017-03-06T16:00:04.159338Z' # Test date with UTC timezone date = datetime.datetime(2017, 3, 6, 16, 0, 4, 159338, datetime.timezone.utc) res = datetime_to_string(date) assert res == '2017-03-06T16:00:04.159338Z' # Test date with non-UTC timezone tzn = datetime.timezone(datetime.timedelta(hours=-6)) date = datetime.datetime(2017, 3, 6, 10, 0, 4, 159338, tzn) res = datetime_to_string(date) assert res == '2017-03-06T16:00:04.159338Z'
def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} if hasattr(self, 'name') and self.name is not None: _dict['name'] = self.name if hasattr(self, 'url') and self.url is not None: _dict['url'] = self.url if hasattr(self, 'status') and self.status is not None: _dict['status'] = self.status if hasattr(self, 'classifier_id') and self.classifier_id is not None: _dict['classifier_id'] = self.classifier_id if hasattr(self, 'created') and self.created is not None: _dict['created'] = datetime_to_string(self.created) if hasattr( self, 'status_description') and self.status_description is not None: _dict['status_description'] = self.status_description if hasattr(self, 'language') and self.language is not None: _dict['language'] = self.language return _dict
def datetime_test(datestr: str, expected: str): dt_value = string_to_datetime(datestr) assert dt_value is not None actual = datetime_to_string(dt_value) assert actual == expected
def test_datetime_conversion(): date = string_to_datetime('2017-03-06 16:00:04.159338') assert date.day == 6 res = datetime_to_string(date) assert res == '2017-03-06T16:00:04.159338'