コード例 #1
0
 def test_invalid_tag_ignored(self):
     # Fix for bug 1356784 - we treated any tag as a version, not just those
     # that are valid versions.
     self.repo.commit()
     self.repo.tag('1')
     self.repo.commit()
     # when the tree is tagged and its wrong:
     self.repo.tag('badver')
     version = packaging._get_version_from_git()
     self.assertThat(version, matchers.StartsWith('1.0.1.dev1.g'))
     # When the tree isn't tagged, we also fall through.
     self.repo.commit()
     version = packaging._get_version_from_git()
     self.assertThat(version, matchers.StartsWith('1.0.1.dev2.g'))
     # We don't fall through x.y versions
     self.repo.commit()
     self.repo.tag('1.2')
     self.repo.commit()
     self.repo.tag('badver2')
     version = packaging._get_version_from_git()
     self.assertThat(version, matchers.StartsWith('1.2.1.dev1.g'))
     # Or x.y.z versions
     self.repo.commit()
     self.repo.tag('1.2.3')
     self.repo.commit()
     self.repo.tag('badver3')
     version = packaging._get_version_from_git()
     self.assertThat(version, matchers.StartsWith('1.2.4.dev1.g'))
     # Or alpha/beta/pre versions
     self.repo.commit()
     self.repo.tag('1.2.4.0a1')
     self.repo.commit()
     self.repo.tag('badver4')
     version = packaging._get_version_from_git()
     self.assertThat(version, matchers.StartsWith('1.2.4.dev1.g'))
コード例 #2
0
ファイル: test_v3.py プロジェクト: carrierstack/keystone
    def assertValidListLinks(self, links):
        self.assertIsNotNone(links)
        self.assertIsNotNone(links.get('self'))
        self.assertThat(links['self'], matchers.StartsWith('http://localhost'))

        self.assertIn('next', links)
        if links['next'] is not None:
            self.assertThat(links['next'],
                            matchers.StartsWith('http://localhost'))

        self.assertIn('previous', links)
        if links['previous'] is not None:
            self.assertThat(links['previous'],
                            matchers.StartsWith('http://localhost'))
コード例 #3
0
    def test_build_pxe_config(self):
        args = {
                'deployment_id': 'aaa',
                'deployment_key': 'bbb',
                'deployment_iscsi_iqn': 'ccc',
                'deployment_aki_path': 'ddd',
                'deployment_ari_path': 'eee',
                'aki_path': 'fff',
                'ari_path': 'ggg',
            }
        config = pxe.build_pxe_config(**args)
        self.assertThat(config, matchers.StartsWith('default deploy'))

        # deploy bits are in the deploy section
        start = config.index('label deploy')
        end = config.index('label boot')
        self.assertThat(config[start:end], matchers.MatchesAll(
            matchers.Contains('kernel ddd'),
            matchers.Contains('initrd=eee'),
            matchers.Contains('deployment_id=aaa'),
            matchers.Contains('deployment_key=bbb'),
            matchers.Contains('iscsi_target_iqn=ccc'),
            matchers.Not(matchers.Contains('kernel fff')),
            ))

        # boot bits are in the boot section
        start = config.index('label boot')
        self.assertThat(config[start:], matchers.MatchesAll(
            matchers.Contains('kernel fff'),
            matchers.Contains('initrd=ggg'),
            matchers.Not(matchers.Contains('kernel ddd')),
            ))
コード例 #4
0
    def _validate_oauth_headers(self, auth_header, oauth_client):
        """Assert that the data in the headers matches the data
        that is produced from oauthlib.
        """

        self.assertThat(auth_header, matchers.StartsWith('OAuth '))
        auth_header = auth_header[len('OAuth '):]
        # NOTE(stevemar): In newer versions of oauthlib there is
        # an additional argument for getting oauth parameters.
        # Adding a conditional here to revert back to no arguments
        # if an earlier version is detected.
        if tuple(oauthlib.__version__.split('.')) > ('0', '6', '1'):
            header_params = oauth_client.get_oauth_params(None)
        else:
            header_params = oauth_client.get_oauth_params()
        parameters = dict(header_params)

        self.assertEqual('HMAC-SHA1', parameters['oauth_signature_method'])
        self.assertEqual('1.0', parameters['oauth_version'])
        self.assertIsInstance(parameters['oauth_nonce'], six.string_types)
        self.assertEqual(oauth_client.client_key,
                         parameters['oauth_consumer_key'])
        if oauth_client.resource_owner_key:
            self.assertEqual(oauth_client.resource_owner_key,
                             parameters['oauth_token'],)
        if oauth_client.verifier:
            self.assertEqual(oauth_client.verifier,
                             parameters['oauth_verifier'])
        if oauth_client.callback_uri:
            self.assertEqual(oauth_client.callback_uri,
                             parameters['oauth_callback'])
        if oauth_client.timestamp:
            self.assertEqual(oauth_client.timestamp,
                             parameters['oauth_timestamp'])
        return parameters
コード例 #5
0
ファイル: test_v3.py プロジェクト: xiaoliukai/keystone
    def assertValidEntity(self, entity, ref=None, keys_to_check=None):
        """Make assertions common to all API entities.

        If a reference is provided, the entity will also be compared against
        the reference.
        """
        if keys_to_check is not None:
            keys = keys_to_check
        else:
            keys = ['name', 'description', 'enabled']

        for k in ['id'] + keys:
            msg = '%s unexpectedly None in %s' % (k, entity)
            self.assertIsNotNone(entity.get(k), msg)

        self.assertIsNotNone(entity.get('links'))
        self.assertIsNotNone(entity['links'].get('self'))
        self.assertThat(entity['links']['self'],
                        matchers.StartsWith('http://localhost'))
        self.assertIn(entity['id'], entity['links']['self'])

        if ref:
            for k in keys:
                msg = '%s not equal: %s != %s' % (k, ref[k], entity[k])
                self.assertEqual(ref[k], entity[k])

        return entity
コード例 #6
0
    def _validate_oauth_headers(self, auth_header, oauth_client):
        """Assert that the data in the headers matches the data
        that is produced from oauthlib.
        """

        self.assertThat(auth_header, matchers.StartsWith('OAuth '))
        auth_header = auth_header[len('OAuth '):]
        header_params = oauth_client.get_oauth_params()
        parameters = dict(header_params)

        self.assertEqual('HMAC-SHA1', parameters['oauth_signature_method'])
        self.assertEqual('1.0', parameters['oauth_version'])
        self.assertIsInstance(parameters['oauth_nonce'], six.string_types)
        self.assertEqual(oauth_client.client_key,
                         parameters['oauth_consumer_key'])
        if oauth_client.resource_owner_key:
            self.assertEqual(
                oauth_client.resource_owner_key,
                parameters['oauth_token'],
            )
        if oauth_client.verifier:
            self.assertEqual(oauth_client.verifier,
                             parameters['oauth_verifier'])
        if oauth_client.callback_uri:
            self.assertEqual(oauth_client.callback_uri,
                             parameters['oauth_callback'])
        if oauth_client.timestamp:
            self.assertEqual(oauth_client.timestamp,
                             parameters['oauth_timestamp'])
        return parameters
コード例 #7
0
    def test_actions(self):
        """Test that information on actions can be invoked

        Test that information on actions can be invoked on each MuranoPL
        object are persisted into object header ('?' key) during serialization
        of Objects section of Object Model

        """
        serialized = self._runner.serialized_model
        actions = serialized['Objects']['?'].get('_actions')
        self.assertIsInstance(actions, dict)
        action_names = [action['name'] for action in actions.values()]
        self.assertIn('testAction', action_names)
        self.assertNotIn('notAction', action_names)
        self.assertIn('testRootMethod', action_names)
        action_meta = None
        for action in actions.values():
            self.assertIsInstance(action.get('enabled'), bool)
            self.assertIsInstance(action.get('name'), six.string_types)
            self.assertThat(
                action['name'],
                matchers.StartsWith('test'))
            if action['name'] == 'testActionMeta':
                action_meta = action
            else:
                self.assertEqual(action['title'], action['name'])
        self.assertIsNotNone(action_meta)
        self.assertEqual(action_meta['title'], "Title of the method")
        self.assertEqual(action_meta['description'],
                         "Description of the method")
        self.assertEqual(action_meta['helpText'], "HelpText of the method")
コード例 #8
0
    def _validate_oauth_headers(self, auth_header, oauth_client):
        """Validate data in the headers.

        Assert that the data in the headers matches the data
        that is produced from oauthlib.
        """

        self.assertThat(auth_header, matchers.StartsWith('OAuth '))
        parameters = dict(
            oauth1.rfc5849.utils.parse_authorization_header(auth_header))

        self.assertEqual('HMAC-SHA1', parameters['oauth_signature_method'])
        self.assertEqual('1.0', parameters['oauth_version'])
        self.assertIsInstance(parameters['oauth_nonce'], six.string_types)
        self.assertEqual(oauth_client.client_key,
                         parameters['oauth_consumer_key'])
        if oauth_client.resource_owner_key:
            self.assertEqual(
                oauth_client.resource_owner_key,
                parameters['oauth_token'],
            )
        if oauth_client.verifier:
            self.assertEqual(oauth_client.verifier,
                             parameters['oauth_verifier'])
        if oauth_client.callback_uri:
            self.assertEqual(oauth_client.callback_uri,
                             parameters['oauth_callback'])
        return parameters
コード例 #9
0
ファイル: test_os_http.py プロジェクト: openstack-dev/os-http
    def test_simple_get(self):
        path = '/%s' % uuid.uuid4().hex
        public_url = '%s%s' % (PUBLIC_SERVICE_URL, path)

        json_a = uuid.uuid4().hex
        json_b = uuid.uuid4().hex

        service_mock = self.requests_mock.get(
            public_url,
            json={json_a: json_b},
            status_code=200,
            reason='OK',
            headers={'Content-Type': 'application/json'})

        resp = self.shell('get', path, '--os-service-type', self.service_type,
                          '--os-auth-type', 'password', '--os-auth-url',
                          AUTH_URL, '--os-project-id', self.project_id,
                          '--os-user-id', self.user_id)

        self.assertEqual('GET', self.requests_mock.last_request.method)
        self.assertEqual(public_url, self.requests_mock.last_request.url)

        self.assertTrue(service_mock.called)

        self.assertThat(resp, matchers.StartsWith('HTTP/1.1 200 OK'))
        self.assertIn('Content-Type: application/json', resp)

        r = '.*{\s*"%s":\s*"%s"\s*}$' % (json_a, json_b)
        self.assertThat(resp, matchers.MatchesRegex(r, re.M | re.S))
コード例 #10
0
    def test_db_instance(self):
        driver = mongodb.DataDriver(self._conf)

        databases = driver.message_databases + [driver.queues_database]
        for db in databases:
            self.assertThat(db.name,
                            matchers.StartsWith(driver.mongodb_conf.database))
コード例 #11
0
 def test_delete(self):
     with self.app.test_client() as c:
         res = c.delete('/v1/leases/{0}'.format(self.lease_uuid),
                        headers=self.headers)
         res_id = res.headers.get(id.HTTP_RESP_HEADER_REQUEST_ID)
         self.assertEqual(204, res.status_code)
         self.assertIn(id.HTTP_RESP_HEADER_REQUEST_ID, res.headers)
         self.assertThat(res_id, matchers.StartsWith('req-'))
コード例 #12
0
    def test_db_instance(self):
        self.config(unreliable=True)
        cache = oslo_cache.get_cache(self.conf)
        control = mongodb.ControlDriver(self.conf, cache)
        data = mongodb.DataDriver(self.conf, cache, control)

        for db in data.message_databases:
            self.assertThat(db.name, matchers.StartsWith(
                data.mongodb_conf.database))
コード例 #13
0
 def test_timestamp_invalid(self):
     test_property_schema = {'type': 'timestamp'}
     # invalid timestamp - day out of range
     value = '2015-04-115T02:59:43.1Z'
     propertyInstance = Property('test_property', value,
                                 test_property_schema)
     error = self.assertRaises(ValueError, propertyInstance.validate)
     expected_message = (_('"%s" is not a valid timestamp.') % value)
     self.assertThat(str(error), matchers.StartsWith(expected_message))
コード例 #14
0
    def test_db_instance(self):
        cache = oslo_cache.get_cache()
        driver = mongodb.DataDriver(self.conf, cache)

        databases = (driver.message_databases + [driver.queues_database])

        for db in databases:
            self.assertThat(db.name,
                            matchers.StartsWith(driver.mongodb_conf.database))
コード例 #15
0
    def test_screenshot_and_page_dump_enabled(self):
        test = SSTStringTestCase('ignored')
        test.script_code = 'assert False'
        test.screenshots_on = True
        test.results_directory = 'results'
        self.run_failing_test(test)
        # We get a screenshot and a pagesource
        self.assertTrue(os.path.exists('results'))
        files = sorted(os.listdir('results'))
        self.assertEqual(2, len(files))

        def byte_size(f):
            return os.path.getsize(os.path.join(test.results_directory, f))

        self.assertGreater(byte_size(files[0]), 0)
        self.assertGreater(byte_size(files[1]), 0)
        self.assertThat(files[0], matchers.StartsWith('pagesource-'))
        self.assertThat(files[1], matchers.StartsWith('screenshot-'))
コード例 #16
0
 def test_tacker_context_create(self):
     ctx = context.Context('user_id', 'tenant_id')
     self.assertEqual('user_id', ctx.user_id)
     self.assertEqual('tenant_id', ctx.project_id)
     self.assertEqual('tenant_id', ctx.tenant_id)
     self.assertThat(ctx.request_id, matchers.StartsWith('req-'))
     self.assertEqual('user_id', ctx.user)
     self.assertEqual('tenant_id', ctx.tenant)
     self.assertIsNone(ctx.user_name)
     self.assertIsNone(ctx.tenant_name)
コード例 #17
0
 def test_send_cross_tenant(self):
     sid, message = base.generate_small_message()
     headers = {'X-Roles': 'admin, monitoring-delegate'}
     cross_tennant_id = '2106b2c8da0eecdb3df4ea84a0b5624b'
     fields = {'tenant_id': cross_tennant_id}
     response = self._run_and_wait(sid,
                                   message,
                                   headers=headers,
                                   fields=fields)
     self.assertThat(response[0]['_source']['tenant'],
                     matchers.StartsWith(cross_tennant_id))
コード例 #18
0
 def test_preversion_too_low_semver_headers(self):
     # That is, the target version is either already released or not high
     # enough for the semver requirements given api breaks etc.
     self.repo.commit()
     self.repo.tag('1.2.3')
     self.repo.commit('sem-ver: feature')
     # Note that we can't target 1.2.4, the feature header means we need
     # to be working on 1.3.0 or above.
     err = self.assertRaises(
         ValueError, packaging._get_version_from_git, '1.2.4')
     self.assertThat(err.args[0], matchers.StartsWith('git history'))
コード例 #19
0
    def test_delete(self):
        with self.app.test_client() as c:
            self.get_computehosts.return_value = fake_computehost(
                id=self.host_id)

            res = c.delete('/v1/{0}'.format(self.host_id),
                           headers=self.headers)
            res_id = res.headers.get(id.HTTP_RESP_HEADER_REQUEST_ID)
            self.assertEqual(204, res.status_code)
            self.assertIn(id.HTTP_RESP_HEADER_REQUEST_ID, res.headers)
            self.assertThat(res_id, matchers.StartsWith('req-'))
コード例 #20
0
 def test_preversion_too_low_simple(self):
     # That is, the target version is either already released or not high
     # enough for the semver requirements given api breaks etc.
     self.repo.commit()
     self.repo.tag('1.2.3')
     self.repo.commit()
     # Note that we can't target 1.2.3 anymore - with 1.2.3 released we
     # need to be working on 1.2.4.
     err = self.assertRaises(
         ValueError, packaging._get_version_from_git, '1.2.3')
     self.assertThat(err.args[0], matchers.StartsWith('git history'))
コード例 #21
0
 def test_send_cross_project(self):
     sid, message = base.generate_small_message()
     headers = {'X-Roles': 'admin, monitoring-delegate'}
     cross_tennant_id = '2106b2c8da0eecdb3df4ea84a0b5624b'
     fields = {'project_id': cross_tennant_id}
     response = self._run_and_wait(sid, message, headers=headers, fields=fields)
     log_msg = response[0]
     for key in CONF.monitoring.log_project_id_path:
         log_msg = log_msg.pop(key)
     self.assertThat(log_msg,
                     matchers.StartsWith(cross_tennant_id))
コード例 #22
0
    def test_generate_request_id(self):
        @webob.dec.wsgify
        def application(req):
            return req.environ[request_id.ENV_REQUEST_ID]

        app = request_id.RequestId(application)
        req = webob.Request.blank('/test')
        res = req.get_response(app)
        res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)
        self.assertThat(res_req_id, matchers.StartsWith(b'req-'))
        # request-id in request environ is returned as response body
        self.assertEqual(res_req_id, res.body)
コード例 #23
0
    def test_actions(self):
        """Test that information on actions can be invoked on each MuranoPL
        object are persisted into object header ('?' key) during serialization
        of Objects section of Object Model

        """
        serialized = self._runner.serialized_model
        self.assertIsInstance(serialized['Objects']['?'].get('_actions'), dict)
        for action in serialized['Objects']['?']['_actions'].values():
            self.assertIsInstance(action.get('enabled'), bool)
            self.assertIsInstance(action.get('name'), types.StringTypes)
            self.assertThat(action['name'], matchers.StartsWith('test'))
コード例 #24
0
    def test_generate_request_id(self):
        @webob.dec.wsgify
        def application(req):
            return req.environ[ENV_REQUEST_ID]

        app = compute_req_id.ComputeReqIdMiddleware(application)
        req = webob.Request.blank('/test')
        req_id = context.generate_request_id()
        req.environ[ENV_REQUEST_ID] = req_id
        res = req.get_response(app)

        res_id = res.headers.get(compute_req_id.HTTP_RESP_HEADER_REQUEST_ID)
        self.assertThat(res_id, matchers.StartsWith('req-'))
        self.assertEqual(res_id.encode('utf-8'), res.body)
コード例 #25
0
 def test_neutron_context_create(self):
     ctx = context.Context('user_id', 'tenant_id')
     self.assertEqual('user_id', ctx.user_id)
     self.assertEqual('tenant_id', ctx.project_id)
     self.assertEqual('tenant_id', ctx.tenant_id)
     request_id = ctx.request_id
     if isinstance(request_id, bytes):
         request_id = request_id.decode('utf-8')
     self.assertThat(request_id, matchers.StartsWith('req-'))
     self.assertEqual('user_id', ctx.user)
     self.assertEqual('tenant_id', ctx.tenant)
     self.assertIsNone(ctx.user_name)
     self.assertIsNone(ctx.tenant_name)
     self.assertIsNone(ctx.auth_token)
コード例 #26
0
 def _assert_response(self,
                      actual_resp,
                      expected_status_code,
                      expected_resp_body,
                      key='lease',
                      expected_api_version='reservation 1.0'):
     res_id = actual_resp.headers.get(id.HTTP_RESP_HEADER_REQUEST_ID)
     api_version = actual_resp.headers.get(
         api_version_request.API_VERSION_REQUEST_HEADER)
     self.assertIn(id.HTTP_RESP_HEADER_REQUEST_ID, actual_resp.headers)
     self.assertIn(api_version_request.API_VERSION_REQUEST_HEADER,
                   actual_resp.headers)
     self.assertIn(api_version_request.VARY_HEADER, actual_resp.headers)
     self.assertThat(res_id, matchers.StartsWith('req-'))
     self.assertEqual(expected_status_code, actual_resp.status_code)
     self.assertEqual(expected_resp_body, actual_resp.get_json()[key])
     self.assertEqual(expected_api_version, api_version)
     self.assertEqual(
         'OpenStack-API-Version',
         actual_resp.headers.get(api_version_request.VARY_HEADER))
コード例 #27
0
    def test_stack_trace(self):
        self._runner.preserve_exception = True
        e = self.assertRaises(
            dsl_exception.MuranoPlException,
            self._runner.testStackTrace)
        call_stack = e.format()
        self.assertThat(
            call_stack,
            matchers.StartsWith(
                'exceptions.LookupError: just random Python exception'))

        self.assertIsInstance(e.original_exception, LookupError)

        filename, line = e.original_exception._position
        self.assertThat(
            call_stack,
            matchers.MatchesRegex(
                r'.*^  File \".*ExceptionHandling\.yaml\", '
                r'line \d+:\d+ in method testStackTrace .*'
                r'of class ExceptionHandling$.*'
                r'^  File \".*{0}\", line {1} '
                r'in method exception_func$.*'.format(filename, line),
                re.MULTILINE | re.DOTALL))
コード例 #28
0
 def assert_starts_with(self, expected_prefix, observed_str, msg=None):
     self.assertThat(observed_str, matchers.StartsWith(expected_prefix),
                     msg)
コード例 #29
0
 def _test_validate_exception(self, profile, expected_msg):
     e = self.assertRaises(q_exc.InvalidInput,
                           self.plugin._validate_portinfo, profile)
     self.assertThat(str(e), matchers.StartsWith(expected_msg))
コード例 #30
0
 def test_untagged_version_after_rc_has_dev_version_preversion(self):
     self.repo.commit()
     self.repo.tag('1.2.3.0a1')
     self.repo.commit()
     version = packaging._get_version_from_git('1.2.3')
     self.assertThat(version, matchers.StartsWith('1.2.3.0a2.dev1'))