def write(content): if expected_content == '': test.assertEquals(util.pad_string(''), content) else: test.assertNotEquals(-1, content.find(expected_content), 'Expected to find:\n%s\n\nActual content: \n%s' % ( expected_content, content))
def testMissingContentType(self): code, content, headers = self.RawRequestError( 'optional_message', content='{"string_value": "blar"}', content_type='') self.assertEquals(400, code) self.assertEquals(util.pad_string('Bad Request'), content) self.assertEquals('text/plain; charset=utf-8', headers['content-type'])
def testUnsupportedContentType(self): code, content, headers = self.RawRequestError( 'optional_message', content='{"string_value": "blar"}', content_type='image/png') self.assertEquals(415, code) self.assertEquals(util.pad_string('Unsupported Media Type'), content) self.assertEquals(headers['content-type'], 'text/plain; charset=utf-8')
def testUnsupportedHttpMethod(self): code, content, headers = self.RawRequestError('optional_message') self.assertEquals(405, code) self.assertEquals( util.pad_string( '/my/service.optional_message is a ProtoRPC method.\n\n' 'Service protorpc.webapp_test_util.TestService\n\n' 'More about ProtoRPC: ' 'http://code.google.com/p/google-protorpc\n'), content) self.assertEquals(headers['content-type'], 'text/plain; charset=utf-8')
def testUnsupportedHttpMethod(self): code, content, headers = self.RawRequestError('optional_message') self.assertEquals(405, code) self.assertEquals( util.pad_string('/my/service.optional_message is a ProtoRPC method.\n\n' 'Service protorpc.webapp_test_util.TestService\n\n' 'More about ProtoRPC: ' 'http://code.google.com/p/google-protorpc\n'), content) self.assertEquals(headers['content-type'], 'text/plain; charset=utf-8')
def testGetNoMethod(self): self.handler.get('/my_service', '') self.assertEquals(405, self.handler.response.status) self.assertEquals( util.pad_string('/my_service is a ProtoRPC service.\n\n' 'Service %s.Service\n\n' 'More about ProtoRPC: ' 'http://code.google.com/p/google-protorpc\n' % __name__), self.handler.response.out.getvalue()) self.assertEquals( 'nosniff', self.handler.response.headers['x-content-type-options'])
def testEmptyConfiguration(self): self.ResetServer(wsgi_util.first_found([])) status, status_text, content, headers = self.DoHttpRequest('/') self.assertEquals(six.moves.http_client.NOT_FOUND, status) self.assertEquals(six.moves.http_client.responses[six.moves.http_client.NOT_FOUND], status_text) self.assertEquals(util.pad_string(six.moves.http_client.responses[six.moves.http_client.NOT_FOUND]), content) self.assertEquals({'content-length': '512', 'content-type': 'text/plain; charset=utf-8', }, headers)
def testGetUnknownContentType(self): self.handler.request.headers['content-type'] = 'image/png' self.handler.get('/my_service', 'method1') self.assertEquals(415, self.handler.response.status) self.assertEquals( util.pad_string('/my_service.method1 is a ProtoRPC method.\n\n' 'Service %s.Service\n\n' 'More about ProtoRPC: ' 'http://code.google.com/p/google-protorpc\n' % __name__), self.handler.response.out.getvalue()) self.assertEquals( 'nosniff', self.handler.response.headers['x-content-type-options'])
def testGetNotSupported(self): self.handler.get('/my_service', 'method1') self.assertEquals(405, self.handler.response.status) expected_message = ('/my_service.method1 is a ProtoRPC method.\n\n' 'Service %s.Service\n\n' 'More about ProtoRPC: ' 'http://code.google.com/p/google-protorpc\n' % __name__) self.assertEquals(util.pad_string(expected_message), self.handler.response.out.getvalue()) self.assertEquals( 'nosniff', self.handler.response.headers['x-content-type-options'])
def testBadMessageError(self): code, content, headers = self.RawRequestError('nested_message', content='{}') self.assertEquals(400, code) expected_content = protojson.encode_message(remote.RpcStatus( state=remote.RpcState.REQUEST_ERROR, error_message=('Error parsing ProtoRPC request ' '(Unable to parse request content: ' 'Message NestedMessage is missing ' 'required field a_value)'))) self.assertEquals(util.pad_string(expected_content), content) self.assertEquals(headers['content-type'], 'application/json')
def testBadMessageError(self): code, content, headers = self.RawRequestError('nested_message', content='{}') self.assertEquals(400, code) expected_content = protojson.encode_message( remote.RpcStatus( state=remote.RpcState.REQUEST_ERROR, error_message=('Error parsing ProtoRPC request ' '(Unable to parse request content: ' 'Message NestedMessage is missing ' 'required field a_value)'))) self.assertEquals(util.pad_string(expected_content), content) self.assertEquals(headers['content-type'], 'application/json')
def testEmptyConfiguration(self): self.ResetServer(wsgi_util.first_found([])) status, status_text, content, headers = self.DoHttpRequest('/') self.assertEqual(six.moves.http_client.NOT_FOUND, status) self.assertEqual( six.moves.http_client.responses[six.moves.http_client.NOT_FOUND], status_text) self.assertEqual( util.pad_string(six.moves.http_client.responses[ six.moves.http_client.NOT_FOUND]), content) self.assertEqual( { 'content-length': '512', 'content-type': 'text/plain; charset=utf-8', }, headers)
def testPadEmptyString(self): self.assertEquals(' ' * 512, util.pad_string(''))
def testPadLongString(self): self.assertEquals('x' * 1000, util.pad_string('x' * 1000))
def testPadString(self): self.assertEquals('hello' + (507 * ' '), util.pad_string('hello'))