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


Python httpretty.activate方法代码示例

本文整理汇总了Python中httpretty.activate方法的典型用法代码示例。如果您正苦于以下问题:Python httpretty.activate方法的具体用法?Python httpretty.activate怎么用?Python httpretty.activate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在httpretty的用法示例。


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

示例1: mock_response

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import activate [as 别名]
def mock_response(method, uri, data, errors=None, warnings=None, pagination=None):
    def wrapper(fn):
        @six.wraps(fn)
        @hp.activate
        def inner(*args, **kwargs):
            body = {'data': data}
            if errors is not None:
                body['errors'] = errors
            if warnings is not None:
                body['warnings'] = warnings
            if pagination is not None:
                body['pagination'] = pagination
            hp.reset()
            hp.register_uri(method, re.compile('.*' + uri + '$'), json.dumps(body))
            return fn(*args, **kwargs)
        return inner
    return wrapper 
开发者ID:coinbase,项目名称:coinbase-python,代码行数:19,代码来源:helpers.py

示例2: mock_course_api

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import activate [as 别名]
def mock_course_api(self, url, body=None, **kwargs):
        """
        Registers an HTTP mock for the specified course API path. The mock returns the specified data.

        The calling test function MUST activate httpretty.

        Arguments
            url     --  URL to be mocked
            body    --  Data returned by the mocked API
            kwargs  --  Additional arguments passed to httpretty.register_uri()
        """

        # Avoid developer confusion when httpretty is not active and fail the test now.
        if not httpretty.is_enabled():
            self.fail('httpretty is not enabled. The mock will not be used!')

        body = body or {}
        default_kwargs = {
            'body': kwargs.get('body', json.dumps(body)),
            'content_type': 'application/json'
        }
        default_kwargs.update(kwargs)

        httpretty.register_uri(httpretty.GET, url, **default_kwargs)
        logger.debug('Mocking Course API URL: %s', url) 
开发者ID:edx,项目名称:edx-analytics-dashboard,代码行数:27,代码来源:__init__.py

示例3: test_activate_ime_engine

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import activate [as 别名]
def test_activate_ime_engine(self):
        driver = android_w3c_driver()
        httpretty.register_uri(
            httpretty.POST,
            appium_command('/session/1234567890/ime/activate'),
        )
        engine = 'com.android.inputmethod.latin/.LatinIME'
        assert isinstance(driver.activate_ime_engine(engine), WebDriver)

        d = get_httpretty_request_body(httpretty.last_request())
        assert d['engine'] == 'com.android.inputmethod.latin/.LatinIME' 
开发者ID:appium,项目名称:python-client,代码行数:13,代码来源:ime_test.py

示例4: off_test_load_orgs

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import activate [as 别名]
def off_test_load_orgs(self):
        """ Test loading of orgs in SH """
        setup_http_server()

        config = Config(CONF_FILE)
        task = TaskIdentitiesLoad(config)
        task.execute()
        # Check the number of orgs loaded
        norgs = len(api.registry(self.sh_db))
        self.assertEqual(norgs, 20)

    # @httpretty.activate
    # TODO: remote loading 
开发者ID:chaoss,项目名称:grimoirelab-sirmordred,代码行数:15,代码来源:test_task_identities.py

示例5: test_remove_cname_return_true_when_can_remove

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import activate [as 别名]
def test_remove_cname_return_true_when_can_remove(self):
    httpretty.register_uri(httpretty.DELETE, 'http://tsuruhost.com/apps/xpto/cname',
                           data='cname=cname1&cname=cname2',
                           status=200)

    self.assertTrue(self.bg.remove_cname('xpto', self.cnames))

    @httpretty.activate
    def test_remove_cname_return_false_when_cant_remove(self):
      httpretty.register_uri(httpretty.DELETE, 'http://tsuruhost.com/apps/xpto/cname',
                             data='cname=cname1&cname=cname2',
                             status=500)

      self.assertFalse(self.bg.remove_cname('xpto', self.cnames))

    @httpretty.activate
    def test_set_cname_return_true_when_can_set(self):
      httpretty.register_uri(httpretty.POST, 'http://tsuruhost.com/apps/xpto/cname',
                             data='cname=cname1&cname=cname2',
                             status=200)

      self.assertTrue(self.bg.set_cname('xpto', self.cnames))

    @httpretty.activate
    def test_set_cname_return_false_when_cant_set(self):
      httpretty.register_uri(httpretty.POST, 'http://tsuruhost.com/apps/xpto/cname',
                             data='cname=cname1&cname=cname2',
                             status=500)

      self.assertFalse(self.bg.set_cname('xpto', self.cnames)) 
开发者ID:emerleite,项目名称:tsuru-bluegreen,代码行数:32,代码来源:bluegreen_test.py

示例6: test_inactive_user_email_domain_restricted_coupon_redemption

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import activate [as 别名]
def test_inactive_user_email_domain_restricted_coupon_redemption(self):
        """
        Verify that a user must activate their account before being allowed
        to redeem an email domain-restricted coupon.
        """
        self.mock_account_api(self.request, self.user.username, data={'is_active': False})
        self.mock_access_token_response()
        email_domain = self.user.email.split('@')[1]
        self.create_coupon(catalog=self.catalog, code=COUPON_CODE, benefit_value=5, email_domains=email_domain)

        response = self.client.get(self.redeem_url_with_params())
        self.assert_redirected_to_email_confirmation(response) 
开发者ID:edx,项目名称:ecommerce,代码行数:14,代码来源:test_views.py

示例7: setUp

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import activate [as 别名]
def setUp(self):
        super(ProgramOfferUpdateViewTests, self).setUp()
        self.program_offer = factories.ProgramOfferFactory(partner=self.partner)
        self.path = reverse('programs:offers:edit', kwargs={'pk': self.program_offer.pk})

        # NOTE: We activate httpretty here so that we don't have to decorate every test method.
        httpretty.enable()
        self.mock_program_detail_endpoint(
            self.program_offer.condition.program_uuid, self.site_configuration.discovery_api_url
        ) 
开发者ID:edx,项目名称:ecommerce,代码行数:12,代码来源:test_views.py

示例8: setUp

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import activate [as 别名]
def setUp(self):
        super(EnterpriseOfferUpdateViewTests, self).setUp()
        self.enterprise_offer = factories.EnterpriseOfferFactory(partner=self.partner)
        self.path = reverse('enterprise:offers:edit', kwargs={'pk': self.enterprise_offer.pk})

        # NOTE: We activate httpretty here so that we don't have to decorate every test method.
        httpretty.enable()
        self.mock_specific_enterprise_customer_api(self.enterprise_offer.condition.enterprise_customer_uuid) 
开发者ID:edx,项目名称:ecommerce,代码行数:10,代码来源:test_views.py

示例9: test_activate_user

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import activate [as 别名]
def test_activate_user(self):
        httpretty.register_uri(
            httpretty.POST,
            BaseApiHandler.build_url(
                self.api_config.base_url,
                '/users',
                'activate',
                'test-username'
            ),
            content_type='application/json',
            status=200)

        response = self.api_handler.activate_user('test-username')
        assert response.status_code == 200 
开发者ID:polyaxon,项目名称:polyaxon-client,代码行数:16,代码来源:test_user.py

示例10: test_access_to_oauth_resource_post_grade_fail

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import activate [as 别名]
def test_access_to_oauth_resource_post_grade_fail(self):
        """
        Check post_grade functionality fails on invalid response.
        """
        # pylint: disable=maybe-no-member
        uri = (u'https://example.edu/courses/MITx/ODL_ENG/2014_T1/xblock/'
               u'i4x:;_;_MITx;_ODL_ENG;_lti;'
               u'_94173d3e79d145fd8ec2e83f15836ac8/handler_noauth'
               u'/grade_handler')

        def request_callback(request, cburi, headers):
            # pylint: disable=unused-argument
            """
            Mock error response callback.
            """
            return 200, headers, "wrong_response"

        httpretty.register_uri(httpretty.POST, uri, body=request_callback)

        consumers = self.consumers
        url = 'https://localhost/post_grade/1.0?'
        new_url = self.generate_launch_request(consumers, url)
        ret = self.localGateway.handle_request(method='GET',
                                               path=new_url,
                                               headers={
                                                  'host': 'localhost',
                                                  'x-forwarded-proto': 'https'
                                               },
                                               body='')
        self.assertTrue(self.has_exception())
        self.assertEqual(ret['body'], "error")

    # DELETED: Not implemented. Sounds like an EdX edge case
    # @httpretty.activate
    # def test_access_to_oauth_resource_post_grade_fix_url(self):
    #     """
    #     Make sure URL remap works for edX vagrant stack.
    #     """
    #     # pylint: disable=maybe-no-member
    #     uri = 'https://localhost:8000/dev_stack'

    #     httpretty.register_uri(httpretty.POST, uri,
    #                            body=self.request_callback)

    #     url = 'https://localhost/initial?'
    #     new_url = self.generate_launch_request(
    #         self.consumers, url, lit_outcome_service_url=uri
    #     )
    #     ret = self.app.get(new_url)
    #     self.assertFalse(self.has_exception())

    #     ret = self.app.get("/post_grade/1.0")
    #     self.assertFalse(self.has_exception())
    #     self.assertEqual(ret.data.decode('utf-8'), "grade=True")

    #     ret = self.app.get("/post_grade/2.0")
    #     self.assertFalse(self.has_exception())
    #     self.assertEqual(ret.data.decode('utf-8'), "grade=False") 
开发者ID:mitodl,项目名称:pylti,代码行数:60,代码来源:test_chalice.py


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