<s> import logging <EOL> from os import makedirs , path <EOL> from shutil import rmtree <EOL> from urllib import urlencode <EOL> from dulwich . errors import NotGitRepository <EOL> from dulwich . repo import Repo <EOL> from tornado . testing import AsyncHTTPTestCase <EOL> from tornado . web import Application <EOL> from magpie . server import make_app <EOL> logging . getLogger ( '<STR_LIT>' ) . setLevel ( logging . ERROR ) <EOL> APP = None <EOL> class BaseTest ( AsyncHTTPTestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . path = path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not path . exists ( cls . path ) : <EOL> makedirs ( cls . path ) <EOL> try : <EOL> cls . repo = Repo ( cls . path ) <EOL> except NotGitRepository : <EOL> cls . repo = Repo . init ( cls . path ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> rmtree ( cls . path ) <EOL> def get_app ( self ) : <EOL> global APP <EOL> if APP is None : <EOL> APP = make_app ( path . join ( path . dirname ( __file__ ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> return APP <EOL> def get ( self , url , allow_errors = False ) : <EOL> self . http_client . fetch ( self . get_url ( url ) , self . stop ) <EOL> res = self . wait ( ) <EOL> if not allow_errors : <EOL> self . assertEqual ( <NUM_LIT:200> , int ( res . code ) ) <EOL> return res <EOL> def post ( self , url , allow_errors = False , ** kwargs ) : <EOL> self . http_client . fetch ( self . get_url ( url ) , method = '<STR_LIT:POST>' , <EOL> body = urlencode ( kwargs ) , <EOL> callback = self . stop ) <EOL> res = self . wait ( ) <EOL> if not allow_errors : <EOL> self . assertEqual ( <NUM_LIT:200> , int ( res . code ) ) <EOL> return res </s>
