<s> """<STR_LIT>""" <EOL> import errno <EOL> import os . path <EOL> import unittest <EOL> import google <EOL> import mox <EOL> from google . appengine . api import appinfo <EOL> from google . appengine . tools . devappserver2 import errors <EOL> from google . appengine . tools . devappserver2 import static_files_handler <EOL> from google . appengine . tools . devappserver2 import wsgi_test_utils <EOL> class TestStaticContentHandlerHandlePath ( wsgi_test_utils . WSGITestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . mox = mox . Mox ( ) <EOL> self . mox . StubOutWithMock ( os . path , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( static_files_handler . StaticContentHandler , <EOL> '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag = { } <EOL> self . mox . UnsetStubs ( ) <EOL> def test_load_file ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> static_files_handler . StaticContentHandler . _read_file ( <EOL> '<STR_LIT>' ) . AndReturn ( '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag , <EOL> { '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } ) <EOL> def test_load_cached_file ( self ) : <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag = { <EOL> '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> static_files_handler . StaticContentHandler . _read_file ( <EOL> '<STR_LIT>' ) . AndReturn ( '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag , <EOL> { '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } ) <EOL> def test_load_head ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> static_files_handler . StaticContentHandler . _read_file ( <EOL> '<STR_LIT>' ) . AndReturn ( '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag , <EOL> { '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } ) <EOL> def test_no_permission_read ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> error = IOError ( ) <EOL> error . errno = errno . EPERM <EOL> static_files_handler . StaticContentHandler . _read_file ( <EOL> '<STR_LIT>' ) . AndRaise ( error ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT>' : '<STR_LIT:/>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> def test_cached_no_permission_read ( self ) : <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag = { <EOL> '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> error = IOError ( ) <EOL> error . errno = errno . EPERM <EOL> static_files_handler . StaticContentHandler . _read_file ( <EOL> '<STR_LIT>' ) . AndRaise ( error ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT>' : '<STR_LIT:/>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> def test_file_does_not_exist_read ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> error = IOError ( ) <EOL> error . errno = errno . ENOENT <EOL> static_files_handler . StaticContentHandler . _read_file ( <EOL> '<STR_LIT>' ) . AndRaise ( error ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT>' : '<STR_LIT:/>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> def test_file_does_not_exist_stat ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> error = IOError ( ) <EOL> error . errno = errno . ENOENT <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndRaise ( error ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT>' : '<STR_LIT:/>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> def test_if_match_without_match ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> static_files_handler . StaticContentHandler . _read_file ( <EOL> '<STR_LIT>' ) . AndReturn ( '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag , <EOL> { '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } ) <EOL> def test_if_match_no_file ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> error = IOError ( ) <EOL> error . errno = errno . ENOENT <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndRaise ( error ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag , <EOL> { } ) <EOL> def test_cached_if_match_without_match ( self ) : <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag = { <EOL> '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT:abc>' ) } <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag , <EOL> { '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT:abc>' ) } ) <EOL> def test_if_none_match_with_match ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> static_files_handler . StaticContentHandler . _read_file ( <EOL> '<STR_LIT>' ) . AndReturn ( '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag , <EOL> { '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } ) <EOL> def test_cached_if_none_match_with_match ( self ) : <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag = { <EOL> '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag , <EOL> { '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } ) <EOL> def test_custom_headers ( self ) : <EOL> http_headers = appinfo . HttpHeadersDict ( ) <EOL> http_headers [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> http_headers [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> http_headers [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> http_headers [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> http_headers [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' , <EOL> http_headers = http_headers ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> static_files_handler . StaticContentHandler . _read_file ( <EOL> '<STR_LIT>' ) . AndReturn ( '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag , <EOL> { '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } ) <EOL> def test_custom_mimetype ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> mime_type = '<STR_LIT>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> static_files_handler . StaticContentHandler . _read_file ( <EOL> '<STR_LIT>' ) . AndReturn ( '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag , <EOL> { '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } ) <EOL> def test_custom_expiration_ignored ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> expiration = '<STR_LIT>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticContentHandler ( <EOL> root_path = None , <EOL> url_map = url_map , <EOL> url_pattern = '<STR_LIT>' ) <EOL> os . path . getmtime ( '<STR_LIT>' ) . AndReturn ( <NUM_LIT> ) <EOL> static_files_handler . StaticContentHandler . _read_file ( <EOL> '<STR_LIT>' ) . AndReturn ( '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertResponse ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' , <EOL> h . _handle_path , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:GET>' } ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <EOL> static_files_handler . StaticContentHandler . _filename_to_mtime_and_etag , <EOL> { '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } ) <EOL> class TestStaticContentHandlerCheckEtagMatch ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_strong_match_required ( self ) : <EOL> self . assertTrue ( <EOL> static_files_handler . StaticContentHandler . _check_etag_match ( <EOL> '<STR_LIT>' , '<STR_LIT:abc>' , allow_weak_match = False ) ) <EOL> def test_strong_match_no_match ( self ) : <EOL> self . assertFalse ( <EOL> static_files_handler . StaticContentHandler . _check_etag_match ( <EOL> '<STR_LIT>' , '<STR_LIT:abc>' , allow_weak_match = False ) ) <EOL> def test_strong_match_with_weak_tag ( self ) : <EOL> self . assertFalse ( <EOL> static_files_handler . StaticContentHandler . _check_etag_match ( <EOL> '<STR_LIT>' , '<STR_LIT:abc>' , allow_weak_match = False ) ) <EOL> def test_strong_match_star ( self ) : <EOL> self . assertTrue ( <EOL> static_files_handler . StaticContentHandler . _check_etag_match ( <EOL> '<STR_LIT:*>' , '<STR_LIT:abc>' , allow_weak_match = False ) ) <EOL> def test_weak_match_required ( self ) : <EOL> self . assertTrue ( <EOL> static_files_handler . StaticContentHandler . _check_etag_match ( <EOL> '<STR_LIT>' , '<STR_LIT:abc>' , allow_weak_match = True ) ) <EOL> def test_weak_match_no_match ( self ) : <EOL> self . assertFalse ( <EOL> static_files_handler . StaticContentHandler . _check_etag_match ( <EOL> '<STR_LIT>' , '<STR_LIT:abc>' , allow_weak_match = True ) ) <EOL> def test_weak_match_with_weak_tag ( self ) : <EOL> self . assertTrue ( <EOL> static_files_handler . StaticContentHandler . _check_etag_match ( <EOL> '<STR_LIT>' , '<STR_LIT:abc>' , allow_weak_match = True ) ) <EOL> def test_weak_match_star ( self ) : <EOL> self . assertTrue ( <EOL> static_files_handler . StaticContentHandler . _check_etag_match ( <EOL> '<STR_LIT:*>' , '<STR_LIT:abc>' , allow_weak_match = True ) ) <EOL> def test_many_etags_match ( self ) : <EOL> self . assertTrue ( <EOL> static_files_handler . StaticContentHandler . _check_etag_match ( <EOL> '<STR_LIT>' , '<STR_LIT>' , allow_weak_match = False ) ) <EOL> def test_many_etags_no_match ( self ) : <EOL> self . assertFalse ( <EOL> static_files_handler . StaticContentHandler . _check_etag_match ( <EOL> '<STR_LIT>' , '<STR_LIT>' , allow_weak_match = False ) ) <EOL> class TestStaticFilesHandler ( wsgi_test_utils . WSGITestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . mox = mox . Mox ( ) <EOL> self . mox . StubOutWithMock ( static_files_handler . StaticContentHandler , <EOL> '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> self . mox . UnsetStubs ( ) <EOL> def test_simple_path ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> static_files = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticFilesHandler ( root_path = '<STR_LIT>' , <EOL> url_map = url_map ) <EOL> match = h . match ( '<STR_LIT:/>' ) <EOL> self . assertTrue ( match ) <EOL> self . assertFalse ( h . match ( '<STR_LIT>' ) ) <EOL> static_files_handler . StaticContentHandler . _handle_path ( <EOL> os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> { } , <EOL> mox . IgnoreArg ( ) ) . AndReturn ( '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> h . handle ( match , { } , None ) ) <EOL> self . mox . VerifyAll ( ) <EOL> def test_patterned_path ( self ) : <EOL> url_map = appinfo . URLMap ( url = r'<STR_LIT>' , <EOL> static_files = r'<STR_LIT>' ) <EOL> h = static_files_handler . StaticFilesHandler ( root_path = '<STR_LIT>' , <EOL> url_map = url_map ) <EOL> match = h . match ( '<STR_LIT>' ) <EOL> self . assertTrue ( match ) <EOL> self . assertFalse ( h . match ( '<STR_LIT:/>' ) ) <EOL> static_files_handler . StaticContentHandler . _handle_path ( <EOL> os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> { } , <EOL> mox . IgnoreArg ( ) ) . AndReturn ( '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> h . handle ( match , { } , None ) ) <EOL> self . mox . VerifyAll ( ) <EOL> def test_invalid_regex ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT>' , <EOL> static_files = '<STR_LIT>' ) <EOL> self . assertRaises ( errors . InvalidAppConfigError , <EOL> static_files_handler . StaticFilesHandler , <EOL> root_path = '<STR_LIT>' , <EOL> url_map = url_map ) <EOL> class TestStaticDirHandler ( wsgi_test_utils . WSGITestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . mox = mox . Mox ( ) <EOL> self . mox . StubOutWithMock ( static_files_handler . StaticContentHandler , <EOL> '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> self . mox . UnsetStubs ( ) <EOL> def test_simple_path ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT>' , <EOL> static_dir = '<STR_LIT>' ) <EOL> h = static_files_handler . StaticDirHandler ( root_path = '<STR_LIT>' , <EOL> url_map = url_map ) <EOL> match = h . match ( '<STR_LIT>' ) <EOL> self . assertTrue ( match ) <EOL> self . assertFalse ( h . match ( '<STR_LIT>' ) ) <EOL> static_files_handler . StaticContentHandler . _handle_path ( <EOL> os . path . join ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> { } , <EOL> mox . IgnoreArg ( ) ) . AndReturn ( '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> h . handle ( match , { } , None ) ) <EOL> self . mox . VerifyAll ( ) <EOL> def test_invalid_regex ( self ) : <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT>' , <EOL> static_files = '<STR_LIT>' ) <EOL> self . assertRaises ( errors . InvalidAppConfigError , <EOL> static_files_handler . StaticDirHandler , <EOL> root_path = '<STR_LIT>' , <EOL> url_map = url_map ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
