Esempio n. 1
0
def test_uri_info_eq_ignores_case():
    """Test that URIInfo.__eq__ method ignores case for
    hostname matching.
    """
    uri_info_uppercase = URIInfo(
        username='******',
        password='******',
        hostname=b'GOOGLE.COM',
        port=80,
        path=b'/',
        query=b'foo=bar&baz=test',
        fragment='',
        scheme='',
    )
    uri_info_lowercase = URIInfo(
        username='******',
        password='******',
        hostname=b'google.com',
        port=80,
        path=b'/',
        query=b'foo=bar&baz=test',
        fragment='',
        scheme='',
    )
    expect(uri_info_uppercase).to.equal(uri_info_lowercase)
Esempio n. 2
0
def test_URIMatcher_respects_querystring():
    ("URIMatcher response querystring")
    matcher = URIMatcher('http://www.foo.com/?query=true', None)
    info = URIInfo.from_uri('http://www.foo.com/', None)
    assert matcher.matches(info)

    matcher = URIMatcher('http://www.foo.com/?query=true',
                         None,
                         match_querystring=True)
    info = URIInfo.from_uri('http://www.foo.com/', None)
    assert not matcher.matches(info)

    matcher = URIMatcher('http://www.foo.com/?query=true',
                         None,
                         match_querystring=True)
    info = URIInfo.from_uri('http://www.foo.com/?query=true', None)
    assert matcher.matches(info)

    matcher = URIMatcher('http://www.foo.com/?query=true&unquery=false',
                         None,
                         match_querystring=True)
    info = URIInfo.from_uri('http://www.foo.com/?unquery=false&query=true',
                            None)
    assert matcher.matches(info)

    matcher = URIMatcher('http://www.foo.com/?unquery=false&query=true',
                         None,
                         match_querystring=True)
    info = URIInfo.from_uri('http://www.foo.com/?query=true&unquery=false',
                            None)
    assert matcher.matches(info)
Esempio n. 3
0
def test_URIMatcher_respects_querystring():
    ("URIMatcher response querystring")
    matcher = URIMatcher('http://www.foo.com/?query=true', None)
    info = URIInfo.from_uri('http://www.foo.com/', None)
    assert matcher.matches(info)

    matcher = URIMatcher('http://www.foo.com/?query=true', None, match_querystring=True)
    info = URIInfo.from_uri('http://www.foo.com/', None)
    assert not matcher.matches(info)

    matcher = URIMatcher('http://www.foo.com/?query=true', None, match_querystring=True)
    info = URIInfo.from_uri('http://www.foo.com/?query=true', None)
    assert matcher.matches(info)
def test_uri_info_full_url():
    uri_info = URIInfo(
        username="******",
        password="******",
        hostname=b"google.com",
        port=80,
        path=b"/",
        query=b"foo=bar&baz=test",
        fragment="",
        scheme="",
    )

    expect(uri_info.full_url()).to.equal("http://*****:*****@google.com/?foo=bar&baz=test")

    expect(uri_info.full_url(use_querystring=False)).to.equal("http://*****:*****@google.com/")
Esempio n. 5
0
def test_uri_info_full_url():
    uri_info = URIInfo(
        username='******',
        password='******',
        hostname=b'google.com',
        port=80,
        path=b'/',
        query=b'foo=bar&baz=test',
        fragment='',
        scheme='',
    )

    expect(uri_info.full_url()).to.equal(
        "http://*****:*****@google.com/?foo=bar&baz=test"
    )
Esempio n. 6
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)
Esempio n. 7
0
def test_uri_info_full_url():
    uri_info = URIInfo(
        username='******',
        password='******',
        hostname=b'google.com',
        port=80,
        path=b'/',
        query=b'foo=bar&baz=test',
        fragment='',
        scheme='',
    )

    expect(uri_info.full_url()).to.equal(
        "http://*****:*****@google.com/?baz=test&foo=bar")

    expect(uri_info.full_url(
        use_querystring=False)).to.equal("http://*****:*****@google.com/")
Esempio n. 8
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)
Esempio n. 9
0
def f_sendall(self, data, *args, **kw):
    self._sent_data.append(data)

    try:
        requestline, _ = data.split(b'\r\n', 1)
        method, path, version = parse_requestline(decode_utf8(requestline))
        is_parsing_headers = True
    except ValueError:
        is_parsing_headers = False

        if not self._entry:
            # If the previous request wasn't mocked, don't mock the subsequent sending of data
            return self.real_sendall(data, *args, **kw)
    self.fd.seek(0)

    if not is_parsing_headers:
        if len(self._sent_data) > 1:
            headers = utf8(last_requestline(self._sent_data))
            meta = self._entry.request.headers
            body = utf8(self._sent_data[-1])
            if meta.get('transfer-encoding', '') == 'chunked':
                if not body.isdigit(
                ) and body != b'\r\n' and body != b'0\r\n\r\n':
                    self._entry.request.body += body
            else:
                self._entry.request.body += body

            httpretty.historify_request(headers, body, False)
            return

    # path might come with
    s = urlsplit(path)
    core.POTENTIAL_HTTP_PORTS.add(int(s.port or 80))
    headers, body = list(map(utf8, data.split(b'\r\n\r\n', 1)))

    request = flaskhttpretty.historify_request(headers, body)

    info = URIInfo(hostname=self._host,
                   port=self._port,
                   path=s.path,
                   query=s.query,
                   last_request=request)
    entry = flaskhttpretty.get_entry(method, info, request)
    if not entry:
        self._entry = None
        self.real_sendall(data)
        return None

    self._entry = entry