Skip to content

Commit

Permalink
netlib.tutils -> mitmproxy.test.tutils
Browse files Browse the repository at this point in the history
There's a LOT more to be done refactoring our different conflicting test utils.
  • Loading branch information
cortesi committed Oct 19, 2016
1 parent 9491d85 commit 853e03a
Show file tree
Hide file tree
Showing 38 changed files with 104 additions and 104 deletions.
4 changes: 1 addition & 3 deletions netlib/tutils.py → mitmproxy/test/tutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
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):
Expand Down
2 changes: 1 addition & 1 deletion pathod/pathoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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
Expand Down
10 changes: 5 additions & 5 deletions test/mitmproxy/addons/test_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mitmproxy.tools import dump
from mitmproxy import http
from mitmproxy import proxy
import netlib.tutils
import mitmproxy.test.tutils
import mock


Expand Down Expand Up @@ -38,19 +38,19 @@ def test_simple(self):
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)
assert sio.getvalue()

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)
Expand All @@ -60,7 +60,7 @@ def test_simple(self):
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()
Expand Down
6 changes: 3 additions & 3 deletions test/mitmproxy/addons/test_serverplayback.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -244,7 +244,7 @@ def test_server_playback_full(self):
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()
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_server_playback_kill(self):
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()
Expand Down
2 changes: 1 addition & 1 deletion test/mitmproxy/addons/test_stickycookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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():
Expand Down
12 changes: 6 additions & 6 deletions test/mitmproxy/console/test_master.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -59,13 +59,13 @@ def _add_request(self, state):

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)

Expand Down Expand Up @@ -127,12 +127,12 @@ def test_basic(self):
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
6 changes: 3 additions & 3 deletions test/mitmproxy/mastertest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import contextlib

from . import tutils
import netlib.tutils
import mitmproxy.test.tutils

from mitmproxy import master
from mitmproxy import io
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/mitmproxy/protocol/test_http1.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
2 changes: 1 addition & 1 deletion test/mitmproxy/test_certs.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
4 changes: 2 additions & 2 deletions test/mitmproxy/test_contentview.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import mitmproxy.contentviews as cv
from . import tutils
import netlib.tutils
import mitmproxy.test.tutils

try:
import pyamf
Expand Down Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion test/mitmproxy/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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:
Expand Down
2 changes: 1 addition & 1 deletion test/mitmproxy/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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

Expand Down
28 changes: 14 additions & 14 deletions test/mitmproxy/test_flow.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_match(self):

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()
Expand Down Expand Up @@ -212,15 +212,15 @@ def test_flow(self):
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

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

Expand Down Expand Up @@ -252,7 +252,7 @@ def test_set_view_filter(self):
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)
Expand Down Expand Up @@ -284,7 +284,7 @@ def _add_request(self, state):
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):
Expand Down Expand Up @@ -444,11 +444,11 @@ def test_all(self):
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

Expand All @@ -473,7 +473,7 @@ def test_simple(self):
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"

Expand All @@ -494,7 +494,7 @@ def test_get_url(self):
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"
Expand All @@ -504,7 +504,7 @@ def test_replace(self):
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"]
Expand All @@ -514,7 +514,7 @@ def test_constrain_encoding(self):
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"

Expand All @@ -528,15 +528,15 @@ def test_simple(self):
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
assert b"foo" not in r.content
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"

Expand Down
8 changes: 4 additions & 4 deletions test/mitmproxy/test_flow_export.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/mitmproxy/test_optmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from mitmproxy import optmanager
from mitmproxy import exceptions
from netlib import tutils
from mitmproxy.test import tutils


class TO(optmanager.OptManager):
Expand Down
Loading

0 comments on commit 853e03a

Please sign in to comment.