def setup_http_server():
http_requests = []<EOL>error_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>tasks_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>tasks_next_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>tasks_empty_body = read_file('<STR_LIT>')<EOL>tasks_trans_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>tasks_trans_next_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>users_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>jane_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>janes_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>jdoe_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>jrae_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>jsmith_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>phids_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>herald_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>bugreport_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>teamdevel_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>phids_users = {<EOL>'<STR_LIT>': jane_body,<EOL>'<STR_LIT>': janes_body,<EOL>'<STR_LIT>': jdoe_body,<EOL>'<STR_LIT>': jrae_body,<EOL>'<STR_LIT>': jsmith_body<EOL>}<EOL>phids = {<EOL>'<STR_LIT>': herald_body,<EOL>'<STR_LIT>': bugreport_body,<EOL>'<STR_LIT>': teamdevel_body<EOL>}<EOL>def request_callback(method, uri, headers):<EOL><INDENT>last_request = httpretty.last_request()<EOL>params = json.loads(last_request.parsed_body['<STR_LIT>'][<NUM_LIT:0>])<EOL>if uri == PHABRICATOR_TASKS_URL:<EOL><INDENT>if params['<STR_LIT>']['<STR_LIT>'] == <NUM_LIT>:<EOL><INDENT>body = tasks_next_body<EOL><DEDENT>elif params['<STR_LIT>']['<STR_LIT>'] == <NUM_LIT>:<EOL><INDENT>body = tasks_empty_body<EOL><DEDENT>elif '<STR_LIT>' not in params:<EOL><INDENT>body = tasks_body<EOL><DEDENT>else:<EOL><INDENT>body = tasks_next_body<EOL><DEDENT><DEDENT>elif uri == PHABRICATOR_TRANSACTIONS_URL:<EOL><INDENT>if <NUM_LIT> in params['<STR_LIT>']:<EOL><INDENT>body = tasks_trans_body<EOL><DEDENT>else:<EOL><INDENT>body = tasks_trans_next_body<EOL><DEDENT><DEDENT>elif uri == PHABRICATOR_USERS_URL:<EOL><INDENT>if len(params['<STR_LIT>']) == <NUM_LIT:4>:<EOL><INDENT>body = users_body<EOL><DEDENT>else:<EOL><INDENT>body = phids_users[params['<STR_LIT>'][<NUM_LIT:0>]]<EOL><DEDENT><DEDENT>elif uri == PHABRICATOR_PHIDS_URL:<EOL><INDENT>if len(params['<STR_LIT>']) == <NUM_LIT:2>:<EOL><INDENT>body = phids_body<EOL><DEDENT>else:<EOL><INDENT>body = phids[params['<STR_LIT>'][<NUM_LIT:0>]]<EOL><DEDENT><DEDENT>elif uri == PHABRICATOR_API_ERROR_URL:<EOL><INDENT>body = error_body<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT>http_requests.append(last_request)<EOL>return (<NUM_LIT:200>, headers, body)<EOL><DEDENT>httpretty.register_uri(httpretty.POST,<EOL>PHABRICATOR_TASKS_URL,<EOL>responses=[<EOL>httpretty.Response(body=request_callback)<EOL>])<EOL>httpretty.register_uri(httpretty.POST,<EOL>PHABRICATOR_TRANSACTIONS_URL,<EOL>responses=[<EOL>httpretty.Response(body=request_callback)<EOL>])<EOL>httpretty.register_uri(httpretty.POST,<EOL>PHABRICATOR_USERS_URL,<EOL>responses=[<EOL>httpretty.Response(body=request_callback)<EOL>])<EOL>httpretty.register_uri(httpretty.POST,<EOL>PHABRICATOR_PHIDS_URL,<EOL>responses=[<EOL>httpretty.Response(body=request_callback)<EOL>])<EOL>httpretty.register_uri(httpretty.POST,<EOL>PHABRICATOR_API_ERROR_URL,<EOL>responses=[<EOL>httpretty.Response(body=request_callback)<EOL>])<EOL>return http_requests<EOL>
Setup a mock HTTP server