def test_OperationSendsRequestData(self): self.force_http_status( 200, 'Success') test_data = 'abcdef' op = RESTOperation('GET', self.test_url, test_data) op.execute() self.mock_HTTPConnection().\ request.assert_called_with('GET', '/', test_data, {})
def test_OperationWillDoHTTPOperation(self): class TestHandler(SimpleGETHTTPRequestHandler): resp = 'HelloWorld!' self.fake_server.replace_request_handler_with(TestHandler) op = RESTOperation('GET', 'http://{0}:{1}/'.format( self.fake_server.hostname, self.fake_server.port)) op.execute() self.assertEqual(TestHandler.resp, op.response)
def test_OperationWillSendHeaders(self): expected_headers = {'x-test-1' : 'hi', 'x-test-2': 'bye'} class TestHandler(SimpleGETHTTPRequestHandler): def do_GET(self): self.send_response(200) self.end_headers() special_keys = [k for k in self.headers if k.startswith('x-')] resp = '/n'.join(['{0} {1}'.format( x, self.headers[x]) for x in special_keys]) self.wfile.write(resp) return self.fake_server.replace_request_handler_with(TestHandler) op = RESTOperation('GET', 'http://{0}:{1}/'.format( self.fake_server.hostname, self.fake_server.port), '', expected_headers) op.execute() expected_response = '/n'.join( ['{0} {1}'.format(x, expected_headers[x]) for x in expected_headers]) self.assertEqual(expected_response, op.response)
def test_OperationCallsPrepareForRequest(self): self.force_http_status( 200, 'Success') op = RESTOperation('GET', self.test_url) op.prepare_for_request = mocksignature(op.prepare_for_request) op.execute() self.assertTrue(op.prepare_for_request.mock.called)
def test_OperationReturnsResponseData(self): response = 'sample response data' self.force_http_status( 200, 'Success', response) op = RESTOperation('GET', self.test_url) op.execute() self.assertEqual( response, op.response)
def test_OperationUsesGet(self): self.force_http_status( 200, 'Success') op = RESTOperation('GET', self.test_url) op.execute() self.mock_HTTPConnection().\ request.assert_called_with('GET', '/', '', {})