How to use the mocket.plugins.httpretty.httprettified function in mocket

To help you get started, we’ve selected a few mocket 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 mindflayer / python-mocket / tests / main / test_httpretty.py View on Github external
@httprettified
def test_httpretty_provides_easy_access_to_querystrings():
    """HTTPretty should provide an easy access to the querystring"""

    HTTPretty.register_uri(HTTPretty.GET, "http://yipit.com/",
                           body="Find the best daily deals")

    requests.get('http://yipit.com/?foo=bar&foo=baz&chuck=norris')
    expect(HTTPretty.last_request.querystring).to.equal({
        'foo': ['bar', 'baz'],
        'chuck': ['norris'],
    })
github mindflayer / python-mocket / tests / main / test_httpretty.py View on Github external
@httprettified
def test_httpretty_should_allow_multiple_methods_for_the_same_uri():
    """HTTPretty should allow registering multiple methods for the same uri"""

    url = 'http://test.com/test'
    methods = ['GET', 'POST', 'PUT', 'OPTIONS']
    for method in methods:
        HTTPretty.register_uri(
            getattr(HTTPretty, method),
            url,
            method
        )

    for method in methods:
        request_action = getattr(requests, method.lower())
        expect(request_action(url).text).to.equal(method)
github mindflayer / python-mocket / tests / main / test_httpretty.py View on Github external
@httprettified
def test_httpretty_should_allow_multiple_responses_with_multiple_methods():
    """HTTPretty should allow multiple responses when binding multiple methods to the same uri"""

    url = 'http://test.com/list'

    #add get responses
    HTTPretty.register_uri(HTTPretty.GET, url,
                           responses=[HTTPretty.Response(body='a'),
                                      HTTPretty.Response(body='b')
                           ]
    )

    #add post responses
    HTTPretty.register_uri(HTTPretty.POST, url,
                           responses=[HTTPretty.Response(body='c'),
                                      HTTPretty.Response(body='d')
github mindflayer / python-mocket / tests / main / test_httpretty.py View on Github external
@httprettified
def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2():
    """HTTPretty should allow adding and overwritting headers by keyword args " \
        "with requests"""

    HTTPretty.register_uri(HTTPretty.GET, "http://github.com/foo",
                           body="this is supposed to be the response",
                           server='Apache',
                           content_length='27',
                           content_type='application/json')

    response = requests.get('http://github.com/foo')

    expect(dict(response.headers)).to.equal({
        'content-type': 'application/json',
        'connection': 'close',
        'content-length': '27',
github mindflayer / python-mocket / tests / main / test_httpretty.py View on Github external
@httprettified
def test_httpretty_should_allow_adding_and_overwritting_requests():
    """HTTPretty should allow adding and overwritting headers with requests"""

    HTTPretty.register_uri(HTTPretty.GET, "http://github.com/foo",
                           body="this is supposed to be the response",
                           adding_headers={
                               'Server': 'Apache',
                               'Content-Length': '27',
                               'Content-Type': 'application/json',
                           })

    response = requests.get('http://github.com/foo')

    expect(dict(response.headers)).to.equal({
        'content-type': 'application/json',
        'connection': 'close',
github mindflayer / python-mocket / tests / main / test_httpretty.py View on Github external
@httprettified
def test_multiline():
    url = 'http://httpbin.org/post'
    data = b'content=Im\r\na multiline\r\n\r\nsentence\r\n'
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        'Accept': 'text/plain',
    }
    HTTPretty.register_uri(
        HTTPretty.POST,
        url,
    )
    response = requests.post(url, data=data, headers=headers)

    expect(response.status_code).to.equal(200)
    expect(HTTPretty.last_request.method).to.equal('POST')
    expect(HTTPretty.last_request.path).to.equal('/post')
github mindflayer / python-mocket / tests / main / test_httpretty.py View on Github external
@httprettified
def test_can_inspect_last_request_with_ssl():
    """HTTPretty.last_request is recorded even when mocking 'https' (SSL)"""

    HTTPretty.register_uri(HTTPretty.POST, "https://secure.github.com/",
                           body='{"repositories": ["HTTPretty", "lettuce"]}')

    response = requests.post(
        'https://secure.github.com',
        '{"username": "gabrielfalcao"}',
        headers={
            'content-type': 'text/json',
        },
    )

    expect(HTTPretty.last_request.method).to.equal('POST')
    expect(HTTPretty.last_request.body).to.equal(
github mindflayer / python-mocket / tests / main / test_httpretty.py View on Github external
@httprettified
def test_lack_of_trailing_slash():
    """HTTPretty should automatically append a slash to given urls"""
    url = 'http://www.youtube.com'
    HTTPretty.register_uri(HTTPretty.GET, url, body='')
    response = requests.get(url)
    expect(response.status_code).should.equal(200)
github mindflayer / python-mocket / tests / main / test_httpretty.py View on Github external
@httprettified
def test_rotating_responses_with_requests():
    """HTTPretty should support rotating responses with requests"""

    HTTPretty.register_uri(
        HTTPretty.GET, "https://api.yahoo.com/test",
        responses=[
            HTTPretty.Response(body=b"first response", status=201),
            HTTPretty.Response(body=b'second and last response', status=202),
        ])

    response1 = requests.get(
        'https://api.yahoo.com/test')

    expect(response1.status_code).to.equal(201)
    expect(response1.text).to.equal('first response')
github mindflayer / python-mocket / tests / main / test_httpretty.py View on Github external
@httprettified
def test_httpretty_should_mock_headers_requests():
    """HTTPretty should mock basic headers with requests"""

    HTTPretty.register_uri(HTTPretty.GET, "http://github.com/",
                           body="this is supposed to be the response",
                           status=201)

    response = requests.get('http://github.com')
    expect(response.status_code).to.equal(201)

    expect(dict(response.headers)).to.equal({
        'content-type': 'text/plain; charset=utf-8',
        'connection': 'close',
        'content-length': '35',
        'status': '201',
        'server': 'Python/HTTPretty',