summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2020-02-01 12:59:51 +0200
committerYuval Adam <_@yuv.al>2020-02-01 12:59:51 +0200
commitb0668017d1d6266d0420d82a0c6467138d1e1b21 (patch)
tree53ba9a0664b86ae054424da634cb112e2dea41c0 /tests
parent8ecb86371b2cb99e0460b15320c2ffbd77ced138 (diff)
Run black on entire codebase
Diffstat (limited to 'tests')
-rw-r--r--tests/test_parse.py67
-rw-r--r--tests/test_viewstate.py21
2 files changed, 47 insertions, 41 deletions
diff --git a/tests/test_parse.py b/tests/test_parse.py
index f9d445f..fea1fd4 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -8,76 +8,83 @@ from viewstate import *
class TestParse(object):
def test_const_value(self):
- vs = ViewState(raw=b'\xff\x01\x67')
+ vs = ViewState(raw=b"\xff\x01\x67")
assert vs.decode() is True
def test_int_value(self):
- vs = ViewState(raw=b'\xff\x01\x02\x88\x01')
+ vs = ViewState(raw=b"\xff\x01\x02\x88\x01")
assert vs.decode() == 136
def test_string_value(self):
- s = 'abcdefghij'
- vs = ViewState(raw=b'\xff\x01\x05' + bytes([len(s)]) + s.encode())
+ s = "abcdefghij"
+ vs = ViewState(raw=b"\xff\x01\x05" + bytes([len(s)]) + s.encode())
assert vs.decode() == s
def test_simple_dict(self):
- vs = ViewState(raw=b'\xff\x01\x18\x02\x05\x01a\x05\x01b\x05\x01c\x05\x01d')
- assert vs.decode() == {'a': 'b', 'c': 'd'}
+ vs = ViewState(raw=b"\xff\x01\x18\x02\x05\x01a\x05\x01b\x05\x01c\x05\x01d")
+ assert vs.decode() == {"a": "b", "c": "d"}
def test_simple_list(self):
- vs = ViewState(raw=b'\xff\x01\x16\x05\x05\x01a\x05\x01b\x05\x01c\x05\x01d\x05\x01e')
- assert vs.decode() == ['a', 'b', 'c', 'd', 'e']
+ vs = ViewState(
+ raw=b"\xff\x01\x16\x05\x05\x01a\x05\x01b\x05\x01c\x05\x01d\x05\x01e"
+ )
+ assert vs.decode() == ["a", "b", "c", "d", "e"]
def test_simple_pair(self):
- vs = ViewState(raw=b'\xff\x01\x0f\x67\x68')
+ vs = ViewState(raw=b"\xff\x01\x0f\x67\x68")
assert vs.decode() == (True, False)
def test_simple_triplet(self):
- vs = ViewState(raw=b'\xff\x01\x10\x67\x68\x67')
+ vs = ViewState(raw=b"\xff\x01\x10\x67\x68\x67")
assert vs.decode() == (True, False, True)
- @pytest.mark.skip(reason='Color parsing is not yet supported')
+ @pytest.mark.skip(reason="Color parsing is not yet supported")
def test_color(self):
- vs = ViewState(raw=b'\xff\x01\n\x91\x01')
- assert vs.decode() == 'Color: Salmon'
+ vs = ViewState(raw=b"\xff\x01\n\x91\x01")
+ assert vs.decode() == "Color: Salmon"
def test_rgba(self):
- vs = ViewState(raw=b'\xff\x01\x09\x10\x20\x30\x40')
- assert vs.decode() == 'RGBA(16,32,48,64)'
+ vs = ViewState(raw=b"\xff\x01\x09\x10\x20\x30\x40")
+ assert vs.decode() == "RGBA(16,32,48,64)"
def test_formatted_string(self):
vs = ViewState()
- s1 = 'System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
- s2 = '6111733106'
- vs.raw = b'\xff\x01()' + bytes([len(s1)]) + s1.encode() + bytes([len(s2)]) + s2.encode()
- assert vs.decode() == 'Formatted string: {} type ref {}'.format(s2, s1)
+ s1 = "System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
+ s2 = "6111733106"
+ vs.raw = (
+ b"\xff\x01()"
+ + bytes([len(s1)])
+ + s1.encode()
+ + bytes([len(s2)])
+ + s2.encode()
+ )
+ assert vs.decode() == "Formatted string: {} type ref {}".format(s2, s1)
- @pytest.mark.skip(reason='Datetime parsing not yet supported')
+ @pytest.mark.skip(reason="Datetime parsing not yet supported")
def test_datetime(self):
vs = ViewState()
- vs.raw = b'\xff\x01\x06\x000Po\x9b\x87\xd5\x88'
+ vs.raw = b"\xff\x01\x06\x000Po\x9b\x87\xd5\x88"
assert vs.decode() == datetime(2018, 3, 11, 22)
- vs.raw = b'\xff\x01\x06\x00\xf0\xb9\x99d\x88\xd5\x88'
+ vs.raw = b"\xff\x01\x06\x00\xf0\xb9\x99d\x88\xd5\x88"
assert vs.decode() == datetime(2018, 3, 12, 22)
def test_complex_pair(self):
vs = ViewState()
- vs.raw = b'\xff\x01\x0f\x67\x0f\x68\x66'
+ vs.raw = b"\xff\x01\x0f\x67\x0f\x68\x66"
assert vs.decode() == (True, (False, 0))
- vs.raw = b'\xff\x01\x0f\x0f\x67\x68\x66'
+ vs.raw = b"\xff\x01\x0f\x0f\x67\x68\x66"
assert vs.decode() == ((True, False), 0)
- vs.raw = b'\xff\x01\x0f\x0f\x67\x05\x061q2w3e\x66'
- assert vs.decode() == ((True, '1q2w3e'), 0)
+ vs.raw = b"\xff\x01\x0f\x0f\x67\x05\x061q2w3e\x66"
+ assert vs.decode() == ((True, "1q2w3e"), 0)
def test_parse_unknown(self):
with pytest.raises(ViewStateException):
- vs = ViewState(raw=b'\xff\x01\x99\x99\x99')
+ vs = ViewState(raw=b"\xff\x01\x99\x99\x99")
assert vs.decode()
def test_parse_samples(self):
- for root, dirs, files in walk('tests/samples'):
+ for root, dirs, files in walk("tests/samples"):
for f in files:
- with open(join(root, f), 'r') as t:
+ with open(join(root, f), "r") as t:
vs = ViewState(t.read())
_ = vs.decode()
-
diff --git a/tests/test_viewstate.py b/tests/test_viewstate.py
index 9cc9285..628e1e0 100644
--- a/tests/test_viewstate.py
+++ b/tests/test_viewstate.py
@@ -6,43 +6,42 @@ from viewstate import *
class TestViewState(object):
-
def test_blank(self):
vs = ViewState()
assert not vs.is_valid()
def test_is_valid(self):
- for root, dirs, files in walk('tests/samples'):
+ for root, dirs, files in walk("tests/samples"):
for f in files:
- with open(join(root, f), 'r') as t:
+ with open(join(root, f), "r") as t:
vs = ViewState(t.read())
assert vs.is_valid() is True
def test_invalid_base64(self):
with pytest.raises(ViewStateException):
- vs = ViewState('hello')
+ vs = ViewState("hello")
def test_invalid_decode(self):
with pytest.raises(ViewStateException):
- vs = ViewState(raw=b'\x01\x02')
+ vs = ViewState(raw=b"\x01\x02")
vs.decode()
def test_no_signature(self):
- vs = ViewState(raw=b'\xff\x01e')
+ vs = ViewState(raw=b"\xff\x01e")
vs.decode()
assert vs.mac is None
assert vs.signature is None
def test_macs(self):
MAC_LENGTHS = {
- 'hmac_sha1': 20,
- 'hmac_sha256': 32,
- 'unknown': 5 # could be any other value
+ "hmac_sha1": 20,
+ "hmac_sha256": 32,
+ "unknown": 5, # could be any other value
}
for mac, n in MAC_LENGTHS.items():
- sig = b'\x55' * n # not a real signature, just testing length
- vs = ViewState(raw=b'\xff\x01d' + sig)
+ sig = b"\x55" * n # not a real signature, just testing length
+ vs = ViewState(raw=b"\xff\x01d" + sig)
vs.decode()
assert vs.mac == mac
assert vs.signature == sig