<s> import os <EOL> import unittest <EOL> import urllib2 <EOL> import json <EOL> import time <EOL> import wptserve <EOL> from base import TestUsingServer , doc_root <EOL> class TestInputFile ( TestUsingServer ) : <EOL> def test_seek ( self ) : <EOL> @ wptserve . handlers . handler <EOL> def handler ( request , response ) : <EOL> rv = [ ] <EOL> f = request . raw_input <EOL> f . seek ( <NUM_LIT:5> ) <EOL> rv . append ( f . read ( <NUM_LIT:2> ) ) <EOL> rv . append ( f . tell ( ) ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> rv . append ( f . readline ( ) ) <EOL> rv . append ( f . tell ( ) ) <EOL> rv . append ( f . read ( - <NUM_LIT:1> ) ) <EOL> rv . append ( f . tell ( ) ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> rv . append ( f . read ( ) ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> rv . extend ( f . readlines ( ) ) <EOL> return "<STR_LIT:U+0020>" . join ( str ( item ) for item in rv ) <EOL> route = ( "<STR_LIT:POST>" , "<STR_LIT>" , handler ) <EOL> self . server . router . register ( * route ) <EOL> resp = self . request ( route [ <NUM_LIT:1> ] , method = "<STR_LIT:POST>" , body = "<STR_LIT>" ) <EOL> self . assertEquals ( <NUM_LIT:200> , resp . getcode ( ) ) <EOL> self . assertEquals ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> resp . read ( ) . split ( "<STR_LIT:U+0020>" ) ) <EOL> def test_iter ( self ) : <EOL> @ wptserve . handlers . handler <EOL> def handler ( request , response ) : <EOL> f = request . raw_input <EOL> return "<STR_LIT:U+0020>" . join ( line for line in f ) <EOL> route = ( "<STR_LIT:POST>" , "<STR_LIT>" , handler ) <EOL> self . server . router . register ( * route ) <EOL> resp = self . request ( route [ <NUM_LIT:1> ] , method = "<STR_LIT:POST>" , body = "<STR_LIT>" ) <EOL> self . assertEquals ( <NUM_LIT:200> , resp . getcode ( ) ) <EOL> self . assertEquals ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , resp . read ( ) . split ( "<STR_LIT:U+0020>" ) ) <EOL> class TestRequest ( TestUsingServer ) : <EOL> def test_body ( self ) : <EOL> @ wptserve . handlers . handler <EOL> def handler ( request , response ) : <EOL> request . raw_input . seek ( <NUM_LIT:5> ) <EOL> return request . body <EOL> route = ( "<STR_LIT:POST>" , "<STR_LIT>" , handler ) <EOL> self . server . router . register ( * route ) <EOL> resp = self . request ( route [ <NUM_LIT:1> ] , method = "<STR_LIT:POST>" , body = "<STR_LIT>" ) <EOL> self . assertEquals ( "<STR_LIT>" , resp . read ( ) ) <EOL> def test_route_match ( self ) : <EOL> @ wptserve . handlers . handler <EOL> def handler ( request , response ) : <EOL> return request . route_match [ "<STR_LIT>" ] + "<STR_LIT:U+0020>" + request . route_match [ "<STR_LIT:*>" ] <EOL> route = ( "<STR_LIT:GET>" , "<STR_LIT>" , handler ) <EOL> self . server . router . register ( * route ) <EOL> resp = self . request ( "<STR_LIT>" ) <EOL> self . assertEquals ( "<STR_LIT>" , resp . read ( ) ) <EOL> class TestAuth ( TestUsingServer ) : <EOL> def test_auth ( self ) : <EOL> @ wptserve . handlers . handler <EOL> def handler ( request , response ) : <EOL> return "<STR_LIT:U+0020>" . join ( ( request . auth . username , request . auth . password ) ) <EOL> route = ( "<STR_LIT:GET>" , "<STR_LIT>" , handler ) <EOL> self . server . router . register ( * route ) <EOL> resp = self . request ( route [ <NUM_LIT:1> ] , auth = ( "<STR_LIT:test>" , "<STR_LIT>" ) ) <EOL> self . assertEquals ( <NUM_LIT:200> , resp . getcode ( ) ) <EOL> self . assertEquals ( [ "<STR_LIT:test>" , "<STR_LIT>" ] , resp . read ( ) . split ( "<STR_LIT:U+0020>" ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
