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


Python httpretty.enable方法代码示例

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


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

示例1: setup

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setup(self):
        httpretty.enable()

        self.key = RSAKey(kid='testkey').load(os.path.join(FIXTURE_ROOT, 'testkey.pem'))
        def jwks(_request, _uri, headers):  # noqa: E306
            ks = KEYS()
            ks.add(self.key.serialize())
            return 200, headers, ks.dump_jwks()
        httpretty.register_uri(
            httpretty.GET, oidc_rp_settings.PROVIDER_JWKS_ENDPOINT, status=200, body=jwks)
        httpretty.register_uri(
            httpretty.POST, oidc_rp_settings.PROVIDER_TOKEN_ENDPOINT,
            body=json.dumps({
                'id_token': self.generate_jws(), 'access_token': 'accesstoken',
                'refresh_token': 'refreshtoken', }),
            content_type='text/json')
        httpretty.register_uri(
            httpretty.GET, oidc_rp_settings.PROVIDER_USERINFO_ENDPOINT,
            body=json.dumps({'sub': '1234', 'email': 'test@example.com', }),
            content_type='text/json')

        yield

        httpretty.disable() 
开发者ID:impak-finance,项目名称:django-oidc-rp,代码行数:26,代码来源:test_backends.py

示例2: setUp

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self):
        """
        Initialize the configuration
        """

        Cache.last_updated[APIURL] = {'__oldest': '2016-12-18T11:49:37Z'}
        httpretty.reset()
        httpretty.enable(allow_net_connect=False)

        oscrc = os.path.join(FIXTURES, 'oscrc')
        osc.core.conf.get_config(override_conffile=oscrc,
                                 override_no_keyring=True,
                                 override_no_gnome_keyring=True)
        #osc.conf.config['debug'] = 1
        #osc.conf.config['http_debug'] = 1

        logging.basicConfig()
        self.logger = logging.getLogger(__file__)
        self.logger.setLevel(logging.DEBUG)

        self.checker = FactorySourceChecker(apiurl = APIURL,
                user = 'factory-source',
                logger = self.logger)
        self.checker.override_allow = False # Test setup cannot handle. 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:26,代码来源:factory_source_tests.py

示例3: setUp

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self):
        """
        Initialize the configuration
        """

        httpretty.reset()
        httpretty.enable()

        oscrc = os.path.join(FIXTURES, 'oscrc')
        osc.core.conf.get_config(override_conffile=oscrc,
                                 override_no_keyring=True,
                                 override_no_gnome_keyring=True)
        #osc.conf.config['debug'] = 1

        logging.basicConfig()
        self.logger = logging.getLogger(__file__)
        self.logger.setLevel(logging.DEBUG)

        self.checker = MaintenanceChecker(apiurl = APIURL,
                user = 'maintbot',
                logger = self.logger)
        self.checker.override_allow = False # Test setup cannot handle. 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:24,代码来源:maintenance_tests.py

示例4: configure_httpretty

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def configure_httpretty(sitedir):
    httpretty.enable()
    dir = Path(f"tests/test_sites/data/test_{sitedir}/")
    data_file = dir / 'data.json'

    data = None
    with open(data_file) as f:
        data = json.load(f)

    for obj in data:
        method = httpretty.POST
        if obj['method'] == 'GET':
            method = httpretty.GET
        with open(dir / obj['file']) as f:
            httpretty.register_uri(
                method,
                obj['url'],
                f.read(),
            ) 
开发者ID:vn-ki,项目名称:anime-downloader,代码行数:21,代码来源:site.py

示例5: endpoints

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def endpoints():
    httpretty.enable()
    with open(os.path.join(TESTS_DIR, 'endpoints.json')) as resource:
        test_data = json.load(resource)

    endpoints = test_data['endpoints']

    for endpoint, options in endpoints.items():
        if isinstance(options.get('body'), (dict, list, tuple)):
            body = json.dumps(options.get('body'))
        else:
            body = options.get('body')

        httpretty.register_uri(method=options.get('method', 'GET'),
                               status=options.get('status', 200),
                               uri=API_URL + endpoint,
                               body=body)
    yield endpoints
    httpretty.disable() 
开发者ID:tortilla,项目名称:tortilla,代码行数:21,代码来源:conftest.py

示例6: setUp

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self):
        httpretty.enable()
        httpretty.register_uri(
            httpretty.GET, "http://test.gf/users",
            body=ujson.dumps([
                sam_profile,
                jack_profile,
            ]),
            content_type="application/json"
        )
        httpretty.register_uri(
            httpretty.GET, "http://test.gf/blog/sam",
            body=ujson.dumps(sams_articles),
            content_type="application/json"
        )
        httpretty.register_uri(
            httpretty.GET, "http://test.gf/blog/jack",
            body=ujson.dumps(jacks_articles),
            content_type="application/json"
        ) 
开发者ID:chihongze,项目名称:girlfriend,代码行数:22,代码来源:crawl.py

示例7: setUp

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self) -> None:
        # https://github.com/gabrielfalcao/HTTPretty/issues/368
        import warnings
        warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*")
        warnings.filterwarnings("ignore", category=PendingDeprecationWarning, message="isAlive*")

        httpretty.enable()
        httpretty.reset()

        conf = influxdb_client.configuration.Configuration()
        conf.host = "http://localhost"
        conf.debug = False

        self.influxdb_client = InfluxDBClient(url=conf.host, token="my-token")

        self.write_options = WriteOptions(batch_size=2, flush_interval=5_000, retry_interval=3_000)
        self._write_client = WriteApi(influxdb_client=self.influxdb_client, write_options=self.write_options) 
开发者ID:influxdata,项目名称:influxdb-client-python,代码行数:19,代码来源:test_WriteApiBatching.py

示例8: test_config_zipa

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def test_config_zipa():
    t.config.host = 'random'
    t.config.prefix = 'prefix'
    t.config.append_slash = True
    t.config.secure = False
    t.config.headers = {
        'x-custom-header': 'custom-value'
    }

    assert t.config['host'] == 'random'
    assert t.config['prefix'] == 'prefix'
    assert t.config['append_slash']
    assert t.config['headers']['x-custom-header'] == 'custom-value'

    httpretty.enable()
    httpretty.register_uri(httpretty.GET, 'http://randomprefix/a/', status=200,
                           content_type='application/json', body=u'{"name": "a"}')

    assert t.a().name == 'a'
    assert httpretty.last_request().headers['x-custom-header'] == 'custom-value' 
开发者ID:presslabs,项目名称:zipa,代码行数:22,代码来源:test_config.py

示例9: setUp

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self):
        httpretty.enable()

        self.geocoder = OpenCageGeocode('abcde') 
开发者ID:OpenCageData,项目名称:python-opencage-geocoder,代码行数:6,代码来源:tests.py

示例10: setup

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setup(self):
        httpretty.enable()

        self.key = RSAKey(kid='testkey').load(os.path.join(FIXTURE_ROOT, 'testkey.pem'))
        def jwks(_request, _uri, headers):  # noqa: E306
            ks = KEYS()
            ks.add(self.key.serialize())
            return 200, headers, ks.dump_jwks()
        httpretty.register_uri(
            httpretty.GET, oidc_rp_settings.PROVIDER_JWKS_ENDPOINT, status=200, body=jwks)

        yield

        httpretty.disable() 
开发者ID:impak-finance,项目名称:django-oidc-rp,代码行数:16,代码来源:test_utils.py

示例11: test_request_timeout

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def test_request_timeout():
    timeout = 0.1
    http_scheme = "http"
    host = "coordinator"
    port = 8080
    url = http_scheme + "://" + host + ":" + str(port) + constants.URL_STATEMENT_PATH

    def long_call(request, uri, headers):
        time.sleep(timeout * 2)
        return (200, headers, "delayed success")

    httpretty.enable()
    for method in [httpretty.POST, httpretty.GET]:
        httpretty.register_uri(method, url, body=long_call)

    # timeout without retry
    for request_timeout in [timeout, (timeout, timeout)]:
        req = PrestoRequest(
            host=host,
            port=port,
            user="test",
            http_scheme=http_scheme,
            max_attempts=1,
            request_timeout=request_timeout,
        )

        with pytest.raises(requests.exceptions.Timeout):
            req.get(url)

        with pytest.raises(requests.exceptions.Timeout):
            req.post("select 1")

    httpretty.disable()
    httpretty.reset() 
开发者ID:prestosql,项目名称:presto-python-client,代码行数:36,代码来源:test_client.py

示例12: patch_get

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def patch_get():
    httpretty.enable()
    yield partial(httpretty.register_uri, httpretty.GET)
    httpretty.disable()
    httpretty.reset() 
开发者ID:frictionlessdata,项目名称:datapackage-py,代码行数:7,代码来源:test_resource.py

示例13: test_it_works_with_remote_files

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def test_it_works_with_remote_files(datapackage_zip):
    httpretty.enable()
    datapackage_zip.seek(0)
    url = 'http://someplace.com/datapackage.zip'
    httpretty.register_uri(
        httpretty.GET, url, body=datapackage_zip.read(), content_type='application/zip')
    package = Package(url)
    assert package.descriptor['name'] == 'proverbs'
    assert len(package.resources) == 1
    assert package.resources[0].data == b'foo\n'
    httpretty.disable() 
开发者ID:frictionlessdata,项目名称:datapackage-py,代码行数:13,代码来源:test_package.py

示例14: setUp

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self):
        """Set up the test case."""
        super(APIWithIDsTestCase, self).setUp()
        self.base_uri = self.get_api_url('{}/'.format(self.endpoint))
        self.client_class = getattr(self.client, self.endpoint)()
        httpretty.enable() 
开发者ID:edx,项目名称:edx-analytics-data-api-client,代码行数:8,代码来源:__init__.py

示例15: setUp

# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self):
        super(ModulesTests, self).setUp()
        httpretty.enable()

        self.course_id = 'edX/TestX/TestCourse'
        self.module_id = 'i4x://TestCourse/block1/module2/abcd1234'

        self.module = self.client.modules(self.course_id, self.module_id) 
开发者ID:edx,项目名称:edx-analytics-data-api-client,代码行数:10,代码来源:test_module.py


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