def setup_http_server(rate_limit=-<NUM_LIT:1>, reset_rate_limit=-<NUM_LIT:1>):
http_requests = []<EOL>events_bodies = [<EOL>read_file('<STR_LIT>', '<STR_LIT:rb>'),<EOL>read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>]<EOL>events_range_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>events_empty_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>event_comments_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>event_rsvps_body = read_file('<STR_LIT>', '<STR_LIT:rb>')<EOL>def request_callback(method, uri, headers, too_many_requests=False):<EOL><INDENT>last_request = httpretty.last_request()<EOL>if uri.startswith(MEETUP_EVENT_1_COMMENTS_URL):<EOL><INDENT>body = event_comments_body<EOL><DEDENT>elif uri.startswith(MEETUP_EVENT_2_COMMENTS_URL):<EOL><INDENT>body = event_comments_body<EOL><DEDENT>elif uri.startswith(MEETUP_EVENT_3_COMMENTS_URL):<EOL><INDENT>body = event_comments_body<EOL><DEDENT>elif uri.startswith(MEETUP_EVENT_1_RSVPS_URL):<EOL><INDENT>body = event_rsvps_body<EOL><DEDENT>elif uri.startswith(MEETUP_EVENT_2_RSVPS_URL):<EOL><INDENT>body = event_rsvps_body<EOL><DEDENT>elif uri.startswith(MEETUP_EVENT_3_RSVPS_URL):<EOL><INDENT>body = event_rsvps_body<EOL><DEDENT>elif uri.startswith(MEETUP_EVENTS_URL):<EOL><INDENT>params = last_request.querystring<EOL>scroll = params.get('<STR_LIT>', None)<EOL>if scroll and scroll[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>body = events_bodies[-<NUM_LIT:1>]<EOL><DEDENT>elif scroll and scroll[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>body = events_range_body<EOL><DEDENT>elif scroll and scroll[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>body = events_empty_body<EOL><DEDENT>else:<EOL><INDENT>body = events_bodies.pop(<NUM_LIT:0>)<EOL>if events_bodies:<EOL><INDENT>headers['<STR_LIT>'] = '<STR_LIT:<>' + MEETUP_EVENTS_URL + '<STR_LIT>'<EOL><DEDENT>if rate_limit != -<NUM_LIT:1>:<EOL><INDENT>headers['<STR_LIT>'] = str(rate_limit)<EOL><DEDENT>if reset_rate_limit != -<NUM_LIT:1>:<EOL><INDENT>headers['<STR_LIT>'] = str(reset_rate_limit)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT>if rate_limit == -<NUM_LIT:1>:<EOL><INDENT>headers['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>if reset_rate_limit == -<NUM_LIT:1>:<EOL><INDENT>headers['<STR_LIT>'] = '<STR_LIT:0>'<EOL><DEDENT>http_requests.append(last_request)<EOL>return (<NUM_LIT:200>, headers, body)<EOL><DEDENT>httpretty.register_uri(httpretty.GET,<EOL>MEETUP_EVENTS_URL,<EOL>responses=[<EOL>httpretty.Response(body=request_callback)<EOL>for _ in range(<NUM_LIT:2>)<EOL>])<EOL>for url in MEETUP_COMMENTS_URL:<EOL><INDENT>httpretty.register_uri(httpretty.GET,<EOL>url,<EOL>responses=[<EOL>httpretty.Response(body=request_callback)<EOL>])<EOL><DEDENT>for url in MEETUP_RSVPS_URL:<EOL><INDENT>httpretty.register_uri(httpretty.GET,<EOL>url,<EOL>responses=[<EOL>httpretty.Response(body=request_callback)<EOL>])<EOL><DEDENT>return http_requests<EOL>
Setup a mock HTTP server