Example #1
0
def test_Entry_class_counts_callable():
    entry = Entry(HTTPretty.GET, 'http://example.com', callable_body)
    entry.info = MagicMock()
    buf = FakeSockFile()
    entry.fill_filekind(buf)
    response = buf.getvalue()
    expect(b'content-length: 3\n').to.be.within(response)
Example #2
0
def test_Entry_class_counts_dynamic():
    result = (200, {}, 'こんにちは'.encode('utf-8'))
    entry = Entry(HTTPretty.GET, 'http://example.com', lambda *args: result)
    entry.info = URIInfo.from_uri('http://example.com', entry)
    buf = FakeSockFile()
    entry.fill_filekind(buf)
    response = buf.getvalue()
    expect(b'content-length: 15\n').to.be.within(response)
def test_Entry_class_counts_dynamic():
    result = (200, {}, 'こんにちは'.encode('utf-8'))
    entry = Entry(HTTPretty.GET, 'http://example.com', lambda *args: result)
    entry.info = URIInfo.from_uri('http://example.com', entry)
    buf = FakeSockFile()
    entry.fill_filekind(buf)
    response = buf.getvalue()
    expect(b'content-length: 15\n').to.be.within(response)
Example #4
0
def test_Entry_class_normalizes_headers():
    entry = Entry(HTTPretty.GET, 'http://example.com', 'example',
                  host='example.com', cache_control='no-cache', x_forward_for='proxy')

    expect(entry.adding_headers).to.equal({
        u'Host': u'example.com',
        u'Cache-Control': u'no-cache',
        u'X-Forward-For': u'proxy'
    })
Example #5
0
 def flask_resp_to_entry(cls, resp, method, info, request):
     headers = {}
     headers['Content-Type'] = resp.content_type
     return Entry(method,
                  info.hostname,
                  body=resp.data,
                  status=resp.status_code,
                  adding_headers=None,
                  forcing_headers=None)
Example #6
0
def test_Entry_class_normalizes_headers():
    entry = Entry(HTTPretty.GET,
                  'http://example.com',
                  'example',
                  host='example.com',
                  cache_control='no-cache',
                  x_forward_for='proxy')

    entry.adding_headers.should.equal({
        'Host': 'example.com',
        'Cache-Control': 'no-cache',
        'X-Forward-For': 'proxy'
    })
Example #7
0
def test_Entry_class_counts_multibyte_characters_in_bytes():
    entry = Entry(HTTPretty.GET, 'http://example.com', 'こんにちは')
    buf = FakeSockFile()
    entry.fill_filekind(buf)
    response = buf.getvalue()
    expect(b'content-length: 15\n').to.be.within(response)
Example #8
0
def test_Entry_class_counts_multibyte_characters_in_bytes():
    entry = Entry(HTTPretty.GET, 'http://example.com', 'こんにちは')
    buf = FakeSockFile()
    entry.fill_filekind(buf)
    response = buf.read()
    expect(b'content-length: 15\n').to.be.within(response)