How to use the httpretty.disable function in httpretty

To help you get started, we’ve selected a few httpretty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github voxpupuli / pypuppetdb / tests / test_baseapi.py View on Github external
def test_with_query(self, baseapi):
        httpretty.enable()
        stub_request('http://localhost:8080/pdb/query/v4/nodes')
        baseapi._query('nodes', query='["certname", "=", "node1"]')
        assert httpretty.last_request().querystring == {
            'query': ['["certname", "=", "node1"]']}
        httpretty.disable()
        httpretty.reset()
github gabrielfalcao / HTTPretty / tests / functional / test_bypass.py View on Github external
def start_http_server(context):
    if httpretty.httpretty._is_enabled:
        allow_net_connect = httpretty.httpretty.allow_net_connect
    else:
        allow_net_connect = True
    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:{}/'.format(context.http_port))
            ready = True
        except (Exception, BaseException):
            if time.time() - started_at >= timeout:
                break

    httpretty.enable(allow_net_connect=allow_net_connect)
github rosette-api / python / tests / test_rosette_api.py View on Github external
body=json_response, status=200, content_type="application/json")
    httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/name-similarity",
                           body=json_response, status=200, content_type="application/json")

    matched_name_data1 = "Michael Jackson"
    matched_name_data2 = "迈克尔·杰克逊"
    params = NameSimilarityParameters()
    params["name1"] = {
        "text": matched_name_data1,
        "language": "eng",
        "entityType": "PERSON"}
    params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"}

    result = api.name_similarity(params)
    assert result["name"] == "Rosette"
    httpretty.disable()
    httpretty.reset()
github rosette-api / python / tests / test_rosette_api.py View on Github external
def test_for_no_content_or_contentUri(api, json_response, doc_params):
    """Test for missing content and contentUri in DocumentParameters"""
    httpretty.enable()
    httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
                           body=json_response, status=200, content_type="application/json")
    httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/entities",
                           body=json_response, status=200, content_type="application/json")

    doc_params['content'] = None
    with pytest.raises(RosetteException) as e_rosette:
        api.entities(doc_params)

    assert e_rosette.value.status == 'badArgument'
    assert e_rosette.value.message == 'Must supply one of Content or ContentUri'
    httpretty.disable()
    httpretty.reset()
github voxpupuli / pypuppetdb / tests / test_baseapi.py View on Github external
def test_cmd_bad_command(self, baseapi):
        httpretty.enable()
        stub_request('http://localhost:8080/pdb/cmd/v1')
        with pytest.raises(pypuppetdb.errors.APIError):
            baseapi._cmd('incorrect command', {})
        httpretty.disable()
        httpretty.reset()
github voxpupuli / pypuppetdb / tests / test_baseapi.py View on Github external
def test_setting_headers_without_token(self, baseapi):
        httpretty.enable()
        stub_request('http://localhost:8080/pdb/query/v4/nodes')
        baseapi._query('nodes')  # need to query some endpoint
        request_headers = dict(httpretty.last_request().headers)
        assert request_headers['accept'] == 'application/json'
        assert request_headers['content-type'] == 'application/json'
        assert request_headers['accept-charset'] == 'utf-8'
        host_val = request_headers.get('host', request_headers.get('Host'))
        assert host_val == 'localhost:8080'
        assert httpretty.last_request().path == '/pdb/query/v4/nodes'
        httpretty.disable()
        httpretty.reset()
github rosette-api / python / tests / test_rosette_api.py View on Github external
def test_the_morphology_han_readings_endpoint(api, json_response, doc_params):
    """Test the morphology han-reading endpoint"""
    httpretty.enable()
    httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
                           body=json_response, status=200, content_type="application/json")
    httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/morphology/han-readings",
                           body=json_response, status=200, content_type="application/json")

    result = api.morphology(doc_params, 'han-readings')
    assert result["name"] == "Rosette"
    httpretty.disable()
    httpretty.reset()
github rosette-api / python / tests / test_rosette_api.py View on Github external
def test_the_name_translation_endpoint(api, json_response):
    """Test the name translation endpoint"""
    httpretty.enable()
    httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
                           body=json_response, status=200, content_type="application/json")
    httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/name-translation",
                           body=json_response, status=200, content_type="application/json")

    params = NameTranslationParameters()
    params["name"] = "some data to translate"
    params["entityType"] = "PERSON"
    params["targetLanguage"] = "eng"
    params["targetScript"] = "Latn"
    result = api.name_translation(params)
    assert result["name"] == "Rosette"
    httpretty.disable()
    httpretty.reset()