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 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))
예제 #3
0
 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'])
예제 #4
0
 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')
예제 #5
0
 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'])
예제 #6
0
 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')
예제 #7
0
 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')
예제 #8
0
 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')
예제 #9
0
 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'])
예제 #10
0
 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)
예제 #11
0
 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'])
예제 #12
0
 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 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 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'])
예제 #15
0
  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')
예제 #16
0
    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 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'])
예제 #18
0
 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)
예제 #19
0
 def testPadEmptyString(self):
   self.assertEquals(' ' * 512, util.pad_string(''))
예제 #20
0
 def testPadLongString(self):
   self.assertEquals('x' * 1000, util.pad_string('x' * 1000))
예제 #21
0
 def testPadString(self):
   self.assertEquals('hello' + (507 * ' '), util.pad_string('hello'))
예제 #22
0
 def testPadEmptyString(self):
   self.assertEquals(' ' * 512, util.pad_string(''))
예제 #23
0
 def testPadLongString(self):
   self.assertEquals('x' * 1000, util.pad_string('x' * 1000))
예제 #24
0
 def testPadString(self):
   self.assertEquals('hello' + (507 * ' '), util.pad_string('hello'))