Python oslo_utils.timeutils.parse_isotime() Examples

The following are 30 code examples of oslo_utils.timeutils.parse_isotime(). 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 oslo_utils.timeutils , or try the search function .
Example #1
Source File: test_orders.py    From python-barbicanclient with Apache License 2.0 6 votes vote down vote up
def test_create_order_defaults_valid_expiration(self, **kwargs):
        """Covers creating orders with various valid expiration data."""
        timestamp = utils.create_timestamp_w_tz_and_offset(**kwargs)

        date = timeutils.parse_isotime(timestamp)
        date = date.astimezone(pytz.utc)

        order = self.barbicanclient.orders.create_key(**order_create_key_data)
        order.expiration = timestamp

        order_ref = self.cleanup.add_entity(order)
        self.assertIsNotNone(order_ref)

        order_resp = self.barbicanclient.orders.get(order_ref)
        self.assertIsNotNone(order_resp)
        self.assertEqual(date, order_resp.expiration) 
Example #2
Source File: test_audit_templates.py    From watcher with Apache License 2.0 6 votes vote down vote up
def test_create_audit_template(self, mock_utcnow):
        audit_template_dict = post_get_test_audit_template(
            goal=self.fake_goal1.uuid,
            strategy=self.fake_strategy1.uuid)
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.post_json('/audit_templates', audit_template_dict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = \
            '/v1/audit_templates/%s' % response.json['uuid']
        self.assertEqual(urlparse.urlparse(response.location).path,
                         expected_location)
        self.assertTrue(utils.is_uuid_like(response.json['uuid']))
        self.assertNotIn('updated_at', response.json.keys)
        self.assertNotIn('deleted_at', response.json.keys)
        self.assertEqual(self.fake_goal1.uuid, response.json['goal_uuid'])
        self.assertEqual(self.fake_strategy1.uuid,
                         response.json['strategy_uuid'])
        return_created_at = timeutils.parse_isotime(
            response.json['created_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_created_at) 
Example #3
Source File: test_acls.py    From python-barbicanclient with Apache License 2.0 6 votes vote down vote up
def test_should_load_acls_data(self):
        self.responses.get(
            self.container_acl_ref, json=self.get_acl_response_data(
                users=self.users2, project_access=True))

        entity = self.manager.create(entity_ref=self.container_ref,
                                     users=self.users1)
        self.assertEqual(self.container_ref, entity.entity_ref)
        self.assertEqual(self.container_acl_ref, entity.acl_ref)

        entity.load_acls_data()

        self.assertEqual(self.users2, entity.read.users)
        self.assertTrue(entity.get('read').project_access)
        self.assertEqual(timeutils.parse_isotime(self.created),
                         entity.read.created)
        self.assertEqual(timeutils.parse_isotime(self.created),
                         entity.get('read').created)

        self.assertEqual(1, len(entity.operation_acls))
        self.assertEqual(self.container_acl_ref, entity.get('read').acl_ref)
        self.assertEqual(self.container_ref, entity.read.entity_ref) 
Example #4
Source File: test_cluster_template.py    From magnum with Apache License 2.0 6 votes vote down vote up
def test_create_cluster_template_with_multi_dns(self, mock_utcnow,
                                                    mock_image_data):
        bdict = apiutils.cluster_template_post_data(
            dns_nameserver="8.8.8.8,114.114.114.114")
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time
        mock_image_data.return_value = {'name': 'mock_name',
                                        'os_distro': 'fedora-atomic'}

        response = self.post_json('/clustertemplates', bdict)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = '/v1/clustertemplates/%s' % bdict['uuid']
        self.assertEqual(expected_location,
                         urlparse.urlparse(response.location).path)
        self.assertEqual(bdict['uuid'], response.json['uuid'])
        self.assertNotIn('updated_at', response.json.keys)
        return_created_at = timeutils.parse_isotime(
            response.json['created_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_created_at) 
Example #5
Source File: test_service.py    From watcher with Apache License 2.0 6 votes vote down vote up
def _data_setup(self):
        service1_name = "SERVICE_ID_1"
        service2_name = "SERVICE_ID_2"
        service3_name = "SERVICE_ID_3"

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.service1 = utils.create_test_service(
                id=1, name=service1_name, host="controller",
                last_seen_up=timeutils.parse_isotime("2016-09-22T08:32:05"))
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.service2 = utils.create_test_service(
                id=2, name=service2_name, host="controller",
                last_seen_up=timeutils.parse_isotime("2016-09-22T08:32:05"))
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.service3 = utils.create_test_service(
                id=3, name=service3_name, host="controller",
                last_seen_up=timeutils.parse_isotime("2016-09-22T08:32:05")) 
Example #6
Source File: test_cluster_template.py    From magnum with Apache License 2.0 6 votes vote down vote up
def test_create_cluster_template(self, mock_utcnow,
                                     mock_image_data):
        bdict = apiutils.cluster_template_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time
        mock_image_data.return_value = {'name': 'mock_name',
                                        'os_distro': 'fedora-atomic'}

        response = self.post_json('/clustertemplates', bdict)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = '/v1/clustertemplates/%s' % bdict['uuid']
        self.assertEqual(expected_location,
                         urlparse.urlparse(response.location).path)
        self.assertEqual(bdict['uuid'], response.json['uuid'])
        self.assertNotIn('updated_at', response.json.keys)
        return_created_at = timeutils.parse_isotime(
            response.json['created_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_created_at) 
Example #7
Source File: functional.py    From ironic-inspector with Apache License 2.0 6 votes vote down vote up
def check_status(self, status, finished, state, error=None):
        self.assertEqual(
            self._fake_status(finished=finished,
                              state=state,
                              finished_at=finished and mock.ANY or None,
                              error=error),
            status
        )
        curr_time = datetime.datetime.fromtimestamp(
            time.time(), tz=pytz.timezone(time.tzname[0]))
        started_at = timeutils.parse_isotime(status['started_at'])
        self.assertLess(started_at, curr_time)
        if finished:
            finished_at = timeutils.parse_isotime(status['finished_at'])
            self.assertLess(started_at, finished_at)
            self.assertLess(finished_at, curr_time)
        else:
            self.assertIsNone(status['finished_at']) 
Example #8
Source File: test_nodegroup.py    From magnum with Apache License 2.0 6 votes vote down vote up
def test_replace_ok_by_name(self, mock_utcnow):
        max_node_count = 4
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.patch_json(self.url + self.nodegroup.name,
                                   [{'path': '/max_node_count',
                                     'value': max_node_count,
                                     'op': 'replace'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(202, response.status_code)

        response = self.get_json(self.url + self.nodegroup.uuid)
        self.assertEqual(max_node_count, response['max_node_count'])
        return_updated_at = timeutils.parse_isotime(
            response['updated_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_updated_at) 
Example #9
Source File: test_nodegroup.py    From magnum with Apache License 2.0 6 votes vote down vote up
def test_replace_ok(self, mock_utcnow):
        max_node_count = 4
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.patch_json(self.url + self.nodegroup.uuid,
                                   [{'path': '/max_node_count',
                                     'value': max_node_count,
                                     'op': 'replace'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(202, response.status_code)

        response = self.get_json(self.url + self.nodegroup.uuid)
        self.assertEqual(max_node_count, response['max_node_count'])
        return_updated_at = timeutils.parse_isotime(
            response['updated_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_updated_at) 
Example #10
Source File: ceilometer.py    From watcher with Apache License 2.0 6 votes vote down vote up
def _timestamps(self, start_time, end_time):

        def _format_timestamp(_time):
            if _time:
                if isinstance(_time, datetime.datetime):
                    return _time.isoformat()
                return _time
            return None

        start_timestamp = _format_timestamp(start_time)
        end_timestamp = _format_timestamp(end_time)

        if ((start_timestamp is not None) and (end_timestamp is not None) and
                (timeutils.parse_isotime(start_timestamp) >
                 timeutils.parse_isotime(end_timestamp))):
            raise exception.Invalid(
                _("Invalid query: %(start_time)s > %(end_time)s") % dict(
                    start_time=start_timestamp, end_time=end_timestamp))
        return start_timestamp, end_timestamp 
Example #11
Source File: test_baymodel.py    From magnum with Apache License 2.0 6 votes vote down vote up
def test_create_baymodel(self, mock_utcnow,
                             mock_image_data):
        bdict = apiutils.baymodel_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time
        mock_image_data.return_value = {'name': 'mock_name',
                                        'os_distro': 'fedora-atomic'}

        response = self.post_json('/baymodels', bdict)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = '/v1/baymodels/%s' % bdict['uuid']
        self.assertEqual(expected_location,
                         urlparse.urlparse(response.location).path)
        self.assertEqual(bdict['uuid'], response.json['uuid'])
        self.assertNotIn('updated_at', response.json.keys)
        return_created_at = timeutils.parse_isotime(
            response.json['created_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_created_at) 
Example #12
Source File: test_cluster.py    From magnum with Apache License 2.0 6 votes vote down vote up
def test_replace_ok_by_name(self, mock_utcnow):
        new_node_count = 4
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.patch_json('/clusters/%s' % self.cluster_obj.name,
                                   [{'path': '/node_count',
                                     'value': new_node_count,
                                     'op': 'replace'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(202, response.status_code)

        response = self.get_json('/clusters/%s' % self.cluster_obj.uuid)
        self.assertEqual(new_node_count, response['node_count'])
        return_updated_at = timeutils.parse_isotime(
            response['updated_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_updated_at)
        # Assert nothing else was changed
        self.assertEqual(self.cluster_obj.uuid, response['uuid'])
        self.assertEqual(self.cluster_obj.cluster_template_id,
                         response['cluster_template_id']) 
Example #13
Source File: test_bay.py    From magnum with Apache License 2.0 6 votes vote down vote up
def test_replace_ok(self, mock_utcnow):
        new_node_count = 4
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.patch_json('/bays/%s' % self.bay.uuid,
                                   [{'path': '/node_count',
                                     'value': new_node_count,
                                     'op': 'replace'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)

        response = self.get_json('/bays/%s' % self.bay.uuid)
        self.assertEqual(new_node_count, response['node_count'])
        return_updated_at = timeutils.parse_isotime(
            response['updated_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_updated_at)
        # Assert nothing else was changed
        self.assertEqual(self.bay.uuid, response['uuid'])
        self.assertEqual(self.bay.cluster_template_id, response['baymodel_id']) 
Example #14
Source File: test_bay.py    From magnum with Apache License 2.0 6 votes vote down vote up
def test_create_bay(self, mock_utcnow):
        bdict = apiutils.bay_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.post_json('/bays', bdict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        self.assertTrue(uuidutils.is_uuid_like(response.json['uuid']))
        self.assertNotIn('updated_at', response.json.keys)
        return_created_at = timeutils.parse_isotime(
            response.json['created_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_created_at)
        self.assertEqual(bdict['bay_create_timeout'],
                         response.json['bay_create_timeout']) 
Example #15
Source File: containers.py    From python-barbicanclient with Apache License 2.0 6 votes vote down vote up
def __init__(self, api, name=None, secrets=None, consumers=None,
                 container_ref=None, created=None, updated=None, status=None,
                 secret_refs=None):
        self._api = api
        self._secret_manager = secret_manager.SecretManager(api)
        self._name = name
        self._container_ref = container_ref
        self._secret_refs = secret_refs
        self._cached_secrets = dict()
        self._initialize_secrets(secrets)
        if container_ref:
            self._consumers = consumers if consumers else list()
            self._created = parse_isotime(created) if created else None
            self._updated = parse_isotime(updated) if updated else None
            self._status = status
        else:
            self._consumers = list()
            self._created = None
            self._updated = None
            self._status = None
        self._acl_manager = acl_manager.ACLManager(api)
        self._acls = None 
Example #16
Source File: validators.py    From sgx-kms with Apache License 2.0 6 votes vote down vote up
def _extract_expiration(self, json_data, schema_name):
        """Extracts and returns the expiration date from the JSON data."""
        expiration = None
        expiration_raw = json_data.get('expiration', None)
        if expiration_raw and expiration_raw.strip():
            try:
                expiration_tz = timeutils.parse_isotime(expiration_raw)
                expiration = timeutils.normalize_time(expiration_tz)
            except ValueError:
                LOG.exception("Problem parsing expiration date")
                raise exception.InvalidObject(schema=schema_name,
                                              reason=u._("Invalid date "
                                                         "for 'expiration'"),
                                              property="expiration")

        return expiration 
Example #17
Source File: validators.py    From sgx-kms with Apache License 2.0 6 votes vote down vote up
def _extract_expiration(self, json_data, schema_name):
        """Extracts and returns the expiration date from the JSON data."""
        expiration = None
        expiration_raw = json_data.get('expiration')
        if expiration_raw and expiration_raw.strip():
            try:
                expiration_tz = timeutils.parse_isotime(expiration_raw.strip())
                expiration = timeutils.normalize_time(expiration_tz)
            except ValueError:
                LOG.exception("Problem parsing expiration date")
                raise exception.InvalidObject(
                    schema=schema_name,
                    reason=u._("Invalid date for 'expiration'"),
                    property="expiration")

        return expiration 
Example #18
Source File: test_audits.py    From watcher with Apache License 2.0 6 votes vote down vote up
def test_replace_ok(self, mock_utcnow):
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        new_state = objects.audit.State.CANCELLED
        response = self.get_json('/audits/%s' % self.audit.uuid)
        self.assertNotEqual(new_state, response['state'])

        response = self.patch_json(
            '/audits/%s' % self.audit.uuid,
            [{'path': '/state', 'value': new_state,
             'op': 'replace'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)

        response = self.get_json('/audits/%s' % self.audit.uuid)
        self.assertEqual(new_state, response['state'])
        return_updated_at = timeutils.parse_isotime(
            response['updated_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_updated_at) 
Example #19
Source File: validators.py    From barbican with Apache License 2.0 6 votes vote down vote up
def _extract_expiration(self, json_data, schema_name):
        """Extracts and returns the expiration date from the JSON data."""
        expiration = None
        expiration_raw = json_data.get('expiration')
        if expiration_raw and expiration_raw.strip():
            try:
                expiration_tz = timeutils.parse_isotime(expiration_raw.strip())
                expiration = timeutils.normalize_time(expiration_tz)
            except ValueError:
                LOG.exception("Problem parsing expiration date")
                raise exception.InvalidObject(
                    schema=schema_name,
                    reason=u._("Invalid date for 'expiration'"),
                    property="expiration")

        return expiration 
Example #20
Source File: validators.py    From barbican with Apache License 2.0 6 votes vote down vote up
def _extract_expiration(self, json_data, schema_name):
        """Extracts and returns the expiration date from the JSON data."""
        expiration = None
        expiration_raw = json_data.get('expiration', None)
        if expiration_raw and expiration_raw.strip():
            try:
                expiration_tz = timeutils.parse_isotime(expiration_raw)
                expiration = timeutils.normalize_time(expiration_tz)
            except ValueError:
                LOG.exception("Problem parsing expiration date")
                raise exception.InvalidObject(schema=schema_name,
                                              reason=u._("Invalid date "
                                                         "for 'expiration'"),
                                              property="expiration")

        return expiration 
Example #21
Source File: test_audits.py    From watcher with Apache License 2.0 6 votes vote down vote up
def test_replace_ok(self, mock_utcnow):
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.get_json('/audits/%s' % self.audit.uuid)
        self.assertNotEqual(self.new_state, response['state'])

        response = self.patch_json(
            '/audits/%s' % self.audit.uuid,
            [{'path': '/state', 'value': self.new_state,
             'op': 'replace'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)

        response = self.get_json('/audits/%s' % self.audit.uuid)
        self.assertEqual(self.new_state, response['state'])
        return_updated_at = timeutils.parse_isotime(
            response['updated_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_updated_at) 
Example #22
Source File: test_audits.py    From watcher with Apache License 2.0 6 votes vote down vote up
def test_create_audit(self, mock_utcnow, mock_trigger_audit):
        mock_trigger_audit.return_value = mock.ANY
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        audit_dict = post_get_test_audit(
            state=objects.audit.State.PENDING,
            params_to_exclude=['uuid', 'state', 'interval', 'scope',
                               'next_run_time', 'hostname', 'goal'])

        response = self.post_json('/audits', audit_dict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = '/v1/audits/%s' % response.json['uuid']
        self.assertEqual(urlparse.urlparse(response.location).path,
                         expected_location)
        self.assertEqual(objects.audit.State.PENDING,
                         response.json['state'])
        self.assertNotIn('updated_at', response.json.keys)
        self.assertNotIn('deleted_at', response.json.keys)
        return_created_at = timeutils.parse_isotime(
            response.json['created_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_created_at) 
Example #23
Source File: fields.py    From oslo.versionedobjects with Apache License 2.0 6 votes vote down vote up
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 #24
Source File: test_audit_templates.py    From watcher with Apache License 2.0 6 votes vote down vote up
def test_replace_goal_uuid_by_name(self, mock_utcnow):
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        new_goal_uuid = self.fake_goal2.uuid
        response = self.get_json(urlparse.quote(
            '/audit_templates/%s' % self.audit_template.name))
        self.assertNotEqual(new_goal_uuid, response['goal_uuid'])

        response = self.patch_json(
            '/audit_templates/%s' % self.audit_template.name,
            [{'path': '/goal', 'value': new_goal_uuid,
              'op': 'replace'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)

        response = self.get_json(
            '/audit_templates/%s' % self.audit_template.name)
        self.assertEqual(new_goal_uuid, response['goal_uuid'])
        return_updated_at = timeutils.parse_isotime(
            response['updated_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_updated_at) 
Example #25
Source File: test_bay.py    From magnum with Apache License 2.0 6 votes vote down vote up
def test_replace_ok_by_name(self, mock_utcnow):
        new_node_count = 4
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.patch_json('/bays/%s' % self.bay.name,
                                   [{'path': '/node_count',
                                     'value': new_node_count,
                                     'op': 'replace'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)

        response = self.get_json('/bays/%s' % self.bay.uuid)
        self.assertEqual(new_node_count, response['node_count'])
        return_updated_at = timeutils.parse_isotime(
            response['updated_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_updated_at)
        # Assert nothing else was changed
        self.assertEqual(self.bay.uuid, response['uuid'])
        self.assertEqual(self.bay.cluster_template_id, response['baymodel_id']) 
Example #26
Source File: secrets.py    From barbican with Apache License 2.0 5 votes vote down vote up
def _is_valid_date_filter(self, date_filter):
        filters = date_filter.split(',')
        sorted_filters = dict()
        try:
            for filter in filters:
                if filter.startswith('gt:'):
                    if sorted_filters.get('gt') or sorted_filters.get('gte'):
                        return False
                    sorted_filters['gt'] = timeutils.parse_isotime(filter[3:])
                elif filter.startswith('gte:'):
                    if sorted_filters.get('gt') or sorted_filters.get(
                            'gte') or sorted_filters.get('eq'):
                        return False
                    sorted_filters['gte'] = timeutils.parse_isotime(filter[4:])
                elif filter.startswith('lt:'):
                    if sorted_filters.get('lt') or sorted_filters.get('lte'):
                        return False
                    sorted_filters['lt'] = timeutils.parse_isotime(filter[3:])
                elif filter.startswith('lte:'):
                    if sorted_filters.get('lt') or sorted_filters.get(
                            'lte') or sorted_filters.get('eq'):
                        return False
                    sorted_filters['lte'] = timeutils.parse_isotime(filter[4:])
                elif sorted_filters.get('eq') or sorted_filters.get(
                        'gte') or sorted_filters.get('lte'):
                    return False
                else:
                    sorted_filters['eq'] = timeutils.parse_isotime(filter)
        except ValueError:
            return False
        return True 
Example #27
Source File: helpers.py    From monasca-api with Apache License 2.0 5 votes vote down vote up
def _convert_time_string(date_time_string):
    dt = timeutils.parse_isotime(date_time_string)
    dt = timeutils.normalize_time(dt)
    timestamp = (dt - datetime.datetime(1970, 1, 1)).total_seconds()
    return timestamp 
Example #28
Source File: test_secrets.py    From python-barbicanclient with Apache License 2.0 5 votes vote down vote up
def test_get_formatted_data(self):
        data = self.secret.get_dict(self.entity_href)
        self.responses.get(self.entity_href, json=data)

        secret = self.manager.get(secret_ref=self.entity_href)
        f_data = secret._get_formatted_data()
        self.assertEqual(
            timeutils.parse_isotime(data['created']).isoformat(),
            f_data[2]) 
Example #29
Source File: test_cas.py    From python-barbicanclient with Apache License 2.0 5 votes vote down vote up
def test_get_formatted_data(self):
        c_entity = cas.CA(api=None,
                          expiration=self.ca.expiration,
                          plugin_name=self.ca.plugin_name,
                          created=self.ca.created)

        data = c_entity._get_formatted_data()

        self.assertEqual(self.ca.plugin_name, data[6])
        self.assertEqual(timeutils.parse_isotime(
                         self.ca.expiration).isoformat(),
                         data[8]) 
Example #30
Source File: test_containers.py    From python-barbicanclient with Apache License 2.0 5 votes vote down vote up
def test_get_formatted_data(self):
        data = self.container.get_dict(self.entity_href)
        self.responses.get(self.entity_href, json=data)

        container = self.manager.get(container_ref=self.entity_href)

        data = container._get_formatted_data()

        self.assertEqual(self.container.name, data[1])
        self.assertEqual(timeutils.parse_isotime(
                         self.container.created).isoformat(),
                         data[2])