<s> from django . test import TestCase <EOL> from django . test import RequestFactory <EOL> from davvy . base import WebDAV <EOL> from django . test . utils import override_settings <EOL> from django . contrib . auth . models import User <EOL> import base64 <EOL> from django . contrib . sessions . middleware import SessionMiddleware <EOL> import os . path <EOL> @ override_settings ( DAVVY_STORAGE_PATH = '<STR_LIT>' ) <EOL> class WebDAVTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . username = '<STR_LIT>' <EOL> self . view = WebDAV . as_view ( root = '<STR_LIT>' ) <EOL> self . user = User . objects . create_user ( <EOL> self . username , '<STR_LIT>' , self . username ) <EOL> self . auth = '<STR_LIT>' + base64 . b64encode ( '<STR_LIT>' . format ( self . username , self . username ) ) <EOL> self . middleware = SessionMiddleware ( ) <EOL> self . factory = RequestFactory ( ) <EOL> self . base = '<STR_LIT>' + self . username <EOL> def test_putandget ( self , resource_name = '<STR_LIT>' ) : <EOL> uri = os . path . join ( self . base , resource_name ) <EOL> request = self . factory . put ( uri , <EOL> content_type = '<STR_LIT>' , <EOL> data = open ( '<STR_LIT>' ) . read ( ) , <EOL> HTTP_AUTHORIZATION = self . auth , <EOL> ) <EOL> self . middleware . process_request ( request ) <EOL> response = self . view ( request , self . username , resource_name ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> request = self . factory . get ( uri , HTTP_AUTHORIZATION = self . auth ) <EOL> self . middleware . process_request ( request ) <EOL> response = self . view ( request , self . username , resource_name ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( response . streaming_content ) , open ( '<STR_LIT>' ) . read ( ) ) <EOL> def test_mkcol ( self , resource_name = '<STR_LIT>' ) : <EOL> uri = os . path . join ( self . base , resource_name ) <EOL> request = self . factory . generic ( '<STR_LIT>' , uri , <EOL> HTTP_AUTHORIZATION = self . auth , <EOL> ) <EOL> self . middleware . process_request ( request ) <EOL> response = self . view ( request , self . username , resource_name ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . test_putandget ( resource_name + '<STR_LIT>' ) <EOL> def test_delete_not_empty_coll ( self ) : <EOL> self . test_mkcol ( '<STR_LIT>' ) <EOL> uri = os . path . join ( self . base , '<STR_LIT>' ) <EOL> request = self . factory . generic ( '<STR_LIT>' , uri , <EOL> HTTP_AUTHORIZATION = self . auth , <EOL> HTTP_DEPTH = '<STR_LIT:0>' , <EOL> ) <EOL> self . middleware . process_request ( request ) <EOL> response = self . view ( request , self . username , '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_delete_coll ( self ) : <EOL> self . test_mkcol ( '<STR_LIT>' ) <EOL> uri = os . path . join ( self . base , '<STR_LIT>' ) <EOL> request = self . factory . generic ( '<STR_LIT>' , uri , <EOL> HTTP_AUTHORIZATION = self . auth , <EOL> ) <EOL> self . middleware . process_request ( request ) <EOL> response = self . view ( request , self . username , '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_delete_resource ( self , resource_name = '<STR_LIT>' ) : <EOL> self . test_putandget ( resource_name ) <EOL> uri = os . path . join ( self . base , resource_name ) <EOL> request = self . factory . generic ( '<STR_LIT>' , uri , <EOL> HTTP_AUTHORIZATION = self . auth , <EOL> ) <EOL> self . middleware . process_request ( request ) <EOL> response = self . view ( request , self . username , resource_name ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) </s>
