本文整理匯總了Python中iso8601.UTC屬性的典型用法代碼示例。如果您正苦於以下問題:Python iso8601.UTC屬性的具體用法?Python iso8601.UTC怎麽用?Python iso8601.UTC使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類iso8601
的用法示例。
在下文中一共展示了iso8601.UTC屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_index_with_created_since_and_created_before
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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'])
示例2: stub_message
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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
示例3: coerce
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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
示例4: fake_vnf_instance_model_dict
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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
示例5: _fake_software_image
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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
示例6: fake_vnf_package_vnfd_model_dict
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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
示例7: _model_non_instantiated_vnf_instance
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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
示例8: fake_vnf_package
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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
示例9: test_soft_delete
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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())
示例10: test_soft_delete
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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())
示例11: test_soft_delete
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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())
示例12: test_soft_delete
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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())
示例13: test_base_attributes
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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)
示例14: test_soft_delete
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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())
示例15: test_soft_delete
# 需要導入模塊: import iso8601 [as 別名]
# 或者: from iso8601 import UTC [as 別名]
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())