当前位置: 首页>>代码示例>>Python>>正文


Python client.get函数代码示例

本文整理汇总了Python中nailgun.client.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_positive_get_routes

    def test_positive_get_routes(self):
        """Issue an HTTP GET response to both available routes.

        :id: 9e40ea7f-71ea-4ced-94ba-cde03620c654

        :expectedresults: The same response is returned.

        Targets BZ 1132817.

        :CaseImportance: Critical
        """
        org = entities.Organization().create()
        entities.SyncPlan(organization=org).create()
        response1 = client.get(
            '{0}/katello/api/v2/sync_plans'.format(settings.server.get_url()),
            auth=settings.server.get_credentials(),
            data={'organization_id': org.id},
            verify=False,
        )
        response2 = client.get(
            '{0}/katello/api/v2/organizations/{1}/sync_plans'.format(
                settings.server.get_url(),
                org.id
            ),
            auth=settings.server.get_credentials(),
            verify=False,
        )
        for response in (response1, response2):
            response.raise_for_status()
        self.assertEqual(
            response1.json()['results'],
            response2.json()['results'],
        )
开发者ID:JacobCallahan,项目名称:robottelo,代码行数:33,代码来源:test_syncplan.py

示例2: test_get_routes

    def test_get_routes(self):
        """@Test: Issue an HTTP GET response to both available routes.

        @Assert: The same response is returned.

        @Feature: SyncPlan

        Targets BZ 1132817.

        """
        org = entities.Organization().create()
        entities.SyncPlan(organization=org).create()
        response1 = client.get(
            '{0}/katello/api/v2/sync_plans'.format(settings.server.get_url()),
            auth=settings.server.get_credentials(),
            data={'organization_id': org.id},
            verify=False,
        )
        response2 = client.get(
            '{0}/katello/api/v2/organizations/{1}/sync_plans'.format(
                settings.server.get_url(),
                org.id
            ),
            auth=settings.server.get_credentials(),
            verify=False,
        )
        for response in (response1, response2):
            response.raise_for_status()
        self.assertEqual(
            response1.json()['results'],
            response2.json()['results'],
        )
开发者ID:cpeters,项目名称:robottelo,代码行数:32,代码来源:test_syncplan.py

示例3: get_organization

def get_organization(server_config, label):
    """Return the organization object with label ``label``.

    This function is necessary because NailGun does not yet have a mixin
    facilitating entity searches.

    :param nailgun.config.ServerConfig server_config: This object defines which
        server will be searched, what credentials will be used when searching
        and so on.
    :param label: A string label that will be used when searching. Every
        organization should have a unique label.
    :returns: An ``Organization`` object.

    """
    response = client.get(
        Organization(server_config).path(),
        data={'search': 'label={}'.format(label)},
        **server_config.get_client_kwargs()
    )
    response.raise_for_status()
    decoded = response.json()
    if decoded['subtotal'] != 1:
        print(
            'Expected to find one organization, but instead found {0}. Search '
            'results: {1}'.format(decoded['subtotal'], decoded['results'])
        )
        exit(1)
    return Organization(
        server_config,
        id=decoded['results'][0]['id']
    ).read()
开发者ID:kbidarkar,项目名称:nailgun,代码行数:31,代码来源:create_user_nailgun.py

示例4: _search

    def _search(self, entity, query, auth=None):
        """Performs a GET ``api/v2/<entity>`` and specify the ``search``
        parameter.

        :param entity: A ``nailgun.entity_mixins.Entity`` object.
        :param string query: A ``search`` parameter.
        :param tuple auth: A ``tuple`` containing the credentials to be used
            for authentication when accessing the API. If ``None``,
            credentials are automatically read from
            :func:`robottelo.common.helpers.get_server_credentials`.
        :return: A ``list`` of found entity dicts or an empty list if nothing
            found
        :rtype: list

        """
        # Use the server credentials if None are provided
        if auth is None:
            auth = get_server_credentials()

        path = entity().path()
        response = client.get(
            path,
            auth=auth,
            data={u'search': query},
            verify=False,
        )
        response.raise_for_status()
        return response.json()['results']
开发者ID:oshtaier,项目名称:robottelo,代码行数:28,代码来源:test_api_smoke.py

示例5: test_ping

    def test_ping(self):
        """@Test: Check if all services are running

        @Feature: Smoke Test

        @Assert: Overall and individual services status should be 'ok'.

        """
        response = client.get(
            entities.Ping().path(),
            auth=get_server_credentials(),
            verify=False,
        )
        response.raise_for_status()
        self.assertEqual(response.json()['status'], u'ok')  # overall status

        # Check that all services are OK. ['services'] is in this format:
        #
        # {u'services': {
        #    u'candlepin': {u'duration_ms': u'40', u'status': u'ok'},
        #    u'candlepin_auth': {u'duration_ms': u'41', u'status': u'ok'},
        #    …
        # }, u'status': u'ok'}
        services = response.json()['services']
        self.assertTrue(
            all([service['status'] == u'ok' for service in services.values()]),
            u"Not all services seem to be up and running!"
        )
开发者ID:oshtaier,项目名称:robottelo,代码行数:28,代码来源:test_api_smoke.py

示例6: test_positive_get_status_code

    def test_positive_get_status_code(self):
        """GET an entity-dependent path.

        :id: 89e4fafe-7780-4be4-acc1-90f7c02a8530

        :expectedresults: HTTP 200 is returned with an ``application/json``
            content-type

        :CaseImportance: Critical
        """
        exclude_list = (
            entities.ActivationKey,  # need organization_id or environment_id
            entities.ContentView,  # need organization_id
            entities.GPGKey,  # need organization_id
            entities.HostCollection,  # need organization_id
            entities.LifecycleEnvironment,  # need organization_id
            entities.Product,  # need organization_id
            entities.Repository,  # need organization_id
        )
        for entity_cls in set(valid_entities()) - set(exclude_list):
            with self.subTest(entity_cls):
                self.logger.info('test_get_status_code arg: %s', entity_cls)
                skip_if_sam(self, entity_cls)
                response = client.get(
                    entity_cls().path(),
                    auth=settings.server.get_credentials(),
                    verify=False,
                )
                response.raise_for_status()
                self.assertEqual(http_client.OK, response.status_code)
                self.assertIn(
                    'application/json',
                    response.headers['content-type']
                )
开发者ID:BlackSmith,项目名称:robottelo,代码行数:34,代码来源:test_multiple_paths.py

示例7: test_get_status_code

    def test_get_status_code(self):
        """@Test: GET an entity-dependent path.

        @Feature: Test multiple API paths

        @Assert: HTTP 200 is returned with an ``application/json`` content-type

        """
        exclude_list = (
            entities.ActivationKey,  # need organization_id or environment_id
            entities.ContentView,  # need organization_id
            entities.GPGKey,  # need organization_id
            entities.HostCollection,  # need organization_id
            entities.LifecycleEnvironment,  # need organization_id
            entities.Product,  # need organization_id
            entities.Repository,  # need organization_id
            entities.System,  # need organization_id
        )
        for entity_cls in set(valid_entities()) - set(exclude_list):
            with self.subTest(entity_cls):
                logger.debug('test_get_status_code arg: %s', entity_cls)
                skip_if_sam(self, entity_cls)
                response = client.get(
                    entity_cls().path(),
                    auth=get_server_credentials(),
                    verify=False,
                )
                response.raise_for_status()
                self.assertEqual(httplib.OK, response.status_code)
                self.assertIn(
                    'application/json',
                    response.headers['content-type']
                )
开发者ID:lpramuk,项目名称:robottelo,代码行数:33,代码来源:test_multiple_paths.py

示例8: test_get_releases_status_code

    def test_get_releases_status_code(self):
        """@Test: Get an activation key's releases. Check response format.

        @Assert: HTTP 200 is returned with an ``application/json`` content-type

        @Feature: ActivationKey

        """
        try:
            attrs = entities.ActivationKey().create()
        except HTTPError as err:
            self.fail(err)
        path = entities.ActivationKey(id=attrs['id']).path(which='releases')
        response = client.get(
            path,
            auth=get_server_credentials(),
            verify=False,
        )
        status_code = httplib.OK
        self.assertEqual(
            status_code,
            response.status_code,
            status_code_error(path, status_code, response),
        )
        self.assertIn('application/json', response.headers['content-type'])
开发者ID:oshtaier,项目名称:robottelo,代码行数:25,代码来源:test_activationkey.py

示例9: test_negative_get_unauthorized

    def test_negative_get_unauthorized(self):
        """GET an entity-dependent path without credentials.

        :id: 49127c71-55a2-42d1-b418-59229e9bad00

        :expectedresults: HTTP 401 is returned

        :CaseImportance: Critical
        """
        exclude_list = (
            entities.ActivationKey,  # need organization_id or environment_id
        )
        test_entities = self.get_entities_for_unauthorized(
            valid_entities(), exclude_list)
        for entity_cls in test_entities:
            with self.subTest(entity_cls):
                self.logger.info('test_get_unauthorized arg: %s', entity_cls)
                skip_if_sam(self, entity_cls)
                response = client.get(
                    entity_cls().path(),
                    auth=(),
                    verify=False
                )
                self.assertEqual(
                    http_client.UNAUTHORIZED, response.status_code)
开发者ID:JacobCallahan,项目名称:robottelo,代码行数:25,代码来源:test_multiple_paths.py

示例10: test_get_links

    def test_get_links(self):
        """@Test: GET ``api/v2`` and check the links returned.

        @Feature: API

        @Assert: The paths returned are equal to ``API_PATHS``.

        """
        # Did the server give us any paths at all?
        response = client.get(self.path, auth=helpers.get_server_credentials(), verify=False)
        response.raise_for_status()
        # See below for an explanation of this transformation.
        api_paths = response.json()["links"]
        for group, path_pairs in api_paths.items():
            api_paths[group] = path_pairs.values()

        if bz_bug_is_open(1166875):
            # The server returns incorrect paths.
            api_paths["docker_images"].append(u"/katello/api/docker_images")
            api_paths["docker_images"].remove(u"/katello/api/compare")
            api_paths["docker_tags"].append(u"/katello/api/docker_tags")
            api_paths["docker_tags"].remove(u"/katello/api/compare")
            api_paths["errata"].append(u"/katello/api/errata")
            api_paths["errata"].append(u"/katello/api/errata/compare")
            api_paths["errata"].remove(u"/katello/api/compare")

        self.assertEqual(frozenset(api_paths.keys()), frozenset(API_PATHS.keys()))
        for group in api_paths.keys():
            self.assertItemsEqual(api_paths[group], API_PATHS[group], group)
开发者ID:ares,项目名称:robottelo,代码行数:29,代码来源:test_api_smoke.py

示例11: test_positive_get_links

    def test_positive_get_links(self):
        """GET ``api/v2`` and check the links returned.

        :id: 7b2dd77a-a821-485b-94db-b583f93c9a89

        :expectedresults: The paths returned are equal to ``API_PATHS``.

        """
        # Did the server give us any paths at all?
        response = client.get(
            self.path,
            auth=settings.server.get_credentials(),
            verify=False,
        )
        response.raise_for_status()
        # See below for an explanation of this transformation.
        api_paths = response.json()['links']
        for group, path_pairs in api_paths.items():
            api_paths[group] = list(path_pairs.values())

        self.assertEqual(
            frozenset(api_paths.keys()),
            frozenset(API_PATHS.keys())
        )
        for group in api_paths.keys():
            self.assertItemsEqual(api_paths[group], API_PATHS[group], group)
开发者ID:BlackSmith,项目名称:robottelo,代码行数:26,代码来源:test_api_endtoend.py

示例12: test_subscribe_system_to_cv

    def test_subscribe_system_to_cv(self):
        """@Test: Subscribe a system to a content view.

        @Feature: ContentView

        @Assert: It is possible to create a system and set its
        'content_view_id' attribute.

        """
        # organization
        # ├── lifecycle environment
        # └── content view
        org = entities.Organization()
        org.id = org.create()['id']
        lifecycle_env = entities.LifecycleEnvironment(organization=org.id)
        lifecycle_env.id = lifecycle_env.create()['id']
        content_view = entities.ContentView(organization=org.id)
        content_view.id = content_view.create()['id']

        # Publish the content view.
        response = content_view.publish()
        humanized_errors = response['humanized']['errors']
        _check_bz_1186432(humanized_errors)
        self.assertEqual(response['result'], 'success', humanized_errors)

        # Get the content view version's ID.
        response = client.get(
            entities.ContentViewVersion().path(),
            auth=get_server_credentials(),
            data={u'content_view_id': content_view.id},
            verify=False,
        )
        response.raise_for_status()
        results = response.json()['results']
        self.assertEqual(len(results), 1)
        cv_version = entities.ContentViewVersion(id=results[0]['id'])

        # Promote the content view version.
        response = cv_version.promote(environment_id=lifecycle_env.id)
        humanized_errors = response['humanized']['errors']
        _check_bz_1186432(humanized_errors)
        self.assertEqual('success', response['result'], humanized_errors)

        # Create a system that is subscribed to the published and promoted
        # content view. Associating this system with the organization and
        # environment created above is not particularly important, but doing so
        # means a shorter test where fewer entities are created, as
        # System.organization and System.environment are required attributes.
        system_attrs = entities.System(
            content_view=content_view.id,
            environment=lifecycle_env.id,
            organization=org.id,
        ).create()

        # See BZ #1151240
        self.assertEqual(system_attrs['content_view_id'], content_view.id)
        self.assertEqual(system_attrs['environment']['id'], lifecycle_env.id)
        self.assertEqual(system_attrs['organization_id'], org.id)
开发者ID:oshtaier,项目名称:robottelo,代码行数:58,代码来源:test_contentview.py

示例13: _poll_task

def _poll_task(task_id, server_config, poll_rate=None, timeout=None):
    """Implement :meth:`nailgun.entities.ForemanTask.poll`.

    See :meth:`nailgun.entities.ForemanTask.poll` for a full description of how
    this method acts. Other methods may also call this method, such as
    :meth:`nailgun.entity_mixins.EntityDeleteMixin.delete`.

    Certain mixins benefit from being able to poll the server after performing
    an operation. However, this module cannot use
    :meth:`nailgun.entities.ForemanTask.poll`, as that would be a circular
    import. Placing the implementation of
    :meth:`nailgun.entities.ForemanTask.poll` here allows both that method and
    the mixins in this module to use the same logic.

    """
    if poll_rate is None:
        poll_rate = TASK_POLL_RATE
    if timeout is None:
        timeout = TASK_TIMEOUT

    # Implement the timeout.
    def raise_task_timeout():
        """Raise a KeyboardInterrupt exception in the main thread."""
        thread.interrupt_main()
    timer = threading.Timer(timeout, raise_task_timeout)

    # Poll until the task finishes. The timeout prevents an infinite loop.
    try:
        timer.start()
        path = '{0}/foreman_tasks/api/tasks/{1}'.format(
            server_config.url,
            task_id
        )
        while True:
            response = client.get(path, **server_config.get_client_kwargs())
            response.raise_for_status()
            task_info = response.json()
            if task_info['state'] != 'running':
                break
            time.sleep(poll_rate)
    except KeyboardInterrupt:
        # raise_task_timeout will raise a KeyboardInterrupt when the timeout
        # expires. Catch the exception and raise TaskTimedOutError
        raise TaskTimedOutError('Timed out polling task {0}'.format(task_id))
    finally:
        timer.cancel()

    # Check for task success or failure.
    if task_info['result'] != 'success':
        raise TaskFailedError(
            'Task {0} completed with result {1}. Error message(s): {2}'.format(
                task_id,
                task_info['result'],
                task_info['humanized']['errors']
            )
        )
    return task_info
开发者ID:kbidarkar,项目名称:nailgun,代码行数:57,代码来源:entity_mixins.py

示例14: test_get_status_code

    def test_get_status_code(self):
        """@Test: GET ``api/v2`` and examine the response.

        @Feature: API

        @Assert: HTTP 200 is returned with an ``application/json`` content-type

        """
        response = client.get(self.path, auth=helpers.get_server_credentials(), verify=False)
        self.assertEqual(response.status_code, httplib.OK)
        self.assertIn("application/json", response.headers["content-type"])
开发者ID:ares,项目名称:robottelo,代码行数:11,代码来源:test_api_smoke.py

示例15: test_get_unauthorized

    def test_get_unauthorized(self, entity_cls):
        """@Test: GET an entity-dependent path without credentials.

        @Feature: Test multiple API paths

        @Assert: HTTP 401 is returned

        """
        logger.debug('test_get_unauthorized arg: %s', entity_cls)
        skip_if_sam(self, entity_cls)
        response = client.get(entity_cls().path(), auth=(), verify=False)
        self.assertEqual(httplib.UNAUTHORIZED, response.status_code)
开发者ID:oshtaier,项目名称:robottelo,代码行数:12,代码来源:test_multiple_paths.py


注:本文中的nailgun.client.get函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。