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'))