Python httpretty 模块,disable() 实例源码

我们从Python开源项目中,提取了以下31个代码示例,用于说明如何使用httpretty.disable()

项目:deb-python-httpretty    作者:openstack    | 项目源码 | 文件源码
def start_http_server(context):
    httpretty.disable()
    context.http_port = get_free_tcp_port()
    context.server = TornadoServer(context.http_port)
    context.server.start()
    ready = False
    timeout = 2
    started_at = time.time()
    while not ready:
        httpretty.disable()
        time.sleep(.1)
        try:
            requests.get('http://localhost:{0}/'.format(context.http_port))
            ready = True
        except:
            if time.time() - started_at >= timeout:
                break

    httpretty.enable()
项目:lecli    作者:rapid7    | 项目源码 | 文件源码
def teardown_httpretty():
    httpretty.disable()
    httpretty.reset()
项目:presto-python-client    作者:prestodb    | 项目源码 | 文件源码
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()
项目:girlfriend    作者:chihongze    | 项目源码 | 文件源码
def tearDown(self):
        os.remove("line_file.json")
        os.remove("array_file.json")
        os.remove("object_file.json")
        os.remove("block_file.json")
        httpretty.disable()
        httpretty.reset()
项目:girlfriend    作者:chihongze    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.disable()
        httpretty.reset()
项目:girlfriend    作者:chihongze    | 项目源码 | 文件源码
def tearDown(self):
        os.remove("test.csv")
        httpretty.disable()
        httpretty.reset()
项目:girlfriend    作者:chihongze    | 项目源码 | 文件源码
def cleanUp(self):
        httpretty.disable()
        httpretty.reset()
项目:desec-stack    作者:desec-io    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.reset()
        httpretty.disable()
项目:desec-stack    作者:desec-io    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.reset()
        httpretty.disable()
项目:desec-stack    作者:desec-io    | 项目源码 | 文件源码
def setUp(self):
        httpretty.reset()
        httpretty.disable()

        if not hasattr(self, 'owner'):
            self.owner = utils.createUser()
            self.ownedDomains = [utils.createDomain(self.owner), utils.createDomain(self.owner)]
            self.token = utils.createToken(user=self.owner)
            self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)

            self.otherOwner = utils.createUser()
            self.otherDomains = [utils.createDomain(self.otherOwner), utils.createDomain()]
            self.otherToken = utils.createToken(user=self.otherOwner)
项目:desec-stack    作者:desec-io    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.reset()
        httpretty.disable()
项目:desec-stack    作者:desec-io    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.reset()
        httpretty.disable()
项目:dati-ckan-docker    作者:italia    | 项目源码 | 文件源码
def _patched_get_content_and_type(self, url, harvest_job, page=1, content_type=None):

    httpretty.enable()

    value1, value2 = original_get_content_and_type(self, url, harvest_job, page, content_type)

    httpretty.disable()

    return value1, value2
项目:cloudstrype    作者:btimby    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.disable()
        httpretty.reset()
项目:cloudstrype    作者:btimby    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.disable()
        httpretty.reset()
项目:cloudstrype    作者:btimby    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.disable()
        httpretty.reset()
项目:simple-environment-monitor-system    作者:diegorubin    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.disable()
        httpretty.reset()
项目:simple-environment-monitor-system    作者:diegorubin    | 项目源码 | 文件源码
def test_alive(self):
        httpretty.enable()
        httpretty.register_uri(httpretty.GET, SERVICE_URL, body="LIVE")

        monitor = SocketPortMonitor(SERVICE_HOST, port=SERVICE_PORT);
        self.assertTrue(monitor.alive())

        httpretty.disable()
        httpretty.reset()
项目:simple-environment-monitor-system    作者:diegorubin    | 项目源码 | 文件源码
def test_check_alive(self):
        httpretty.enable()
        httpretty.register_uri(httpretty.GET, SERVICE_URL, body="LIVE")

        self.assertTrue(check_alive('SocketPortMonitor', SERVICE_HOST, port='8888'))

        httpretty.disable()
        httpretty.reset()
项目:simple-environment-monitor-system    作者:diegorubin    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.disable()
        httpretty.reset()
项目:postman-audit    作者:tylrd    | 项目源码 | 文件源码
def teardown_function(function):
    httpretty.disable()
项目:rakuten-ws    作者:alexandriagroup    | 项目源码 | 文件源码
def httpretty():
    httpretty_module.reset()
    httpretty_module.enable()
    yield httpretty_module
    httpretty_module.disable()
项目:concourse-resource-bitbucket    作者:Karunamon    | 项目源码 | 文件源码
def step_impl(context):
    d = context.bad_login
    assert d['source']['username'] != 'ValidUser'
    httpretty.enable()
    httpretty.register_uri(
            httpretty.POST,
            context.good_build_url,
            body='{"errors":[{"context":null,"message":"Authentication failed. Please check your credentials and try again.","exceptionName":"com.atlassian.bitbucket.auth.IncorrectPasswordAuthenticationException"}]}',
            status=401
    )
    from scripts.bitbucket import post_result, err
    result = post_result(context.good_build_url, d['source']['username'], d['source']['password'], False, good_status_dict(), True)
    assert result.status_code == 401
    httpretty.disable()
    httpretty.reset()
项目:concourse-resource-bitbucket    作者:Karunamon    | 项目源码 | 文件源码
def step_impl(context):
    d = context.good_login
    assert context.good_login['source']['username'] == 'ValidUser'
    httpretty.enable()
    httpretty.register_uri(
            httpretty.POST,
            context.bad_build_url,
            body='{"errors":[{"context":null,"message":"You are not permitted to access this resource","exceptionName":"com.atlassian.bitbucket.AuthorisationException"}]}',
            status=403
    )
    from scripts.bitbucket import post_result, err
    result = post_result(context.bad_build_url, d['source']['username'], d['source']['password'], False, good_status_dict(), True)
    assert result.status_code == 403
    httpretty.disable()
    httpretty.reset()
项目:evologger    作者:freeranger    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.disable()  # disable afterwards, so that you will have no problems in code that uses that socket module
        httpretty.reset()
项目:Startup-Fairy    作者:cs373gc-fall-2016    | 项目源码 | 文件源码
def tearDown(self):
        """Disable afterwards to let other code use that socket module"""

        httpretty.disable()
        httpretty.reset()

    # -----
    # About
    # -----
项目:ouroboros    作者:madedotcom    | 项目源码 | 文件源码
def cleanup_httpretty(self):
        httpretty.reset()
        httpretty.disable()
项目:deb-python-httpretty    作者:openstack    | 项目源码 | 文件源码
def test_httpretty_bypasses_when_disabled(context):
    "httpretty should bypass all requests by disabling it"

    httpretty.register_uri(
        httpretty.GET, "http://localhost:{0}/go-for-bubbles/".format(context.http_port),
        body="glub glub")

    httpretty.disable()

    fd = urllib2.urlopen('http://localhost:{0}/go-for-bubbles/'.format(context.http_port))
    got1 = fd.read()
    fd.close()

    expect(got1).to.equal(
        b'. o O 0 O o . o O 0 O o . o O 0 O o . o O 0 O o . o O 0 O o .')

    fd = urllib2.urlopen('http://localhost:{0}/come-again/'.format(context.http_port))
    got2 = fd.read()
    fd.close()

    expect(got2).to.equal(b'<- HELLO WORLD ->')

    httpretty.enable()

    fd = urllib2.urlopen('http://localhost:{0}/go-for-bubbles/'.format(context.http_port))
    got3 = fd.read()
    fd.close()

    expect(got3).to.equal(b'glub glub')
    core.POTENTIAL_HTTP_PORTS.remove(context.http_port)
项目:openkongqi    作者:gams    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.disable()
        httpretty.reset()
项目:quizlet    作者:s-alexey    | 项目源码 | 文件源码
def tearDown(self):
        httpretty.disable()
项目:swagger-stub    作者:Trax-air    | 项目源码 | 文件源码
def swagger_stub(swagger_files_url):
    """Fixture to stub a microservice from swagger files.

    To use this fixture you need to define a swagger fixture named
    swagger_files_url with the path to your swagger files, and the url to stub.
    Then just add this fixture to your tests and your request pointing to the
    urls in swagger_files_url will be managed by the stub.

    Example:
        @pytest.fixture
        def swagger_files_url():
            return [('tests/swagger.yaml', 'http://localhost:8000')]
    """
    httpretty.enable()

    for i in swagger_files_url:  # Get all given swagger files and url
        base_url = i[1]
        s = SwaggerParser(i[0])
        swagger_url[base_url] = s

        # Register all urls
        httpretty.register_uri(
            httpretty.GET, re.compile(base_url + r'/.*'),
            body=get_data_from_request)

        httpretty.register_uri(
            httpretty.POST, re.compile(base_url + r'/.*'),
            body=get_data_from_request)

        httpretty.register_uri(
            httpretty.PUT, re.compile(base_url + r'/.*'),
            body=get_data_from_request)

        httpretty.register_uri(
            httpretty.PATCH, re.compile(base_url + r'/.*'),
            body=get_data_from_request)

        httpretty.register_uri(
            httpretty.DELETE, re.compile(base_url + r'/.*'),
            body=get_data_from_request)

        memory[base_url] = StubMemory(s)
        yield memory[base_url]

    # Close httpretty
    httpretty.disable()
    httpretty.reset()