netlib.tutils -> mitmproxy.test.tutils
There's a LOT more to be done refactoring our different conflicting test utils.
This commit is contained in:
parent
9491d8589a
commit
853e03a5e7
|
@ -89,9 +89,7 @@ class RaisesContext:
|
|||
return True
|
||||
|
||||
|
||||
test_data = data.Data(__name__)
|
||||
# FIXME: Temporary workaround during repo merge.
|
||||
test_data.dirname = os.path.join(test_data.dirname, "..", "test", "netlib")
|
||||
test_data = data.Data(__name__).push("../../test/netlib")
|
||||
|
||||
|
||||
def treq(**kwargs):
|
|
@ -11,7 +11,7 @@ import time
|
|||
import OpenSSL.crypto
|
||||
import logging
|
||||
|
||||
from netlib.tutils import treq
|
||||
from mitmproxy.test.tutils import treq
|
||||
from mitmproxy.utils import strutils
|
||||
from netlib import tcp
|
||||
from mitmproxy import certs
|
||||
|
|
|
@ -7,7 +7,7 @@ from mitmproxy import exceptions
|
|||
from mitmproxy.tools import dump
|
||||
from mitmproxy import http
|
||||
from mitmproxy import proxy
|
||||
import netlib.tutils
|
||||
import mitmproxy.test.tutils
|
||||
import mock
|
||||
|
||||
|
||||
|
@ -38,11 +38,11 @@ class TestDumper(mastertest.MasterTest):
|
|||
sio = io.StringIO()
|
||||
d.configure(dump.Options(tfile = sio, flow_detail = 4), updated)
|
||||
flow = tutils.tflow()
|
||||
flow.request = netlib.tutils.treq()
|
||||
flow.request = mitmproxy.test.tutils.treq()
|
||||
flow.request.stickycookie = True
|
||||
flow.client_conn = mock.MagicMock()
|
||||
flow.client_conn.address.host = "foo"
|
||||
flow.response = netlib.tutils.tresp(content=None)
|
||||
flow.response = mitmproxy.test.tutils.tresp(content=None)
|
||||
flow.response.is_replay = True
|
||||
flow.response.status_code = 300
|
||||
d.response(flow)
|
||||
|
@ -50,7 +50,7 @@ class TestDumper(mastertest.MasterTest):
|
|||
|
||||
sio = io.StringIO()
|
||||
d.configure(dump.Options(tfile = sio, flow_detail = 4), updated)
|
||||
flow = tutils.tflow(resp=netlib.tutils.tresp(content=b"{"))
|
||||
flow = tutils.tflow(resp=mitmproxy.test.tutils.tresp(content=b"{"))
|
||||
flow.response.headers["content-type"] = "application/json"
|
||||
flow.response.status_code = 400
|
||||
d.response(flow)
|
||||
|
@ -60,7 +60,7 @@ class TestDumper(mastertest.MasterTest):
|
|||
d.configure(dump.Options(tfile = sio), updated)
|
||||
flow = tutils.tflow()
|
||||
flow.request.content = None
|
||||
flow.response = http.HTTPResponse.wrap(netlib.tutils.tresp())
|
||||
flow.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
|
||||
flow.response.content = None
|
||||
d.response(flow)
|
||||
assert "content missing" in sio.getvalue()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from .. import tutils, mastertest
|
||||
|
||||
import netlib.tutils
|
||||
import mitmproxy.test.tutils
|
||||
from mitmproxy.addons import serverplayback
|
||||
from mitmproxy import options
|
||||
from mitmproxy import proxy
|
||||
|
@ -244,7 +244,7 @@ class TestServerPlayback:
|
|||
m.addons.add(s)
|
||||
|
||||
f = tutils.tflow()
|
||||
f.response = netlib.tutils.tresp(content=f.request.content)
|
||||
f.response = mitmproxy.test.tutils.tresp(content=f.request.content)
|
||||
s.load([f, f])
|
||||
|
||||
tf = tutils.tflow()
|
||||
|
@ -273,7 +273,7 @@ class TestServerPlayback:
|
|||
m.addons.add(s)
|
||||
|
||||
f = tutils.tflow()
|
||||
f.response = netlib.tutils.tresp(content=f.request.content)
|
||||
f.response = mitmproxy.test.tutils.tresp(content=f.request.content)
|
||||
s.load([f])
|
||||
|
||||
f = tutils.tflow()
|
||||
|
|
|
@ -3,7 +3,7 @@ from mitmproxy.addons import stickycookie
|
|||
from mitmproxy import master
|
||||
from mitmproxy import options
|
||||
from mitmproxy import proxy
|
||||
from netlib import tutils as ntutils
|
||||
from mitmproxy.test import tutils as ntutils
|
||||
|
||||
|
||||
def test_domain_match():
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import gc
|
||||
|
||||
import netlib.tutils
|
||||
import mitmproxy.test.tutils
|
||||
from mitmproxy.tools import console
|
||||
from mitmproxy import proxy
|
||||
from mitmproxy.tools.console import common
|
||||
|
@ -59,13 +59,13 @@ class TestConsoleState:
|
|||
|
||||
def _add_response(self, state):
|
||||
f = self._add_request(state)
|
||||
f.response = netlib.tutils.tresp()
|
||||
f.response = mitmproxy.test.tutils.tresp()
|
||||
state.update_flow(f)
|
||||
|
||||
def test_add_response(self):
|
||||
c = console.master.ConsoleState()
|
||||
f = self._add_request(c)
|
||||
f.response = netlib.tutils.tresp()
|
||||
f.response = mitmproxy.test.tutils.tresp()
|
||||
c.focus = None
|
||||
c.update_flow(f)
|
||||
|
||||
|
@ -127,12 +127,12 @@ class TestMaster(mastertest.MasterTest):
|
|||
def test_intercept(self):
|
||||
"""regression test for https://github.com/mitmproxy/mitmproxy/issues/1605"""
|
||||
m = self.mkmaster(intercept="~b bar")
|
||||
f = tutils.tflow(req=netlib.tutils.treq(content=b"foo"))
|
||||
f = tutils.tflow(req=mitmproxy.test.tutils.treq(content=b"foo"))
|
||||
m.request(f)
|
||||
assert not m.state.flows[0].intercepted
|
||||
f = tutils.tflow(req=netlib.tutils.treq(content=b"bar"))
|
||||
f = tutils.tflow(req=mitmproxy.test.tutils.treq(content=b"bar"))
|
||||
m.request(f)
|
||||
assert m.state.flows[1].intercepted
|
||||
f = tutils.tflow(resp=netlib.tutils.tresp(content=b"bar"))
|
||||
f = tutils.tflow(resp=mitmproxy.test.tutils.tresp(content=b"bar"))
|
||||
m.request(f)
|
||||
assert m.state.flows[2].intercepted
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import contextlib
|
||||
|
||||
from . import tutils
|
||||
import netlib.tutils
|
||||
import mitmproxy.test.tutils
|
||||
|
||||
from mitmproxy import master
|
||||
from mitmproxy import io
|
||||
|
@ -17,13 +17,13 @@ class TestMaster:
|
|||
class MasterTest:
|
||||
|
||||
def cycle(self, master, content):
|
||||
f = tutils.tflow(req=netlib.tutils.treq(content=content))
|
||||
f = tutils.tflow(req=mitmproxy.test.tutils.treq(content=content))
|
||||
master.clientconnect(f.client_conn)
|
||||
master.serverconnect(f.server_conn)
|
||||
master.request(f)
|
||||
if not f.error:
|
||||
f.response = http.HTTPResponse.wrap(
|
||||
netlib.tutils.tresp(content=content)
|
||||
mitmproxy.test.tutils.tresp(content=content)
|
||||
)
|
||||
master.response(f)
|
||||
master.clientdisconnect(f)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from netlib.http import http1
|
||||
from netlib.tcp import TCPClient
|
||||
from netlib.tutils import treq
|
||||
from mitmproxy.test.tutils import treq
|
||||
from .. import tutils, tservers
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
from mitmproxy import certs
|
||||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
# class TestDNTree:
|
||||
# def test_simple(self):
|
||||
|
|
|
@ -6,7 +6,7 @@ from mitmproxy.types import multidict
|
|||
|
||||
import mitmproxy.contentviews as cv
|
||||
from . import tutils
|
||||
import netlib.tutils
|
||||
import mitmproxy.test.tutils
|
||||
|
||||
try:
|
||||
import pyamf
|
||||
|
@ -232,7 +232,7 @@ def test_get_content_view():
|
|||
|
||||
|
||||
def test_get_message_content_view():
|
||||
r = netlib.tutils.treq()
|
||||
r = mitmproxy.test.tutils.treq()
|
||||
desc, lines, err = cv.get_message_content_view(cv.get("Raw"), r)
|
||||
assert desc == "Raw"
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import queue
|
|||
from mitmproxy.exceptions import Kill, ControlException
|
||||
from mitmproxy import proxy
|
||||
from mitmproxy import master
|
||||
from netlib.tutils import raises
|
||||
from mitmproxy.test.tutils import raises
|
||||
|
||||
|
||||
class TMsg:
|
||||
|
|
|
@ -9,7 +9,7 @@ from mitmproxy.addons import script
|
|||
from mitmproxy.utils import data
|
||||
from mitmproxy import master
|
||||
|
||||
from netlib import tutils as netutils
|
||||
from mitmproxy.test import tutils as netutils
|
||||
from netlib.http import Headers
|
||||
from netlib.http import cookies
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import mock
|
||||
import io
|
||||
|
||||
import netlib.tutils
|
||||
import mitmproxy.test.tutils
|
||||
from netlib.http import Headers
|
||||
import mitmproxy.io
|
||||
from mitmproxy import flowfilter, options
|
||||
|
@ -59,7 +59,7 @@ class TestHTTPFlow:
|
|||
|
||||
def test_backup(self):
|
||||
f = tutils.tflow()
|
||||
f.response = http.HTTPResponse.wrap(netlib.tutils.tresp())
|
||||
f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
|
||||
f.request.content = b"foo"
|
||||
assert not f.modified()
|
||||
f.backup()
|
||||
|
@ -212,7 +212,7 @@ class TestState:
|
|||
assert c.add_flow(newf)
|
||||
assert c.active_flow_count() == 2
|
||||
|
||||
f.response = http.HTTPResponse.wrap(netlib.tutils.tresp())
|
||||
f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
|
||||
assert c.update_flow(f)
|
||||
assert c.flow_count() == 2
|
||||
assert c.active_flow_count() == 1
|
||||
|
@ -220,7 +220,7 @@ class TestState:
|
|||
assert not c.update_flow(None)
|
||||
assert c.active_flow_count() == 1
|
||||
|
||||
newf.response = http.HTTPResponse.wrap(netlib.tutils.tresp())
|
||||
newf.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
|
||||
assert c.update_flow(newf)
|
||||
assert c.active_flow_count() == 0
|
||||
|
||||
|
@ -252,7 +252,7 @@ class TestState:
|
|||
c.set_view_filter("~s")
|
||||
assert c.filter_txt == "~s"
|
||||
assert len(c.view) == 0
|
||||
f.response = http.HTTPResponse.wrap(netlib.tutils.tresp())
|
||||
f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
|
||||
c.update_flow(f)
|
||||
assert len(c.view) == 1
|
||||
c.set_view_filter(None)
|
||||
|
@ -284,7 +284,7 @@ class TestState:
|
|||
def _add_response(self, state):
|
||||
f = tutils.tflow()
|
||||
state.add_flow(f)
|
||||
f.response = http.HTTPResponse.wrap(netlib.tutils.tresp())
|
||||
f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
|
||||
state.update_flow(f)
|
||||
|
||||
def _add_error(self, state):
|
||||
|
@ -444,11 +444,11 @@ class TestFlowMaster:
|
|||
fm.addons.add(s)
|
||||
f = tutils.tflow(req=None)
|
||||
fm.clientconnect(f.client_conn)
|
||||
f.request = http.HTTPRequest.wrap(netlib.tutils.treq())
|
||||
f.request = http.HTTPRequest.wrap(mitmproxy.test.tutils.treq())
|
||||
fm.request(f)
|
||||
assert s.flow_count() == 1
|
||||
|
||||
f.response = http.HTTPResponse.wrap(netlib.tutils.tresp())
|
||||
f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
|
||||
fm.response(f)
|
||||
assert s.flow_count() == 1
|
||||
|
||||
|
@ -473,7 +473,7 @@ class TestRequest:
|
|||
assert r.get_state() == r2.get_state()
|
||||
|
||||
def test_get_url(self):
|
||||
r = http.HTTPRequest.wrap(netlib.tutils.treq())
|
||||
r = http.HTTPRequest.wrap(mitmproxy.test.tutils.treq())
|
||||
|
||||
assert r.url == "http://address:22/path"
|
||||
|
||||
|
@ -494,7 +494,7 @@ class TestRequest:
|
|||
assert r.pretty_url == "https://foo.com:22/path"
|
||||
|
||||
def test_replace(self):
|
||||
r = http.HTTPRequest.wrap(netlib.tutils.treq())
|
||||
r = http.HTTPRequest.wrap(mitmproxy.test.tutils.treq())
|
||||
r.path = "path/foo"
|
||||
r.headers["Foo"] = "fOo"
|
||||
r.content = b"afoob"
|
||||
|
@ -504,7 +504,7 @@ class TestRequest:
|
|||
assert r.headers["boo"] == "boo"
|
||||
|
||||
def test_constrain_encoding(self):
|
||||
r = http.HTTPRequest.wrap(netlib.tutils.treq())
|
||||
r = http.HTTPRequest.wrap(mitmproxy.test.tutils.treq())
|
||||
r.headers["accept-encoding"] = "gzip, oink"
|
||||
r.constrain_encoding()
|
||||
assert "oink" not in r.headers["accept-encoding"]
|
||||
|
@ -514,7 +514,7 @@ class TestRequest:
|
|||
assert "oink" not in r.headers["accept-encoding"]
|
||||
|
||||
def test_get_content_type(self):
|
||||
resp = http.HTTPResponse.wrap(netlib.tutils.tresp())
|
||||
resp = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
|
||||
resp.headers = Headers(content_type="text/plain")
|
||||
assert resp.headers["content-type"] == "text/plain"
|
||||
|
||||
|
@ -528,7 +528,7 @@ class TestResponse:
|
|||
assert resp2.get_state() == resp.get_state()
|
||||
|
||||
def test_replace(self):
|
||||
r = http.HTTPResponse.wrap(netlib.tutils.tresp())
|
||||
r = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
|
||||
r.headers["Foo"] = "fOo"
|
||||
r.content = b"afoob"
|
||||
assert r.replace("foo(?i)", "boo") == 3
|
||||
|
@ -536,7 +536,7 @@ class TestResponse:
|
|||
assert r.headers["boo"] == "boo"
|
||||
|
||||
def test_get_content_type(self):
|
||||
resp = http.HTTPResponse.wrap(netlib.tutils.tresp())
|
||||
resp = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
|
||||
resp.headers = Headers(content_type="text/plain")
|
||||
assert resp.headers["content-type"] == "text/plain"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
|
||||
import netlib.tutils
|
||||
import mitmproxy.test.tutils
|
||||
from netlib.http import Headers
|
||||
from mitmproxy import export # heh
|
||||
from . import tutils
|
||||
|
@ -20,15 +20,15 @@ def python_equals(testdata, text):
|
|||
|
||||
|
||||
def req_get():
|
||||
return netlib.tutils.treq(method=b'GET', content=b'', path=b"/path?a=foo&a=bar&b=baz")
|
||||
return mitmproxy.test.tutils.treq(method=b'GET', content=b'', path=b"/path?a=foo&a=bar&b=baz")
|
||||
|
||||
|
||||
def req_post():
|
||||
return netlib.tutils.treq(method=b'POST', headers=())
|
||||
return mitmproxy.test.tutils.treq(method=b'POST', headers=())
|
||||
|
||||
|
||||
def req_patch():
|
||||
return netlib.tutils.treq(method=b'PATCH', path=b"/path?query=param")
|
||||
return mitmproxy.test.tutils.treq(method=b'PATCH', path=b"/path?query=param")
|
||||
|
||||
|
||||
class TestExportCurlCommand:
|
||||
|
|
|
@ -2,7 +2,7 @@ import copy
|
|||
|
||||
from mitmproxy import optmanager
|
||||
from mitmproxy import exceptions
|
||||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
class TO(optmanager.OptManager):
|
||||
|
|
|
@ -2,7 +2,7 @@ import os
|
|||
import socket
|
||||
import time
|
||||
|
||||
import netlib.tutils
|
||||
import mitmproxy.test.tutils
|
||||
from mitmproxy import controller
|
||||
from mitmproxy import options
|
||||
from mitmproxy.addons import script
|
||||
|
@ -16,7 +16,7 @@ from mitmproxy import exceptions
|
|||
from netlib.http import authentication
|
||||
from netlib.http import http1
|
||||
from netlib.tcp import Address
|
||||
from netlib.tutils import raises
|
||||
from mitmproxy.test.tutils import raises
|
||||
from pathod import pathoc
|
||||
from pathod import pathod
|
||||
|
||||
|
@ -794,7 +794,7 @@ class TestStreamRequest(tservers.HTTPProxyTest):
|
|||
class MasterFakeResponse(tservers.TestMaster):
|
||||
@controller.handler
|
||||
def request(self, f):
|
||||
f.response = http.HTTPResponse.wrap(netlib.tutils.tresp())
|
||||
f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
|
||||
|
||||
|
||||
class TestFakeResponse(tservers.HTTPProxyTest):
|
||||
|
@ -873,7 +873,7 @@ class MasterIncomplete(tservers.TestMaster):
|
|||
|
||||
@controller.handler
|
||||
def request(self, f):
|
||||
resp = http.HTTPResponse.wrap(netlib.tutils.tresp())
|
||||
resp = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
|
||||
resp.content = None
|
||||
f.response = resp
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from mitmproxy.types import bidi
|
||||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
def test_bidi():
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
from mitmproxy.types import multidict
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import time
|
||||
from mitmproxy.utils import human
|
||||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
def test_format_timestamp():
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from mitmproxy.utils import strutils
|
||||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
def test_always_bytes():
|
||||
|
|
|
@ -9,7 +9,7 @@ from unittest.case import SkipTest
|
|||
|
||||
import io
|
||||
|
||||
import netlib.tutils
|
||||
import mitmproxy.test.tutils
|
||||
from mitmproxy import controller
|
||||
from mitmproxy import connections
|
||||
from mitmproxy import flow
|
||||
|
@ -102,9 +102,9 @@ def tflow(client_conn=True, server_conn=True, req=True, resp=None, err=None):
|
|||
if server_conn is True:
|
||||
server_conn = tserver_conn()
|
||||
if req is True:
|
||||
req = netlib.tutils.treq()
|
||||
req = mitmproxy.test.tutils.treq()
|
||||
if resp is True:
|
||||
resp = netlib.tutils.tresp()
|
||||
resp = mitmproxy.test.tutils.tresp()
|
||||
if err is True:
|
||||
err = terr()
|
||||
|
||||
|
@ -197,7 +197,7 @@ class MockParser(argparse.ArgumentParser):
|
|||
raise Exception(message)
|
||||
|
||||
|
||||
raises = netlib.tutils.raises
|
||||
raises = mitmproxy.test.tutils.raises
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
|
|
@ -5,7 +5,7 @@ from netlib.http.http1.assemble import (
|
|||
assemble_response_head, _assemble_request_line, _assemble_request_headers,
|
||||
_assemble_response_headers,
|
||||
assemble_body)
|
||||
from netlib.tutils import treq, raises, tresp
|
||||
from mitmproxy.test.tutils import treq, raises, tresp
|
||||
|
||||
|
||||
def test_assemble_request():
|
||||
|
|
|
@ -10,7 +10,7 @@ from netlib.http.http1.read import (
|
|||
_read_request_line, _parse_authority_form, _read_response_line, _check_http_version,
|
||||
_read_headers, _read_chunked, get_header_tokens
|
||||
)
|
||||
from netlib.tutils import treq, tresp, raises
|
||||
from mitmproxy.test.tutils import treq, tresp, raises
|
||||
|
||||
|
||||
def test_get_header_tokens():
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import binascii
|
||||
|
||||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
from netlib.http import authentication, Headers
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import time
|
||||
|
||||
from netlib.http import cookies
|
||||
from netlib.tutils import raises
|
||||
from mitmproxy.test.tutils import raises
|
||||
|
||||
import mock
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import mock
|
|||
import pytest
|
||||
|
||||
from netlib.http import encoding
|
||||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
@pytest.mark.parametrize("encoder", [
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import collections
|
||||
|
||||
from netlib.http.headers import Headers, parse_content_type, assemble_content_type
|
||||
from netlib.tutils import raises
|
||||
from mitmproxy.test.tutils import raises
|
||||
|
||||
|
||||
class TestHeaders:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from netlib.tutils import tresp
|
||||
from netlib import http, tutils
|
||||
from mitmproxy.test import tutils
|
||||
from netlib import http
|
||||
|
||||
|
||||
def _test_passthrough_attr(message, attr):
|
||||
|
@ -37,12 +37,12 @@ def _test_decoded_attr(message, attr):
|
|||
|
||||
class TestMessageData:
|
||||
def test_eq_ne(self):
|
||||
data = tresp(timestamp_start=42, timestamp_end=42).data
|
||||
same = tresp(timestamp_start=42, timestamp_end=42).data
|
||||
data = tutils.tresp(timestamp_start=42, timestamp_end=42).data
|
||||
same = tutils.tresp(timestamp_start=42, timestamp_end=42).data
|
||||
assert data == same
|
||||
assert not data != same
|
||||
|
||||
other = tresp(content=b"foo").data
|
||||
other = tutils.tresp(content=b"foo").data
|
||||
assert not data == other
|
||||
assert data != other
|
||||
|
||||
|
@ -52,28 +52,28 @@ class TestMessageData:
|
|||
class TestMessage:
|
||||
|
||||
def test_init(self):
|
||||
resp = tresp()
|
||||
resp = tutils.tresp()
|
||||
assert resp.data
|
||||
|
||||
def test_eq_ne(self):
|
||||
resp = tresp(timestamp_start=42, timestamp_end=42)
|
||||
same = tresp(timestamp_start=42, timestamp_end=42)
|
||||
resp = tutils.tresp(timestamp_start=42, timestamp_end=42)
|
||||
same = tutils.tresp(timestamp_start=42, timestamp_end=42)
|
||||
assert resp == same
|
||||
assert not resp != same
|
||||
|
||||
other = tresp(timestamp_start=0, timestamp_end=0)
|
||||
other = tutils.tresp(timestamp_start=0, timestamp_end=0)
|
||||
assert not resp == other
|
||||
assert resp != other
|
||||
|
||||
assert resp != 0
|
||||
|
||||
def test_serializable(self):
|
||||
resp = tresp()
|
||||
resp = tutils.tresp()
|
||||
resp2 = http.Response.from_state(resp.get_state())
|
||||
assert resp == resp2
|
||||
|
||||
def test_content_length_update(self):
|
||||
resp = tresp()
|
||||
resp = tutils.tresp()
|
||||
resp.content = b"foo"
|
||||
assert resp.data.content == b"foo"
|
||||
assert resp.headers["content-length"] == "3"
|
||||
|
@ -85,19 +85,19 @@ class TestMessage:
|
|||
assert resp.headers["content-length"] == "0"
|
||||
|
||||
def test_headers(self):
|
||||
_test_passthrough_attr(tresp(), "headers")
|
||||
_test_passthrough_attr(tutils.tresp(), "headers")
|
||||
|
||||
def test_timestamp_start(self):
|
||||
_test_passthrough_attr(tresp(), "timestamp_start")
|
||||
_test_passthrough_attr(tutils.tresp(), "timestamp_start")
|
||||
|
||||
def test_timestamp_end(self):
|
||||
_test_passthrough_attr(tresp(), "timestamp_end")
|
||||
_test_passthrough_attr(tutils.tresp(), "timestamp_end")
|
||||
|
||||
def test_http_version(self):
|
||||
_test_decoded_attr(tresp(), "http_version")
|
||||
_test_decoded_attr(tutils.tresp(), "http_version")
|
||||
|
||||
def test_replace(self):
|
||||
r = tresp()
|
||||
r = tutils.tresp()
|
||||
r.content = b"foofootoo"
|
||||
r.replace(b"foo", "gg")
|
||||
assert r.content == b"ggggtoo"
|
||||
|
@ -109,7 +109,7 @@ class TestMessage:
|
|||
|
||||
class TestMessageContentEncoding:
|
||||
def test_simple(self):
|
||||
r = tresp()
|
||||
r = tutils.tresp()
|
||||
assert r.raw_content == b"message"
|
||||
assert "content-encoding" not in r.headers
|
||||
r.encode("gzip")
|
||||
|
@ -120,7 +120,7 @@ class TestMessageContentEncoding:
|
|||
assert r.raw_content != b"message"
|
||||
|
||||
def test_modify(self):
|
||||
r = tresp()
|
||||
r = tutils.tresp()
|
||||
assert "content-encoding" not in r.headers
|
||||
r.encode("gzip")
|
||||
|
||||
|
@ -133,7 +133,7 @@ class TestMessageContentEncoding:
|
|||
r.content = u"foo"
|
||||
|
||||
def test_unknown_ce(self):
|
||||
r = tresp()
|
||||
r = tutils.tresp()
|
||||
r.headers["content-encoding"] = "zopfli"
|
||||
r.raw_content = b"foo"
|
||||
with tutils.raises(ValueError):
|
||||
|
@ -142,7 +142,7 @@ class TestMessageContentEncoding:
|
|||
assert r.get_content(strict=False) == b"foo"
|
||||
|
||||
def test_cannot_decode(self):
|
||||
r = tresp()
|
||||
r = tutils.tresp()
|
||||
r.encode("gzip")
|
||||
r.raw_content = b"foo"
|
||||
with tutils.raises(ValueError):
|
||||
|
@ -160,7 +160,7 @@ class TestMessageContentEncoding:
|
|||
assert "content-encoding" not in r.headers
|
||||
|
||||
def test_none(self):
|
||||
r = tresp(content=None)
|
||||
r = tutils.tresp(content=None)
|
||||
assert r.content is None
|
||||
r.content = b"foo"
|
||||
assert r.content is not None
|
||||
|
@ -168,7 +168,7 @@ class TestMessageContentEncoding:
|
|||
assert r.content is None
|
||||
|
||||
def test_cannot_encode(self):
|
||||
r = tresp()
|
||||
r = tutils.tresp()
|
||||
r.encode("gzip")
|
||||
r.content = None
|
||||
assert r.headers["content-encoding"]
|
||||
|
@ -187,7 +187,7 @@ class TestMessageContentEncoding:
|
|||
|
||||
class TestMessageText:
|
||||
def test_simple(self):
|
||||
r = tresp(content=b'\xfc')
|
||||
r = tutils.tresp(content=b'\xfc')
|
||||
assert r.raw_content == b"\xfc"
|
||||
assert r.content == b"\xfc"
|
||||
assert r.text == u"ü"
|
||||
|
@ -204,12 +204,12 @@ class TestMessageText:
|
|||
assert r.text == u"ü"
|
||||
|
||||
def test_guess_json(self):
|
||||
r = tresp(content=b'"\xc3\xbc"')
|
||||
r = tutils.tresp(content=b'"\xc3\xbc"')
|
||||
r.headers["content-type"] = "application/json"
|
||||
assert r.text == u'"ü"'
|
||||
|
||||
def test_none(self):
|
||||
r = tresp(content=None)
|
||||
r = tutils.tresp(content=None)
|
||||
assert r.text is None
|
||||
r.text = u"foo"
|
||||
assert r.text is not None
|
||||
|
@ -217,7 +217,7 @@ class TestMessageText:
|
|||
assert r.text is None
|
||||
|
||||
def test_modify(self):
|
||||
r = tresp()
|
||||
r = tutils.tresp()
|
||||
|
||||
r.text = u"ü"
|
||||
assert r.raw_content == b"\xfc"
|
||||
|
@ -228,7 +228,7 @@ class TestMessageText:
|
|||
assert r.headers["content-length"] == "2"
|
||||
|
||||
def test_unknown_ce(self):
|
||||
r = tresp()
|
||||
r = tutils.tresp()
|
||||
r.headers["content-type"] = "text/html; charset=wtf"
|
||||
r.raw_content = b"foo"
|
||||
with tutils.raises(ValueError):
|
||||
|
@ -236,7 +236,7 @@ class TestMessageText:
|
|||
assert r.get_text(strict=False) == u"foo"
|
||||
|
||||
def test_cannot_decode(self):
|
||||
r = tresp()
|
||||
r = tutils.tresp()
|
||||
r.headers["content-type"] = "text/html; charset=utf8"
|
||||
r.raw_content = b"\xFF"
|
||||
with tutils.raises(ValueError):
|
||||
|
@ -245,7 +245,7 @@ class TestMessageText:
|
|||
assert r.get_text(strict=False) == '\udcff'
|
||||
|
||||
def test_cannot_encode(self):
|
||||
r = tresp()
|
||||
r = tutils.tresp()
|
||||
r.content = None
|
||||
assert "content-type" not in r.headers
|
||||
assert r.raw_content is None
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from netlib.http import Headers
|
||||
from netlib.tutils import treq, raises
|
||||
from mitmproxy.test.tutils import treq, raises
|
||||
from .test_message import _test_decoded_attr, _test_passthrough_attr
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import time
|
|||
from netlib.http import Headers
|
||||
from netlib.http import Response
|
||||
from netlib.http.cookies import CookieAttrs
|
||||
from netlib.tutils import raises, tresp
|
||||
from mitmproxy.test.tutils import raises, tresp
|
||||
from .test_message import _test_passthrough_attr, _test_decoded_attr
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
from netlib.http import url
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import ipaddress
|
||||
from io import BytesIO
|
||||
from netlib import socks, tcp, tutils
|
||||
from netlib import socks
|
||||
from netlib import tcp
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
def test_client_greeting():
|
||||
|
|
|
@ -11,7 +11,7 @@ from OpenSSL import SSL
|
|||
|
||||
from mitmproxy import certs
|
||||
from netlib import tcp
|
||||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
from mitmproxy import exceptions
|
||||
|
||||
from . import tservers
|
||||
|
|
|
@ -4,7 +4,7 @@ import io
|
|||
import OpenSSL
|
||||
|
||||
from netlib import tcp
|
||||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
class _ServerThread(threading.Thread):
|
||||
|
|
|
@ -3,7 +3,7 @@ import codecs
|
|||
import pytest
|
||||
|
||||
from netlib import websockets
|
||||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
|
||||
class TestFrameHeader:
|
||||
|
|
|
@ -4,7 +4,7 @@ from mock import Mock
|
|||
from netlib import http
|
||||
from netlib import tcp
|
||||
from netlib.http import http1
|
||||
from netlib.tutils import raises
|
||||
from mitmproxy.test.tutils import raises
|
||||
from mitmproxy import exceptions
|
||||
|
||||
from pathod import pathoc, language
|
||||
|
|
|
@ -3,7 +3,7 @@ import codecs
|
|||
|
||||
import hyperframe
|
||||
from netlib import tcp, http
|
||||
from netlib.tutils import raises
|
||||
from mitmproxy.test.tutils import raises
|
||||
from netlib.http import http2
|
||||
from mitmproxy import exceptions
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import urllib
|
|||
from mitmproxy.utils import data
|
||||
|
||||
from netlib import tcp
|
||||
from netlib import tutils
|
||||
from mitmproxy.test import tutils
|
||||
|
||||
from pathod import language
|
||||
from pathod import pathoc
|
||||
|
|
Loading…
Reference in New Issue