<s> import os <EOL> import unittest <EOL> import urllib2 <EOL> import json <EOL> import wptserve <EOL> from base import TestUsingServer , doc_root <EOL> class TestFileHandler ( TestUsingServer ) : <EOL> def test_not_handled ( self ) : <EOL> with self . assertRaises ( urllib2 . HTTPError ) as cm : <EOL> resp = self . request ( "<STR_LIT>" ) <EOL> self . assertEquals ( cm . exception . code , <NUM_LIT> ) <EOL> class TestRewriter ( TestUsingServer ) : <EOL> def test_rewrite ( self ) : <EOL> @ wptserve . handlers . handler <EOL> def handler ( request , response ) : <EOL> return request . request_path <EOL> route = ( "<STR_LIT:GET>" , "<STR_LIT>" , handler ) <EOL> self . server . rewriter . register ( "<STR_LIT:GET>" , "<STR_LIT>" , route [ <NUM_LIT:1> ] ) <EOL> self . server . router . register ( * route ) <EOL> resp = self . request ( "<STR_LIT>" ) <EOL> self . assertEquals ( <NUM_LIT:200> , resp . getcode ( ) ) <EOL> self . assertEquals ( "<STR_LIT>" , resp . read ( ) ) <EOL> class TestRequestHandler ( TestUsingServer ) : <EOL> def test_exception ( self ) : <EOL> @ wptserve . handlers . handler <EOL> def handler ( request , response ) : <EOL> raise Exception <EOL> route = ( "<STR_LIT:GET>" , "<STR_LIT>" , handler ) <EOL> self . server . router . register ( * route ) <EOL> with self . assertRaises ( urllib2 . HTTPError ) as cm : <EOL> resp = self . request ( "<STR_LIT>" ) <EOL> self . assertEquals ( cm . exception . code , <NUM_LIT> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
