<s> import os <EOL> import six <EOL> import time <EOL> import shutil <EOL> import inspect <EOL> import unittest2 as unittest <EOL> from six import BytesIO <EOL> from pyspider import run <EOL> from pyspider . libs import utils <EOL> from tests import data_sample_handler , data_handler <EOL> @ unittest . skipIf ( six . PY3 , '<STR_LIT>' ) <EOL> class TestWebDav ( unittest . TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( self ) : <EOL> import easywebdav <EOL> shutil . rmtree ( '<STR_LIT>' , ignore_errors = True ) <EOL> os . makedirs ( '<STR_LIT>' ) <EOL> ctx = run . cli . make_context ( '<STR_LIT:test>' , [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] , None , obj = utils . ObjectDict ( testing_mode = True ) ) <EOL> self . ctx = run . cli . invoke ( ctx ) <EOL> ctx = run . webui . make_context ( '<STR_LIT>' , [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] , self . ctx ) <EOL> self . app = run . webui . invoke ( ctx ) <EOL> self . app_thread = utils . run_in_thread ( self . app . run ) <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> self . webdav = easywebdav . connect ( '<STR_LIT:localhost>' , port = <NUM_LIT> , path = '<STR_LIT>' ) <EOL> self . webdav_up = easywebdav . connect ( '<STR_LIT:localhost>' , port = <NUM_LIT> , path = '<STR_LIT>' , <EOL> username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> @ classmethod <EOL> def tearDownClass ( self ) : <EOL> for each in self . ctx . obj . instances : <EOL> each . quit ( ) <EOL> self . app_thread . join ( ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> assert not utils . check_port_open ( <NUM_LIT> ) <EOL> assert not utils . check_port_open ( <NUM_LIT> ) <EOL> assert not utils . check_port_open ( <NUM_LIT> ) <EOL> assert not utils . check_port_open ( <NUM_LIT> ) <EOL> assert not utils . check_port_open ( <NUM_LIT> ) <EOL> shutil . rmtree ( '<STR_LIT>' , ignore_errors = True ) <EOL> def test_10_ls ( self ) : <EOL> self . assertEqual ( len ( self . webdav . ls ( ) ) , <NUM_LIT:1> ) <EOL> def test_20_create_error ( self ) : <EOL> import easywebdav <EOL> with self . assertRaises ( easywebdav . OperationFailed ) : <EOL> self . webdav . upload ( inspect . getsourcefile ( data_sample_handler ) , <EOL> '<STR_LIT>' ) <EOL> with self . assertRaises ( easywebdav . OperationFailed ) : <EOL> self . webdav . upload ( inspect . getsourcefile ( data_sample_handler ) , <EOL> '<STR_LIT>' ) <EOL> def test_30_create_ok ( self ) : <EOL> self . webdav . upload ( inspect . getsourcefile ( data_handler ) , '<STR_LIT>' ) <EOL> self . webdav . upload ( inspect . getsourcefile ( data_sample_handler ) , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( self . webdav . ls ( ) ) , <NUM_LIT:3> ) <EOL> def test_40_get_404 ( self ) : <EOL> io = BytesIO ( ) <EOL> import easywebdav <EOL> with self . assertRaises ( easywebdav . OperationFailed ) : <EOL> self . webdav . download ( '<STR_LIT>' , io ) <EOL> io . close ( ) <EOL> def test_50_get ( self ) : <EOL> io = BytesIO ( ) <EOL> self . webdav . download ( '<STR_LIT>' , io ) <EOL> self . assertEqual ( inspect . getsource ( data_handler ) , io . getvalue ( ) ) <EOL> io . close ( ) <EOL> io = BytesIO ( ) <EOL> self . webdav . download ( '<STR_LIT>' , io ) <EOL> self . assertEqual ( inspect . getsource ( data_sample_handler ) , io . getvalue ( ) ) <EOL> io . close ( ) <EOL> def test_60_edit ( self ) : <EOL> self . webdav . upload ( inspect . getsourcefile ( data_handler ) , '<STR_LIT>' ) <EOL> def test_70_get ( self ) : <EOL> io = BytesIO ( ) <EOL> self . webdav . download ( '<STR_LIT>' , io ) <EOL> self . assertEqual ( inspect . getsource ( data_handler ) , io . getvalue ( ) ) <EOL> io . close ( ) <EOL> def test_80_password ( self ) : <EOL> import requests <EOL> rv = requests . post ( '<STR_LIT>' , data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> self . assertEqual ( rv . status_code , <NUM_LIT:200> ) <EOL> import easywebdav <EOL> with self . assertRaises ( easywebdav . OperationFailed ) : <EOL> self . webdav . upload ( inspect . getsourcefile ( data_sample_handler ) , '<STR_LIT>' ) <EOL> self . webdav_up . upload ( inspect . getsourcefile ( data_sample_handler ) , '<STR_LIT>' ) </s>
