summaryrefslogtreecommitdiff
path: root/testing/tests
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-03-22 21:43:07 -0300
committerdrebs <drebs@leap.se>2017-04-04 18:27:38 +0200
commit45b73d58930a2a66394a6797c94a50c34e8f96e7 (patch)
tree395e8085ebfb7773ccba8a5c292523b4018b1b0b /testing/tests
parent4cf662b0b043579badd231f30fc4eb58f9e6f09c (diff)
[refactor] adds a PreamblePipe for preamble download
Downloading until there is a space then splitting the content was a mess. Extracted this behaviour out of DecrypterBuffer into a new component so it eases testing by introducing a single responsibility class.
Diffstat (limited to 'testing/tests')
-rw-r--r--testing/tests/pipes/test_pipes.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/testing/tests/pipes/test_pipes.py b/testing/tests/pipes/test_pipes.py
index d7db2716..42ed81ac 100644
--- a/testing/tests/pipes/test_pipes.py
+++ b/testing/tests/pipes/test_pipes.py
@@ -19,9 +19,11 @@ Tests for streaming components.
"""
from twisted.trial import unittest
from leap.soledad.client._pipes import TruncatedTailPipe
+from leap.soledad.client._pipes import PreamblePipe
+from io import BytesIO
-class TruncatedTailTestCase(unittest.TestCase):
+class TruncatedTailPipeTestCase(unittest.TestCase):
def test_tail_truncating_pipe(self):
pipe = TruncatedTailPipe(tail_size=20)
@@ -30,3 +32,20 @@ class TruncatedTailTestCase(unittest.TestCase):
pipe.write(data)
result = pipe.close()
assert result.getvalue() == 'A' * 100
+
+
+class PreamblePipeTestCase(unittest.TestCase):
+
+ def test_preamble_pipe(self):
+ remaining = BytesIO()
+ preamble = BytesIO()
+
+ def callback(dataBuffer):
+ preamble.write(dataBuffer.getvalue())
+ return remaining
+ pipe = PreamblePipe(callback)
+ payload = 'A' * 100 + ' ' + 'B' * 20
+ for data in payload:
+ pipe.write(data)
+ assert remaining.getvalue() == 'B' * 20
+ assert preamble.getvalue() == 'A' * 100