From 45b73d58930a2a66394a6797c94a50c34e8f96e7 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Wed, 22 Mar 2017 21:43:07 -0300 Subject: [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. --- testing/tests/pipes/test_pipes.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'testing/tests/pipes/test_pipes.py') 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 -- cgit v1.2.3