Python iso8601.UTC Examples
The following are 30
code examples of iso8601.UTC().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
iso8601
, or try the search function
.
Example #1
Source File: test_goal.py From watcher with Apache License 2.0 | 6 votes |
def test_soft_delete(self, mock_get_goal, mock_soft_delete_goal): mock_get_goal.return_value = self.fake_goal fake_deleted_goal = self.fake_goal.copy() fake_deleted_goal['deleted_at'] = datetime.datetime.utcnow() mock_soft_delete_goal.return_value = fake_deleted_goal expected_goal = fake_deleted_goal.copy() expected_goal['created_at'] = expected_goal['created_at'].replace( tzinfo=iso8601.UTC) expected_goal['deleted_at'] = expected_goal['deleted_at'].replace( tzinfo=iso8601.UTC) uuid = self.fake_goal['uuid'] goal = objects.Goal.get_by_uuid(self.context, uuid) goal.soft_delete() mock_get_goal.assert_called_once_with(self.context, uuid) mock_soft_delete_goal.assert_called_once_with(uuid) self.assertEqual(self.context, goal._context) self.assertEqual(expected_goal, goal.as_dict())
Example #2
Source File: test_audit_template.py From watcher with Apache License 2.0 | 6 votes |
def test_soft_delete(self, m_get_audit_template, m_soft_delete_audit_template): m_get_audit_template.return_value = self.fake_audit_template fake_deleted_audit_template = self.fake_audit_template.copy() fake_deleted_audit_template['deleted_at'] = datetime.datetime.utcnow() m_soft_delete_audit_template.return_value = fake_deleted_audit_template expected_audit_template = fake_deleted_audit_template.copy() expected_audit_template['created_at'] = expected_audit_template[ 'created_at'].replace(tzinfo=iso8601.UTC) expected_audit_template['deleted_at'] = expected_audit_template[ 'deleted_at'].replace(tzinfo=iso8601.UTC) del expected_audit_template['goal'] del expected_audit_template['strategy'] uuid = self.fake_audit_template['uuid'] audit_template = objects.AuditTemplate.get_by_uuid(self.context, uuid) audit_template.soft_delete() m_get_audit_template.assert_called_once_with( self.context, uuid, eager=False) m_soft_delete_audit_template.assert_called_once_with(uuid) self.assertEqual(self.context, audit_template._context) self.assertEqual(expected_audit_template, audit_template.as_dict())
Example #3
Source File: test_scoring_engine.py From watcher with Apache License 2.0 | 6 votes |
def test_soft_delete(self, mock_get_scoring_engine, mock_soft_delete): mock_get_scoring_engine.return_value = self.fake_scoring_engine fake_deleted_scoring_engine = self.fake_scoring_engine.copy() fake_deleted_scoring_engine['deleted_at'] = datetime.datetime.utcnow() mock_soft_delete.return_value = fake_deleted_scoring_engine expected_scoring_engine = fake_deleted_scoring_engine.copy() expected_scoring_engine['created_at'] = expected_scoring_engine[ 'created_at'].replace(tzinfo=iso8601.UTC) expected_scoring_engine['deleted_at'] = expected_scoring_engine[ 'deleted_at'].replace(tzinfo=iso8601.UTC) _id = self.fake_scoring_engine['id'] scoring_engine = objects.ScoringEngine.get_by_id(self.context, _id) scoring_engine.soft_delete() mock_get_scoring_engine.assert_called_once_with(self.context, _id) mock_soft_delete.assert_called_once_with(_id) self.assertEqual(self.context, scoring_engine._context) self.assertEqual(expected_scoring_engine, scoring_engine.as_dict())
Example #4
Source File: test_objects.py From watcher with Apache License 2.0 | 6 votes |
def test_base_attributes(self): dt = datetime.datetime(1955, 11, 5, 0, 0, tzinfo=iso8601.UTC) datatime = fields.DateTimeField() obj = MyObj(self.context) obj.created_at = dt obj.updated_at = dt expected = {'watcher_object.name': 'MyObj', 'watcher_object.namespace': 'watcher', 'watcher_object.version': '1.5', 'watcher_object.changes': ['created_at', 'updated_at'], 'watcher_object.data': {'created_at': datatime.stringify(dt), 'updated_at': datatime.stringify(dt), } } actual = obj.obj_to_primitive() # watcher_object.changes is built from a set and order is undefined self.assertEqual(sorted(expected['watcher_object.changes']), sorted(actual['watcher_object.changes'])) del expected[ 'watcher_object.changes'], actual['watcher_object.changes'] self.assertEqual(expected, actual)
Example #5
Source File: test_service.py From watcher with Apache License 2.0 | 6 votes |
def test_soft_delete(self, mock_get_service, mock_soft_delete): mock_get_service.return_value = self.fake_service fake_deleted_service = self.fake_service.copy() fake_deleted_service['deleted_at'] = datetime.datetime.utcnow() mock_soft_delete.return_value = fake_deleted_service expected_service = fake_deleted_service.copy() expected_service['created_at'] = expected_service[ 'created_at'].replace(tzinfo=iso8601.UTC) expected_service['deleted_at'] = expected_service[ 'deleted_at'].replace(tzinfo=iso8601.UTC) _id = self.fake_service['id'] service = objects.Service.get(self.context, _id) service.soft_delete() mock_get_service.assert_called_once_with(self.context, _id) mock_soft_delete.assert_called_once_with(_id) self.assertEqual(self.context, service._context) self.assertEqual(expected_service, service.as_dict())
Example #6
Source File: test_action_description.py From watcher with Apache License 2.0 | 6 votes |
def test_soft_delete(self, mock_get_action_desc, mock_soft_delete): mock_get_action_desc.return_value = self.fake_action_desc fake_deleted_action_desc = self.fake_action_desc.copy() fake_deleted_action_desc['deleted_at'] = datetime.datetime.utcnow() mock_soft_delete.return_value = fake_deleted_action_desc expected_action_desc = fake_deleted_action_desc.copy() expected_action_desc['created_at'] = expected_action_desc[ 'created_at'].replace(tzinfo=iso8601.UTC) expected_action_desc['deleted_at'] = expected_action_desc[ 'deleted_at'].replace(tzinfo=iso8601.UTC) _id = self.fake_action_desc['id'] action_desc = objects.ActionDescription.get(self.context, _id) action_desc.soft_delete() mock_get_action_desc.assert_called_once_with(self.context, _id) mock_soft_delete.assert_called_once_with(_id) self.assertEqual(self.context, action_desc._context) self.assertEqual(expected_action_desc, action_desc.as_dict())
Example #7
Source File: test_audit.py From watcher with Apache License 2.0 | 6 votes |
def test_soft_delete(self, mock_get_audit, mock_soft_delete_audit, mock_update_audit): mock_get_audit.return_value = self.fake_audit fake_deleted_audit = self.fake_audit.copy() fake_deleted_audit['deleted_at'] = datetime.datetime.utcnow() mock_soft_delete_audit.return_value = fake_deleted_audit mock_update_audit.return_value = fake_deleted_audit expected_audit = fake_deleted_audit.copy() expected_audit['created_at'] = expected_audit['created_at'].replace( tzinfo=iso8601.UTC) expected_audit['deleted_at'] = expected_audit['deleted_at'].replace( tzinfo=iso8601.UTC) del expected_audit['goal'] del expected_audit['strategy'] uuid = self.fake_audit['uuid'] audit = objects.Audit.get_by_uuid(self.context, uuid, eager=False) audit.soft_delete() mock_get_audit.assert_called_once_with(self.context, uuid, eager=False) mock_soft_delete_audit.assert_called_once_with(uuid) mock_update_audit.assert_called_once_with(uuid, {'state': 'DELETED'}) self.assertEqual(self.context, audit._context) self.assertEqual(expected_audit, audit.as_dict())
Example #8
Source File: fakes.py From tacker with Apache License 2.0 | 6 votes |
def fake_vnf_package(**updates): vnf_package = { 'algorithm': None, 'deleted': False, 'deleted_at': None, 'updated_at': None, 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1, tzinfo=iso8601.UTC), 'hash': None, 'location_glance_store': None, 'onboarding_state': 'CREATED', 'operational_state': 'DISABLED', 'tenant_id': uuidsentinel.tenant_id, 'usage_state': 'NOT_IN_USE', 'user_data': {'abc': 'xyz'}, 'id': constants.UUID, } if updates: vnf_package.update(updates) return vnf_package
Example #9
Source File: fakes.py From tacker with Apache License 2.0 | 6 votes |
def _model_non_instantiated_vnf_instance(**updates): vnf_instance = { 'created_at': datetime.datetime(2020, 1, 1, 1, 1, 1, tzinfo=iso8601.UTC), 'deleted': False, 'deleted_at': None, 'id': uuidsentinel.vnf_instance_id, 'instantiated_vnf_info': None, 'instantiation_state': fields.VnfInstanceState.NOT_INSTANTIATED, 'updated_at': None, 'vim_connection_info': [], 'vnf_instance_description': 'Vnf instance description', 'vnf_instance_name': 'Vnf instance name', 'vnf_product_name': 'Sample VNF', 'vnf_provider': 'Vnf provider', 'vnf_software_version': '1.0', 'tenant_id': uuidsentinel.tenant_id, 'vnfd_id': uuidsentinel.vnfd_id, 'vnfd_version': '1.0'} if updates: vnf_instance.update(**updates) return vnf_instance
Example #10
Source File: fakes.py From tacker with Apache License 2.0 | 6 votes |
def fake_vnf_package_vnfd_model_dict(**updates): vnfd = { 'package_uuid': uuidsentinel.package_uuid, 'deleted': False, 'deleted_at': None, 'updated_at': None, 'created_at': datetime.datetime(2020, 1, 1, 1, 1, 1, tzinfo=iso8601.UTC), 'vnf_product_name': 'Sample VNF', 'vnf_provider': 'test vnf provider', 'vnf_software_version': '1.0', 'vnfd_id': uuidsentinel.vnfd_id, 'vnfd_version': '1.0', 'id': constants.UUID, } if updates: vnfd.update(updates) return vnfd
Example #11
Source File: fakes.py From tacker with Apache License 2.0 | 6 votes |
def fake_vnf_instance_model_dict(**updates): vnf_instance = { 'deleted': False, 'deleted_at': None, 'updated_at': None, 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1, tzinfo=iso8601.UTC), 'vnf_product_name': 'Sample VNF', 'vnf_instance_name': 'Sample VNF', 'vnf_instance_description': None, 'vnf_provider': 'test vnf provider', 'vnf_software_version': '1.0', 'vnfd_id': uuidsentinel.vnfd_id, 'vnfd_version': '1.0', 'instantiation_state': 'NOT_INSTANTIATED', 'vim_connection_info': [], 'tenant_id': '33f8dbdae36142eebf214c1869eb4e4c', 'id': constants.UUID, } if updates: vnf_instance.update(updates) return vnf_instance
Example #12
Source File: test_messages.py From manila with Apache License 2.0 | 6 votes |
def test_index_with_created_since_and_created_before(self): msg = stubs.stub_message( fakes.get_fake_uuid(), created_at=datetime.datetime(1900, 2, 1, 1, 1, 1, tzinfo=iso8601.UTC)) self.mock_object(message_api.API, 'get_all', mock.Mock( return_value=[msg])) req = fakes.HTTPRequest.blank( '/messages?created_since=1900-01-01T01:01:01&' 'created_before=1900-03-01T01:01:01', version=messages.MESSAGES_QUERY_BY_TIMESTAMP, base_url='http://localhost/v2') req.environ['manila.context'] = self.ctxt res_dict = self.controller.index(req) ex2 = self._expected_message_from_controller( msg['id'], created_at=datetime.datetime(1900, 2, 1, 1, 1, 1, tzinfo=iso8601.UTC))['message'] self.assertEqual([ex2], res_dict['messages'])
Example #13
Source File: stubs.py From manila with Apache License 2.0 | 6 votes |
def stub_message(id, **kwargs): message = { 'id': id, 'project_id': 'fake_project', 'action_id': message_field.Action.ALLOCATE_HOST[0], 'message_level': message_levels.ERROR, 'request_id': FAKE_UUID, 'resource_type': message_field.Resource.SHARE, 'resource_id': 'fake_uuid', 'updated_at': datetime.datetime(1900, 1, 1, 1, 1, 1, tzinfo=iso8601.UTC), 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1, tzinfo=iso8601.UTC), 'expires_at': datetime.datetime(1900, 1, 1, 1, 1, 1, tzinfo=iso8601.UTC), 'detail_id': message_field.Detail.NO_VALID_HOST[0], } message.update(kwargs) return message
Example #14
Source File: fields.py From oslo.versionedobjects with Apache License 2.0 | 6 votes |
def coerce(self, obj, attr, value): if isinstance(value, str): # NOTE(danms): Being tolerant of isotime strings here will help us # during our objects transition value = timeutils.parse_isotime(value) elif not isinstance(value, datetime.datetime): raise ValueError(_('A datetime.datetime is required ' 'in field %(attr)s, not a %(type)s') % {'attr': attr, 'type': type(value).__name__}) if value.utcoffset() is None and self.tzinfo_aware: # NOTE(danms): Legacy objects from sqlalchemy are stored in UTC, # but are returned without a timezone attached. # As a transitional aid, assume a tz-naive object is in UTC. value = value.replace(tzinfo=iso8601.UTC) elif not self.tzinfo_aware: value = value.replace(tzinfo=None) return value
Example #15
Source File: fakes.py From tacker with Apache License 2.0 | 6 votes |
def _fake_software_image(updates=None): software_image = { 'id': uuidsentinel.software_image_id, 'disk_format': 'qcow2', 'min_ram': 0, 'min_disk': 1, 'container_format': 'bare', 'provider': 'fake provider', 'image_path': 'fake image path', 'software_image_id': 'fake_software_image_id', 'size': 1, 'name': 'fake software image name', 'hash': 'fake software image hash', 'version': '11.22.33', 'algorithm': 'fake-algorithm', 'metadata': {'key3': 'value3', 'key4': 'value4'}, 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1, tzinfo=iso8601.UTC), } if updates: software_image.update(updates) return software_image
Example #16
Source File: test_fields.py From masakari with Apache License 2.0 | 5 votes |
def test_stringify(self): self.assertEqual( '2016-11-05T18:00:00Z', self.field.stringify( datetime.datetime(2016, 11, 5, 18, 0, 0, tzinfo=iso8601.iso8601.UTC)))
Example #17
Source File: validation.py From sndlatr with Apache License 2.0 | 5 votes |
def parse_datetime(date): """ Validates date is in iso8601 format. Returns parsed datetime in UTC as as native datetime (tzinfo=None). """ if not isinstance(date, basestring): raise Invalid('date is not a string') try: return iso8601.parse_date(date).astimezone(iso8601.UTC).replace( tzinfo=None) except: raise Invalid('date is not in iso8601 format')
Example #18
Source File: test_audit_template.py From watcher with Apache License 2.0 | 5 votes |
def test_create(self, mock_create_audit_template): goal = utils.create_test_goal() self.fake_audit_template['goal_id'] = goal.id mock_create_audit_template.return_value = self.fake_audit_template audit_template = objects.AuditTemplate( self.context, **self.fake_audit_template) audit_template.create() expected_audit_template = self.fake_audit_template.copy() expected_audit_template['created_at'] = expected_audit_template[ 'created_at'].replace(tzinfo=iso8601.UTC) mock_create_audit_template.assert_called_once_with( expected_audit_template) self.assertEqual(self.context, audit_template._context)
Example #19
Source File: test_action.py From watcher with Apache License 2.0 | 5 votes |
def test_soft_delete(self, mock_get_action, mock_soft_delete_action, mock_update_action, mock_send_update, mock_send_delete): mock_get_action.return_value = self.fake_action fake_deleted_action = self.fake_action.copy() fake_deleted_action['deleted_at'] = datetime.datetime.utcnow() mock_soft_delete_action.return_value = fake_deleted_action mock_update_action.return_value = fake_deleted_action expected_action = fake_deleted_action.copy() expected_action['created_at'] = expected_action['created_at'].replace( tzinfo=iso8601.UTC) expected_action['deleted_at'] = expected_action['deleted_at'].replace( tzinfo=iso8601.UTC) del expected_action['action_plan'] uuid = self.fake_action['uuid'] action = objects.Action.get_by_uuid(self.context, uuid) action.soft_delete() mock_get_action.assert_called_once_with( self.context, uuid, eager=False) mock_soft_delete_action.assert_called_once_with(uuid) mock_update_action.assert_called_once_with( uuid, {'state': objects.action.State.DELETED}) self.assertEqual(self.context, action._context) self.assertEqual(expected_action, action.as_dict())
Example #20
Source File: test_action.py From watcher with Apache License 2.0 | 5 votes |
def test_save(self, mock_get_action, mock_update_action, mock_get_audit, mock_get_strategy): mock_get_action.return_value = self.fake_action fake_saved_action = self.fake_action.copy() mock_get_audit.return_value = mock.PropertyMock( uuid=c_utils.generate_uuid()) mock_get_strategy.return_value = mock.PropertyMock( uuid=c_utils.generate_uuid()) fake_saved_action['updated_at'] = datetime.datetime.utcnow() mock_update_action.return_value = fake_saved_action uuid = self.fake_action['uuid'] action = objects.Action.get_by_uuid( self.context, uuid, eager=self.eager) action.state = objects.action.State.SUCCEEDED if not self.eager: self.assertRaises(exception.EagerlyLoadedActionRequired, action.save) else: action.save() expected_update_at = fake_saved_action['updated_at'].replace( tzinfo=iso8601.UTC) mock_get_action.assert_called_once_with( self.context, uuid, eager=self.eager) mock_update_action.assert_called_once_with( uuid, {'state': objects.action.State.SUCCEEDED}) self.assertEqual(self.context, action._context) self.assertEqual(expected_update_at, action.updated_at) self.assertEqual(0, self.m_send_update.call_count)
Example #21
Source File: utils.py From magnum with Apache License 2.0 | 5 votes |
def datetime_or_none(dt): """Validate a datetime or None value.""" if dt is None: return None elif isinstance(dt, datetime.datetime): if dt.utcoffset() is None: # NOTE(danms): Legacy objects from sqlalchemy are stored in UTC, # but are returned without a timezone attached. # As a transitional aid, assume a tz-naive object is in UTC. return dt.replace(tzinfo=iso8601.UTC) else: return dt raise ValueError(_("A datetime.datetime is required here"))
Example #22
Source File: test_scoring_engine.py From watcher with Apache License 2.0 | 5 votes |
def test_create(self, mock_create_scoring_engine): mock_create_scoring_engine.return_value = self.fake_scoring_engine scoring_engine = objects.ScoringEngine( self.context, **self.fake_scoring_engine) scoring_engine.create() expected_scoring_engine = self.fake_scoring_engine.copy() expected_scoring_engine['created_at'] = expected_scoring_engine[ 'created_at'].replace(tzinfo=iso8601.UTC) mock_create_scoring_engine.assert_called_once_with( expected_scoring_engine) self.assertEqual(self.context, scoring_engine._context)
Example #23
Source File: test_action_plan.py From watcher with Apache License 2.0 | 5 votes |
def test_create(self, mock_create_action_plan): mock_create_action_plan.return_value = self.fake_action_plan action_plan = objects.ActionPlan( self.context, **self.fake_action_plan) action_plan.create() expected_action_plan = self.fake_action_plan.copy() expected_action_plan['created_at'] = expected_action_plan[ 'created_at'].replace(tzinfo=iso8601.UTC) mock_create_action_plan.assert_called_once_with(expected_action_plan) self.assertEqual(self.context, action_plan._context)
Example #24
Source File: fakes.py From tacker with Apache License 2.0 | 5 votes |
def return_vnf_resource(): version_obj = objects.VnfResource( created_at=datetime.datetime(1900, 1, 1, 1, 1, 1, tzinfo=iso8601.UTC), deleted=False, deleted_at=None, id=uuidsentinel.vnf_resource_id, resource_identifier=uuidsentinel.resource_identifier, resource_name='test-image', resource_status='CREATED', resource_type='image', updated_at=None, vnf_instance_id=uuidsentinel.vnf_instance_id ) return version_obj
Example #25
Source File: test_service.py From watcher with Apache License 2.0 | 5 votes |
def test_create(self, mock_create_service): mock_create_service.return_value = self.fake_service service = objects.Service(self.context, **self.fake_service) service.create() expected_service = self.fake_service.copy() expected_service['created_at'] = expected_service[ 'created_at'].replace(tzinfo=iso8601.UTC) mock_create_service.assert_called_once_with(expected_service) self.assertEqual(self.context, service._context)
Example #26
Source File: test_fields.py From masakari with Apache License 2.0 | 5 votes |
def setUp(self): super(TestDateTime, self).setUp() self.dt = datetime.datetime(2016, 11, 5, tzinfo=iso8601.UTC) self.field = fields.DateTimeField() self.coerce_good_values = [(self.dt, self.dt), (utils.isotime(self.dt), self.dt)] self.coerce_bad_values = [1, 'foo'] self.to_primitive_values = [(self.dt, utils.isotime(self.dt))] self.from_primitive_values = [(utils.isotime(self.dt), self.dt)]
Example #27
Source File: test_action_description.py From watcher with Apache License 2.0 | 5 votes |
def test_create(self, mock_create_action_desc): mock_create_action_desc.return_value = self.fake_action_desc action_desc = objects.ActionDescription( self.context, **self.fake_action_desc) action_desc.create() expected_action_desc = self.fake_action_desc.copy() expected_action_desc['created_at'] = expected_action_desc[ 'created_at'].replace(tzinfo=iso8601.UTC) mock_create_action_desc.assert_called_once_with(expected_action_desc) self.assertEqual(self.context, action_desc._context)
Example #28
Source File: fakes.py From masakari with Apache License 2.0 | 5 votes |
def create_fake_host(**updates): host = { 'name': 'fake_host', 'id': 1, 'reserved': False, 'on_maintenance': False, 'type': 'SSH', 'control_attributes': 'fake', 'uuid': uuidsentinel.fake_host, 'failover_segment': FAILOVER_SEGMENT, 'created_at': datetime.datetime( 2019, 8, 8, 0, 0, 0, tzinfo=iso8601.UTC), 'updated_at': None, 'deleted_at': None, 'deleted': False } if updates: host.update(updates) return objects.Host(**host)
Example #29
Source File: test_audit.py From watcher with Apache License 2.0 | 5 votes |
def test_create(self, mock_create_audit): mock_create_audit.return_value = self.fake_audit audit = objects.Audit(self.context, **self.fake_audit) audit.create() expected_audit = self.fake_audit.copy() expected_audit['created_at'] = expected_audit['created_at'].replace( tzinfo=iso8601.UTC) mock_create_audit.assert_called_once_with(expected_audit) self.assertEqual(self.context, audit._context)
Example #30
Source File: test_audit.py From watcher with Apache License 2.0 | 5 votes |
def test_save(self, mock_get_audit, mock_update_audit): mock_get_audit.return_value = self.fake_audit fake_saved_audit = self.fake_audit.copy() fake_saved_audit['state'] = objects.audit.State.SUCCEEDED fake_saved_audit['updated_at'] = datetime.datetime.utcnow() mock_update_audit.return_value = fake_saved_audit expected_audit = fake_saved_audit.copy() expected_audit['created_at'] = expected_audit['created_at'].replace( tzinfo=iso8601.UTC) expected_audit['updated_at'] = expected_audit['updated_at'].replace( tzinfo=iso8601.UTC) uuid = self.fake_audit['uuid'] audit = objects.Audit.get_by_uuid(self.context, uuid, eager=self.eager) audit.state = objects.audit.State.SUCCEEDED audit.save() mock_get_audit.assert_called_once_with( self.context, uuid, eager=self.eager) mock_update_audit.assert_called_once_with( uuid, {'state': objects.audit.State.SUCCEEDED}) self.assertEqual(self.context, audit._context) self.eager_load_audit_assert(audit, self.fake_goal) self.m_send_update.assert_called_once_with( self.context, audit, old_state=self.fake_audit['state']) self.assertEqual( {k: v for k, v in expected_audit.items() if k not in audit.object_fields}, {k: v for k, v in audit.as_dict().items() if k not in audit.object_fields})