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)
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
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/")