diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-06-09 13:28:43 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-06-09 13:28:43 +1200 |
commit | c421c41307ce1ced06dae9f1d37fb516e6437f1e (patch) | |
tree | 4a93a3fedd5c9f226b8b675e76301557ebee97c9 /test | |
parent | 90cb84b53629d0a8807b3a8992acc32dd93a9a63 (diff) | |
download | mitmproxy-c421c41307ce1ced06dae9f1d37fb516e6437f1e.tar.gz mitmproxy-c421c41307ce1ced06dae9f1d37fb516e6437f1e.tar.bz2 mitmproxy-c421c41307ce1ced06dae9f1d37fb516e6437f1e.zip |
Remove odict
- Adds default implementations for _kconv and _reduce_values to MultiDict.
Without these, operations fail in really, really non-obvious ways.
- Replace the remaining few instances of ODict
Fixes #1159
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/test_contentview.py | 6 | ||||
-rw-r--r-- | test/netlib/test_multidict.py | 4 | ||||
-rw-r--r-- | test/netlib/test_odict.py | 143 |
3 files changed, 3 insertions, 150 deletions
diff --git a/test/mitmproxy/test_contentview.py b/test/mitmproxy/test_contentview.py index f5ba45a6..667a36fe 100644 --- a/test/mitmproxy/test_contentview.py +++ b/test/mitmproxy/test_contentview.py @@ -1,8 +1,8 @@ from mitmproxy.exceptions import ContentViewException from netlib.http import Headers -from netlib.odict import ODict from netlib import encoding from netlib.http import url +from netlib import multidict import mitmproxy.contentviews as cv from . import tutils @@ -55,7 +55,7 @@ class TestContentView: f = v( "", headers=Headers(), - query=ODict([("foo", "bar")]), + query=multidict.MultiDict([("foo", "bar")]), ) assert f[0] == "Query" @@ -175,7 +175,7 @@ Larry def test_view_query(self): d = "" v = cv.ViewQuery() - f = v(d, query=ODict([("foo", "bar")])) + f = v(d, query=multidict.MultiDict([("foo", "bar")])) assert f[0] == "Query" assert [x for x in f[1]] == [[("header", "foo: "), ("text", "bar")]] diff --git a/test/netlib/test_multidict.py b/test/netlib/test_multidict.py index a35d5cc5..038441e7 100644 --- a/test/netlib/test_multidict.py +++ b/test/netlib/test_multidict.py @@ -4,10 +4,6 @@ from netlib.multidict import MultiDict, ImmutableMultiDict, MultiDictView class _TMulti(object): @staticmethod - def _reduce_values(values): - return values[0] - - @staticmethod def _kconv(key): return key.lower() diff --git a/test/netlib/test_odict.py b/test/netlib/test_odict.py deleted file mode 100644 index b6fd6401..00000000 --- a/test/netlib/test_odict.py +++ /dev/null @@ -1,143 +0,0 @@ -from netlib import odict, tutils - - -class TestODict(object): - - def test_repr(self): - h = odict.ODict() - h["one"] = ["two"] - assert repr(h) - - def test_str_err(self): - h = odict.ODict() - with tutils.raises(ValueError): - h["key"] = u"foo" - with tutils.raises(ValueError): - h["key"] = b"foo" - - def test_getset_state(self): - od = odict.ODict() - od.add("foo", 1) - od.add("foo", 2) - od.add("bar", 3) - state = od.get_state() - nd = odict.ODict.from_state(state) - assert nd == od - b = odict.ODict() - b.set_state(state) - assert b == od - - def test_iter(self): - od = odict.ODict() - assert not [i for i in od] - od.add("foo", 1) - assert [i for i in od] - - def test_keys(self): - od = odict.ODict() - assert not od.keys() - od.add("foo", 1) - assert od.keys() == ["foo"] - od.add("foo", 2) - assert od.keys() == ["foo"] - od.add("bar", 2) - assert len(od.keys()) == 2 - - def test_copy(self): - od = odict.ODict() - od.add("foo", 1) - od.add("foo", 2) - od.add("bar", 3) - assert od == od.copy() - assert not od != od.copy() - - def test_del(self): - od = odict.ODict() - od.add("foo", 1) - od.add("Foo", 2) - od.add("bar", 3) - del od["foo"] - assert len(od.lst) == 2 - - def test_replace(self): - od = odict.ODict() - od.add("one", "two") - od.add("two", "one") - assert od.replace("one", "vun") == 2 - assert od.lst == [ - ["vun", "two"], - ["two", "vun"], - ] - - def test_get(self): - od = odict.ODict() - od.add("one", "two") - assert od.get("one") == ["two"] - assert od.get("two") is None - - def test_get_first(self): - od = odict.ODict() - od.add("one", "two") - od.add("one", "three") - assert od.get_first("one") == "two" - assert od.get_first("two") is None - - def test_extend(self): - a = odict.ODict([["a", "b"], ["c", "d"]]) - b = odict.ODict([["a", "b"], ["e", "f"]]) - a.extend(b) - assert len(a) == 4 - assert a["a"] == ["b", "b"] - - -class TestODictCaseless(object): - - def test_override(self): - o = odict.ODictCaseless() - o.add('T', 'application/x-www-form-urlencoded; charset=UTF-8') - o["T"] = ["foo"] - assert o["T"] == ["foo"] - - def test_case_preservation(self): - od = odict.ODictCaseless() - od["Foo"] = ["1"] - assert "foo" in od - assert od.items()[0][0] == "Foo" - assert od.get("foo") == ["1"] - assert od.get("foo", [""]) == ["1"] - assert od.get("Foo", [""]) == ["1"] - assert od.get("xx", "yy") == "yy" - - def test_del(self): - od = odict.ODictCaseless() - od.add("foo", 1) - od.add("Foo", 2) - od.add("bar", 3) - del od["foo"] - assert len(od) == 1 - - def test_keys(self): - od = odict.ODictCaseless() - assert not od.keys() - od.add("foo", 1) - assert od.keys() == ["foo"] - od.add("Foo", 2) - assert od.keys() == ["foo"] - od.add("bar", 2) - assert len(od.keys()) == 2 - - def test_add_order(self): - od = odict.ODict( - [ - ["one", "uno"], - ["two", "due"], - ["three", "tre"], - ] - ) - od["two"] = ["foo", "bar"] - assert od.lst == [ - ["one", "uno"], - ["two", "foo"], - ["three", "tre"], - ["two", "bar"], - ] |