<s> import os <EOL> import unittest <EOL> import mock <EOL> from upstream . shard import Shard <EOL> from upstream . streamer import Streamer <EOL> from upstream . exc import ConnectError , FileError , ShardError , ResponseError <EOL> class TestStreamer ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . stream = Streamer ( "<STR_LIT>" ) <EOL> self . orig_hash = None <EOL> self . uploadfile = "<STR_LIT>" <EOL> self . downloadfile = "<STR_LIT>" <EOL> self . shard = Shard ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ) <EOL> def tearDown ( self ) : <EOL> del self . stream <EOL> del self . orig_hash <EOL> del self . uploadfile <EOL> try : <EOL> os . remove ( self . downloadfile ) <EOL> except : <EOL> pass <EOL> try : <EOL> os . remove ( self . shard . filehash ) <EOL> except : <EOL> pass <EOL> del self . downloadfile <EOL> del self . shard <EOL> def test_initialization ( self ) : <EOL> self . assertEqual ( self . stream . server , "<STR_LIT>" ) <EOL> def test_check_connectivity ( self ) : <EOL> def _failing_connection ( ) : <EOL> Streamer ( "<STR_LIT>" ) <EOL> self . assertRaises ( ConnectError , _failing_connection ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_upload_form_encoded ( self , post ) : <EOL> pass <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_upload_sharded_encoded ( self , post ) : <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> self . stream . _upload_sharded_encoded ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_filestream ( self , post ) : <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> self . stream . _filestream ( '<STR_LIT>' ) <EOL> def test_upload ( self ) : <EOL> self . shard = self . stream . upload ( self . uploadfile ) <EOL> self . assertEqual ( <EOL> self . shard . filehash , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> self . shard . decryptkey , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def _failing_upload ( ) : <EOL> self . stream . upload ( "<STR_LIT>" ) <EOL> self . assertRaises ( FileError , _failing_upload ) <EOL> def test_upload_patched_404 ( self ) : <EOL> self . stream . _upload_form_encoded = mock . MagicMock ( ) <EOL> self . stream . _upload_form_encoded . return_value ( ) <EOL> self . stream . _upload_form_encoded . return_value . status_code = <NUM_LIT> <EOL> def _fourohfour ( ) : <EOL> self . stream . upload ( self . uploadfile ) <EOL> with self . assertRaises ( ResponseError ) as ex : <EOL> _fourohfour ( ) <EOL> self . assertEqual ( ex . message , "<STR_LIT>" ) <EOL> def test_upload_patched_402 ( self ) : <EOL> self . stream . _upload_form_encoded = mock . MagicMock ( ) <EOL> self . stream . _upload_form_encoded . return_value ( ) <EOL> self . stream . _upload_form_encoded . return_value . status_code = <NUM_LIT> <EOL> def _fourohtwo ( ) : <EOL> self . stream . upload ( self . uploadfile ) <EOL> with self . assertRaises ( ResponseError ) : <EOL> _fourohtwo ( ) <EOL> def test_upload_patched_500 ( self ) : <EOL> self . stream . _upload_form_encoded = mock . MagicMock ( ) <EOL> self . stream . _upload_form_encoded . return_value ( ) <EOL> self . stream . _upload_form_encoded . return_value . status_code = <NUM_LIT> <EOL> def _fivehundred ( ) : <EOL> self . stream . upload ( self . uploadfile ) <EOL> with self . assertRaises ( ResponseError ) as ex : <EOL> _fivehundred ( ) <EOL> self . assertEqual ( ex . message , "<STR_LIT>" ) <EOL> def test_upload_patched_501 ( self ) : <EOL> self . stream . _upload_form_encoded = mock . MagicMock ( ) <EOL> self . stream . _upload_form_encoded . return_value ( ) <EOL> self . stream . _upload_form_encoded . return_value . status_code = <NUM_LIT> <EOL> self . stream . _upload_form_encoded . return_value . reason = "<STR_LIT>" <EOL> def _fiveohone ( ) : <EOL> self . stream . upload ( self . uploadfile ) <EOL> with self . assertRaises ( ResponseError ) as ex : <EOL> _fiveohone ( ) <EOL> self . assertEqual ( ex . message , <EOL> "<STR_LIT>" ) <EOL> def test_upload_check_path ( self ) : <EOL> homedir = os . path . expanduser ( self . uploadfile ) <EOL> result = self . stream . check_path ( self . uploadfile ) <EOL> self . assertEqual ( homedir , result ) <EOL> with self . assertRaises ( FileError ) as ex : <EOL> self . stream . check_path ( '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> ex . message , '<STR_LIT>' ) <EOL> def test_download ( self ) : <EOL> r = self . stream . download ( self . shard ) <EOL> self . assertTrue ( r ) <EOL> self . assertEquals ( r . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( r . content ) , <NUM_LIT> ) <EOL> def test_download_exception ( self ) : <EOL> self . shard . filehash = self . shard . filehash [ : - <NUM_LIT:5> ] <EOL> with self . assertRaises ( ResponseError ) as ex : <EOL> self . stream . download ( self . shard ) <EOL> self . assertEqual ( ex . exception . response . status_code , <NUM_LIT> ) <EOL> def test_download_empty_shard ( self ) : <EOL> shard = Shard ( ) <EOL> with self . assertRaises ( ShardError ) as e : <EOL> self . stream . download ( shard ) <EOL> self . assertEqual ( str ( e . exception ) , "<STR_LIT>" ) </s>
