def setUp(self): XpresserUnittest.setUp(self) self.click('proxy-menu-icon') self.find('proxy-tabs') self.http_daemon = HTTPDaemon() self.http_daemon.start() self.http_daemon.wait_for_start() proxy_support = urllib2.ProxyHandler({'http': '127.0.0.1:8080'}) self.opener = urllib2.build_opener(proxy_support)
def test_POST_request(self): self.http_daemon = HTTPDaemon() self.http_daemon.start() self.http_daemon.wait_for_start() # # Send the request to our server using the GUI # self.double_click('localhost') self.type('127.0.0.1:%s' % self.http_daemon.get_port(), False) # Move to the beginning self.type(['<PgUp>',], False) # Replace GET with POST self.type(['<Delete>',], False) self.type(['<Delete>',], False) self.type(['<Delete>',], False) self.type('POST', False) # Move to the end (postdata) self.type(['<PgDn>',], False) post_data = 'foo=bar&spam=eggs' self.type(post_data, False) self.click('send') # Wait until we actually get the response, and verify we got the # response body we expected: self.find('abcdef') self.find('200_OK') # # Assert that it's what we really expected # requests = self.http_daemon.requests self.assertEqual(len(requests), 1) request = requests[0] head, postdata = MANUAL_REQUEST_EXAMPLE, '' http_request = http_request_parser(head, postdata) self.assertEqual(http_request.get_url().get_path(), request.path) self.assertEqual('POST', request.command) for header_name, header_value in http_request.get_headers().iteritems(): self.assertIn(header_name.lower(), request.headers) self.assertEqual(header_value, request.headers[header_name.lower()]) self.assertEqual(str(len(post_data)), request.headers['content-length']) self.http_daemon.shutdown()
def test_GET_request(self): self.http_daemon = HTTPDaemon() self.http_daemon.start() self.http_daemon.wait_for_start() # # Send the request to our server using the GUI # self.double_click('localhost') self.type('127.0.0.1:%s' % self.http_daemon.get_port(), False) self.click('play') # Wait until we actually get the response, and verify we got the # response body we expected: self.click('response_tab') self.find('abcdef') self.find('200_OK') # # Assert that it's what we really expected # requests = self.http_daemon.requests self.assertEqual(len(requests), 10) head, postdata = FUZZY_REQUEST_EXAMPLE, '' parsed_request = http_request_parser(head, postdata) for i, daemon_request in enumerate(self.http_daemon.requests): self.assertEqual('/%s' % i, daemon_request.path) self.assertEqual(parsed_request.get_method(), daemon_request.command) for header_name, header_value in parsed_request.get_headers( ).iteritems(): self.assertIn(header_name.lower(), daemon_request.headers) self.assertEqual(header_value, daemon_request.headers[header_name.lower()]) self.http_daemon.shutdown()
def test_GET_request(self): self.http_daemon = HTTPDaemon() self.http_daemon.start() self.http_daemon.wait_for_start() # # Send the request to our server using the GUI # self.double_click('localhost') self.type('127.0.0.1:%s' % self.http_daemon.get_port(), False) self.click('send') # Wait until we actually get the response, and verify we got the # response body we expected: self.find('abcdef') self.find('200_OK') # # Assert that it's what we really expected # requests = self.http_daemon.requests self.assertEqual(len(requests), 1) request = requests[0] head, postdata = MANUAL_REQUEST_EXAMPLE, '' http_request = HTTPRequestParser(head, postdata) self.assertEqual(http_request.get_url().get_path(), request.path) self.assertEqual(http_request.get_method(), request.command) for header_name, header_value in http_request.get_headers().iteritems( ): self.assertIn(header_name.lower(), request.headers) self.assertEqual(header_value, request.headers[header_name.lower()]) self.http_daemon.shutdown()
def setUp(self): self.http_daemon = HTTPDaemon() self.http_daemon.start() self.http_daemon.wait_for_start() self.requests = self.http_daemon.requests
def test_POST_request(self): self.http_daemon = HTTPDaemon() self.http_daemon.start() self.http_daemon.wait_for_start() # # Send the request to our server using the GUI # self.double_click('localhost') self.type('127.0.0.1:%s' % self.http_daemon.get_port(), False) # Move to the beginning self.type([ '<PgUp>', ], False) # Replace GET with POST self.type([ '<Delete>', ], False) self.type([ '<Delete>', ], False) self.type([ '<Delete>', ], False) self.type('POST', False) # Move to the end (postdata) self.type([ '<PgDn>', ], False) post_data = 'foo=bar&spam=eggs' self.type(post_data, False) self.click('play') # Wait until we actually get the response, and verify we got the # response body we expected: self.click('response_tab') self.find('abcdef') self.find('200_OK') # # Assert that it's what we really expected # requests = self.http_daemon.requests self.assertEqual(len(requests), 10) head, postdata = FUZZY_REQUEST_EXAMPLE, '' parsed_request = HTTPRequestParser(head, postdata) for i, daemon_request in enumerate(self.http_daemon.requests): self.assertEqual('/%s' % i, daemon_request.path) self.assertEqual('POST', daemon_request.command) for header_name, header_value in parsed_request.get_headers( ).iteritems(): self.assertIn(header_name.lower(), daemon_request.headers) self.assertEqual(header_value, daemon_request.headers[header_name.lower()]) self.http_daemon.shutdown()