Example #1
0
    def test_chat(self):
        self.mox.StubOutWithMock(xmpp_request_handler.XmppRequestHandler,
                                 '_send')

        request = webapp2.Request.blank('/xmpp',
                                        POST={
                                            'message_type': 'chat',
                                            'to': '*****@*****.**',
                                            'from': '*****@*****.**',
                                            'chat': 'Chat content'
                                        })
        response = webapp2.Response()
        handler = xmpp_request_handler.XmppRequestHandler(request, response)
        admin_request_handler.AdminRequestHandler(handler).post()
        data = xmpp_request_handler._FormData()
        data.add_text('from', '*****@*****.**', 'plain')
        data.add_text('to', '*****@*****.**', 'plain')
        data.add_text('body', 'Chat content', 'plain')
        data.add_text(
            'stanza',
            CompareXml(
                '<ns0:message from="*****@*****.**" to="*****@*****.**" '
                'type="chat" xmlns:ns0="jabber:client">'
                '<ns0:body>Chat content</ns0:body>'
                '</ns0:message>'), 'xml')

        handler._send('/_ah/xmpp/message/chat/', data).AndReturn(
            dispatcher.ResponseTuple('404 Not Found', [], 'Response'))
        self.mox.ReplayAll()
        handler.post()
        self.mox.VerifyAll()
        self.assertEqual('404 Not Found', response.status)
Example #2
0
    def test_post_entity_key_string(self):
        request = webapp2.Request.blank(
            '/datastore/edit/%s' % self.entity4.key(),
            POST={
                'overflowdatetime|dateprop': str(2**60),
                'int|intprop': '123',
                'string|stringprop': '',
                'next': 'http://redirect/'
            })
        response = webapp2.Response()
        handler = datastore_viewer.DatastoreEditRequestHandler(
            request, response)
        admin_request_handler.AdminRequestHandler(handler).post(
            str(self.entity4.key()))

        self.mox.ReplayAll()
        handler.post(str(self.entity4.key()))
        self.mox.VerifyAll()

        self.assertEqual(302, response.status_int)
        self.assertEqual('http://redirect/', response.location)

        # Check that the entity was updated.
        entity = datastore.Get(self.entity4.key())
        self.assertEqual(2**60, entity['dateprop'])
        self.assertEqual(123, entity['intprop'])
        self.assertEqual([10, 11], entity['listprop'])
        self.assertNotIn('stringprop', entity)
Example #3
0
  def test_get_entity_zero_props(self):
    request = webapp2.Request.blank(
        '/datastore/edit/%s?next=http://next/' % self.entity5.key())
    response = webapp2.Response()
    handler = datastore_viewer.DatastoreEditRequestHandler(request, response)

    admin_request_handler.AdminRequestHandler(handler).get(
        str(self.entity5.key()))
    handler.render(
        'datastore_edit.html',
        {'fields': [('boolprop',
                     'bool',
                     mox.Regex('^<select class="bool"(.|\n)*$')),
                    ('floatprop',
                     'float',
                     mox.Regex('^<input class="float".*value="0\.0".*$')),
                    ('intprop',
                     'int',
                     mox.Regex('^<input class="int".*value="0".*$')),
                    ('stringprop',
                     'string',
                     mox.Regex('^<input class="string".*value="".*$'))],
         'key': str(self.entity5.key()),
         'key_id': 127,
         'key_name': None,
         'kind': 'Kind1',
         'namespace': '',
         'next': 'http://next/',
         'parent_key': None,
         'parent_key_string': None})

    self.mox.ReplayAll()
    handler.get(str(self.entity5.key()))
    self.mox.VerifyAll()
Example #4
0
 def test_post(self):
   handler = admin_request_handler.AdminRequestHandler(None, None)
   metrics._MetricsLogger().LogOnceOnStop(
       'admin-console', 'AdminRequestHandler.post')
   self.mox.ReplayAll()
   handler.post()
   self.mox.VerifyAll()
Example #5
0
  def test_page_request(self):
    for i in range(1000):
      entity = datastore.Entity('Kind1', id=i+1, _app=self.app_id)
      entity['intprop'] = i
      datastore.Put(entity)

    request = webapp2.Request.blank(
        '/datastore?kind=Kind1&page=3')
    response = webapp2.Response()
    handler = datastore_viewer.DatastoreRequestHandler(request, response)

    admin_request_handler.AdminRequestHandler(handler).get()
    handler.render(
        'datastore_viewer.html',
        {'entities': mox.IgnoreArg(),  # Tested with _get_entity_template_data.
         'headers': mox.IgnoreArg(),  # Tested with _get_entity_template_data.
         'kind': 'Kind1',
         'kinds': ['Kind1'],
         'message': None,
         'namespace': '',
         'num_pages': 50,
         'order': None,
         'order_base_url': '/datastore?kind=Kind1&page=3',
         'page': 3,
         'paging_base_url': '/datastore?kind=Kind1',
         'select_namespace_url':
         '/datastore?kind=Kind1&namespace=&page=3',
         'show_namespace': False,
         'start': 40,
         'total_entities': 1000})

    self.mox.ReplayAll()
    handler.get()
    self.mox.VerifyAll()
Example #6
0
  def test_get_entity_string(self):
    request = webapp2.Request.blank(
        '/datastore/edit/%s?next=http://next/' % self.entity1.key())
    response = webapp2.Response()
    handler = datastore_viewer.DatastoreEditRequestHandler(request, response)
    admin_request_handler.AdminRequestHandler(handler).get(
        str(self.entity1.key()))
    handler.render(
        'datastore_edit.html',
        {'fields': [('dateprop',
                     'overflowdatetime',
                     mox.Regex('^<input class="overflowdatetime".*'
                               'value="1152921504606846976".*$')),
                    ('intprop',
                     'int',
                     mox.Regex('^<input class="int".*value="1".*$')),
                    ('listprop', 'list', mox.Regex(r'\[7L?, 8L?, 9L?\]'))],
         'key': str(self.entity1.key()),
         'key_id': 123,
         'key_name': None,
         'kind': 'Kind1',
         'namespace': '',
         'next': 'http://next/',
         'parent_key': None,
         'parent_key_string': None})

    self.mox.ReplayAll()
    handler.get(str(self.entity1.key()))
    self.mox.VerifyAll()
Example #7
0
  def test_kind_request_and_populated_datastore(self):
    entity = datastore.Entity('Kind1', id=123, _app=self.app_id)
    entity['intprop'] = 1
    entity['listprop'] = [7, 8, 9]
    datastore.Put(entity)

    request = webapp2.Request.blank('/datastore?kind=Kind1')
    response = webapp2.Response()
    handler = datastore_viewer.DatastoreRequestHandler(request, response)

    admin_request_handler.AdminRequestHandler(handler).get()
    handler.render(
        'datastore_viewer.html',
        {'entities': mox.IgnoreArg(),  # Tested with _get_entity_template_data.
         'headers': mox.IgnoreArg(),  # Tested with _get_entity_template_data.
         'kind': 'Kind1',
         'kinds': ['Kind1'],
         'message': None,
         'namespace': '',
         'num_pages': 1,
         'order': None,
         'order_base_url': '/datastore?kind=Kind1',
         'page': 1,
         'paging_base_url': '/datastore?kind=Kind1',
         'select_namespace_url': '/datastore?kind=Kind1&namespace=',
         'show_namespace': False,
         'start': 0,
         'total_entities': 1})

    self.mox.ReplayAll()
    handler.get()
    self.mox.VerifyAll()
Example #8
0
    def test_empty_request_and_empty_datastore(self):
        request = webapp2.Request.blank('/datastore')
        response = webapp2.Response()
        handler = datastore_viewer.DatastoreRequestHandler(request, response)

        admin_request_handler.AdminRequestHandler(handler).get()
        handler.render(
            'datastore_viewer.html', {
                'entities': [],
                'headers': [],
                'kind': None,
                'kinds': [],
                'message': None,
                'namespace': '',
                'num_pages': 0,
                'order': None,
                'paging_base_url': '/datastore?',
                'order_base_url': '/datastore?',
                'page': 1,
                'select_namespace_url': '/datastore?namespace=',
                'show_namespace': False,
                'start': 0,
                'total_entities': 0
            })
        self.mox.ReplayAll()
        handler.get()
        self.mox.VerifyAll()
Example #9
0
    def test_post_no_entity_key_string(self):
        request = webapp2.Request.blank('/datastore/edit',
                                        POST={
                                            'kind': 'Kind1',
                                            'overflowdatetime|dateprop':
                                            '2009-12-24 23:59:59',
                                            'int|intprop': '123',
                                            'string|stringprop': 'Hello',
                                            'next': 'http://redirect/'
                                        })
        response = webapp2.Response()
        handler = datastore_viewer.DatastoreEditRequestHandler(
            request, response)
        admin_request_handler.AdminRequestHandler(handler).post(None)

        self.mox.ReplayAll()
        handler.post()
        self.mox.VerifyAll()

        self.assertEqual(302, response.status_int)
        self.assertEqual('http://redirect/', response.location)

        # Check that the entity was added.
        query = datastore.Query('Kind1')
        query.update({
            'dateprop': datetime.datetime(2009, 12, 24, 23, 59, 59),
            'intprop': 123,
            'stringprop': 'Hello'
        })
        self.assertEquals(1, query.Count())
Example #10
0
    def test_subscribe(self):
        self.mox.StubOutWithMock(xmpp_request_handler.XmppRequestHandler,
                                 '_send')

        request = webapp2.Request.blank('/xmpp',
                                        POST={
                                            'message_type': 'subscribe',
                                            'to': '*****@*****.**',
                                            'from': '*****@*****.**',
                                            'subscription_type': 'subscribe'
                                        })
        response = webapp2.Response()
        handler = xmpp_request_handler.XmppRequestHandler(request, response)
        admin_request_handler.AdminRequestHandler(handler).post()
        data = xmpp_request_handler._FormData()
        data.add_text('from', '*****@*****.**', 'plain')
        data.add_text('to', '*****@*****.**', 'plain')
        data.add_text(
            'stanza',
            CompareXml(
                '<ns0:presence from="*****@*****.**" to="*****@*****.**" '
                'type="subscribe" xmlns:ns0="jabber:client" />'), 'xml')

        handler._send('/_ah/xmpp/subscription/subscribe/', data).AndReturn(
            dispatcher.ResponseTuple('404 Not Found', [], 'Response'))
        self.mox.ReplayAll()
        handler.post()
        self.mox.VerifyAll()
        self.assertEqual('404 Not Found', response.status)
Example #11
0
 def test_get(self):
     handler = admin_request_handler.AdminRequestHandler(
         None, webapp2.Response())
     metrics._MetricsLogger().LogOnceOnStop('admin-console',
                                            'AdminRequestHandler.get')
     self.mox.ReplayAll()
     handler.get()
     self.mox.VerifyAll()
Example #12
0
 def test_construct_url_remove(self):
   request = webapp2.Request.blank('/foo', POST={'arg1': 'value1',
                                                 'arg2': 'value2'})
   response = webapp2.Response()
   handler = admin_request_handler.AdminRequestHandler(request, response)
   url = handler._construct_url(remove=['arg1'])
   parsed_url = urlparse.urlparse(url)
   self.assertEqual('/foo', parsed_url.path)
   self.assertEqual({'arg2': ['value2']},
                    urlparse.parse_qs(parsed_url.query))
Example #13
0
  def test_get_no_entity_key_string_and_no_entities_in_namespace(self):
    request = webapp2.Request.blank(
        '/datastore/edit?kind=Kind1&namespace=cat&next=http://next/')
    response = webapp2.Response()
    handler = datastore_viewer.DatastoreEditRequestHandler(request, response)
    admin_request_handler.AdminRequestHandler(handler).get(None)

    self.mox.ReplayAll()
    handler.get()
    self.mox.VerifyAll()

    self.assertEqual(302, response.status_int)
    self.assertRegexpMatches(
        response.location,
        r'/datastore\?kind=Kind1&message=Cannot+.*&namespace=cat')
Example #14
0
  def test_post_when_console_disabled_fails(self):
    self.mox.StubOutWithMock(console.ConsoleRequestHandler, 'enable_console')
    request = webapp2.Request.blank('', POST={'code': 'print 5+5',
                                              'module_name': 'default'})
    response = webapp2.Response()

    handler = console.ConsoleRequestHandler(request, response)
    handler.enable_console = False
    admin_request_handler.AdminRequestHandler(handler).post()

    self.mox.ReplayAll()
    handler.post()
    self.mox.VerifyAll()
    self.assertEqual(404, response.status_int)
    self.assertIn('The interactive console is currently disabled.',
                  response.body)
Example #15
0
 def test_construct_url_add(self):
     request = webapp2.Request.blank('/foo',
                                     POST={
                                         'arg1': 'value1',
                                         'arg2': 'value2'
                                     })
     response = webapp2.Response()
     handler = admin_request_handler.AdminRequestHandler(request, response)
     url = handler._construct_url(add={'arg2': 'new2', 'arg3': 'new3'})
     parsed_url = six.moves.urllib.parse.urllib.parse(url)
     self.assertEqual('/foo', parsed_url.path)
     self.assertEqual(
         {
             'arg1': ['value1'],
             'arg2': ['new2'],
             'arg3': ['new3']
         }, six.moves.urllib.parse.parse_qs(parsed_url.query))
 def test_get_with_pytz(self, pytz=object()):
     cron_handler.pytz = pytz
     jobs = object()
     request = webapp2.Request.blank('/cron')
     response = webapp2.Response()
     handler = cron_handler.CronHandler(request, response)
     admin_request_handler.AdminRequestHandler(handler).get()
     self.mox.StubOutWithMock(handler, '_get_cron_jobs')
     self.mox.StubOutWithMock(handler, 'render')
     handler._get_cron_jobs().AndReturn(jobs)
     handler.render('cron.html', {
         'has_pytz': bool(pytz),
         'cronjobs': jobs
     }).AndReturn('template')
     self.mox.ReplayAll()
     handler.get()
     self.mox.VerifyAll()
     self.assertEqual('template', response.body)
Example #17
0
    def test_empty_request_and_populated_datastore(self):
        entity = datastore.Entity('Kind1', id=123, _app=self.app_id)
        entity['intprop'] = 1
        entity['listprop'] = [7, 8, 9]
        datastore.Put(entity)

        request = webapp2.Request.blank('/datastore')
        response = webapp2.Response()
        handler = datastore_viewer.DatastoreRequestHandler(request, response)

        admin_request_handler.AdminRequestHandler(handler).get()

        self.mox.ReplayAll()
        handler.get()
        self.mox.VerifyAll()

        self.assertEqual(302, response.status_int)
        self.assertEqual('http://localhost/datastore?kind=Kind1',
                         response.location)
Example #18
0
    def test_get_no_entity_key_string(self):
        request = webapp2.Request.blank(
            '/datastore/edit?kind=Kind1&next=http://next/')
        response = webapp2.Response()
        handler = datastore_viewer.DatastoreEditRequestHandler(
            request, response)

        admin_request_handler.AdminRequestHandler(handler).get(None)
        handler.render(
            'datastore_edit.html', {
                'fields': [('boolprop', 'bool',
                            mox.Regex('^<select class="bool"(.|\n)*$')),
                           ('dateprop', 'overflowdatetime',
                            mox.Regex('^<input class="overflowdatetime".*'
                                      'value="".*$')),
                           ('floatprop', 'float',
                            mox.Regex('^<input class="float".*value="".*$')),
                           ('intprop', 'int',
                            mox.Regex('^<input class="int".*value="".*$')),
                           ('listprop', 'list', ''),
                           ('stringprop', 'string',
                            mox.Regex('^<input class="string".*$'))],
                'key':
                None,
                'key_id':
                None,
                'key_name':
                None,
                'kind':
                'Kind1',
                'namespace':
                '',
                'next':
                'http://next/',
                'parent_key':
                None,
                'parent_key_string':
                None
            })

        self.mox.ReplayAll()
        handler.get()
        self.mox.VerifyAll()
 def test_get_with_invalid_cron_yaml(self):
     cron_handler.pytz = None
     request = webapp2.Request.blank('/cron')
     response = webapp2.Response()
     handler = cron_handler.CronHandler(request, response)
     admin_request_handler.AdminRequestHandler(handler).get()
     self.mox.StubOutWithMock(handler, '_get_cron_jobs')
     self.mox.StubOutWithMock(handler, 'render')
     self.mox.StubOutWithMock(traceback, 'format_exc')
     handler._get_cron_jobs().AndRaise(yaml_errors.Error)
     traceback.format_exc().AndReturn('traceback')
     handler.render('cron.html', {
         'has_pytz': False,
         'cron_error': 'traceback'
     }).AndReturn('template')
     self.mox.ReplayAll()
     handler.get()
     self.mox.VerifyAll()
     self.assertEqual('template', response.body)
 def test_post(self):
     self.mox.StubOutWithMock(cron_handler.CronHandler, 'dispatcher')
     request = webapp2.Request.blank('/cron', POST={'url': '/url'})
     response = webapp2.Response()
     handler = cron_handler.CronHandler(request, response)
     admin_request_handler.AdminRequestHandler(handler).post()
     handler.dispatcher = self.mox.CreateMock(dispatcher.Dispatcher)
     handler.dispatcher.add_request(method='GET',
                                    relative_url='/url',
                                    headers=[('X-AppEngine-Cron', 'true')],
                                    body='',
                                    source_ip='0.1.0.1').AndReturn(
                                        dispatcher.ResponseTuple(
                                            '500 Internal Server Error', [],
                                            ''))
     self.mox.ReplayAll()
     handler.post()
     self.mox.VerifyAll()
     self.assertEqual(500, response.status_int)
    def test_post(self):
        request = webapp2.Request.blank('/blobstore',
                                        method='POST',
                                        POST=multidict.MultiDict([
                                            ('blob_key', 'a'),
                                            ('blob_key', 'b')
                                        ]))
        response = webapp2.Response()
        handler = blobstore_viewer.BlobstoreRequestHandler(request, response)
        admin_request_handler.AdminRequestHandler(handler).post()
        self.mox.StubOutWithMock(blobstore, 'delete')
        blobstore.delete(['a', 'b'])

        self.mox.ReplayAll()
        handler.post()
        self.mox.VerifyAll()
        self.assertEqual(302, response.status_int)
        self.assertEqual('http://localhost/blobstore',
                         response.headers.get('Location'))
    def test_get_with_offset(self):
        request = webapp2.Request.blank('/blobstore?offset=40')
        response = webapp2.Response()
        handler = blobstore_viewer.BlobstoreRequestHandler(request, response)

        blob_infos = [object() for _ in range(10)]
        blobstore_viewer._get_blobs(40,
                                    BLOBS_PER_PAGE + 1).AndReturn(blob_infos)
        admin_request_handler.AdminRequestHandler(handler).get()
        handler.render(
            'blobstore_viewer.html', {
                'previous': 20,
                'next': None,
                'blob_infos': blob_infos,
                'offset': 40,
                'return_to': 'http://localhost/blobstore?offset=40',
            })

        self.mox.ReplayAll()
        handler.get()
        self.mox.VerifyAll()
Example #23
0
  def test_post_new_module(self):
    self.mox.StubOutWithMock(console.ConsoleRequestHandler, 'enable_console')
    request = webapp2.Request.blank('', POST={'code': 'print 5+5',
                                              'module_name': 'default'})
    response = webapp2.Response()

    handler = console.ConsoleRequestHandler(request, response)
    handler.enable_console = True
    admin_request_handler.AdminRequestHandler(handler).post()
    handler.dispatcher = self.dispatcher
    handler.dispatcher.get_module_by_name('default').AndReturn(self.module)
    self.module.create_interactive_command_module().AndReturn(
        self.interactive_command_module)
    self.interactive_command_module.send_interactive_command(
        'print 5+5').AndReturn('10\n')

    self.mox.ReplayAll()
    handler.post()
    self.mox.VerifyAll()
    self.assertEqual(200, response.status_int)
    self.assertEqual('10\n', response.body)
Example #24
0
  def test_post_exception(self):
    self.mox.StubOutWithMock(console.ConsoleRequestHandler, 'enable_console')
    console.ConsoleRequestHandler._modulename_to_shell_module = {
        'default': self.interactive_command_module}

    request = webapp2.Request.blank('', POST={'code': 'print 5+5',
                                              'module_name': 'default'})
    response = webapp2.Response()

    handler = console.ConsoleRequestHandler(request, response)
    handler.enable_console = True
    admin_request_handler.AdminRequestHandler(handler).post()
    handler.dispatcher = self.dispatcher
    self.interactive_command_module.send_interactive_command(
        'print 5+5').AndRaise(module.InteractiveCommandError('restart'))

    self.mox.ReplayAll()
    handler.post()
    self.mox.VerifyAll()
    self.assertEqual(200, response.status_int)
    self.assertEqual('restart', response.body)
Example #25
0
    def test_get(self):
        queue1 = taskqueue_utils.QueueInfo(
            name='queue1',
            mode=taskqueue_service_pb.TaskQueueMode.PUSH,
            rate='10/s',
            bucket_size=20,
            tasks_in_queue=10,
            oldest_eta_usec=-1)
        queue2 = taskqueue_utils.QueueInfo(
            name='queue1',
            mode=taskqueue_service_pb.TaskQueueMode.PUSH,
            rate='20/s',
            bucket_size=20,
            tasks_in_queue=10,
            oldest_eta_usec=-1)
        queue3 = taskqueue_utils.QueueInfo(
            name='queue1',
            mode=taskqueue_service_pb.TaskQueueMode.PULL,
            rate='20/s',
            bucket_size=20,
            tasks_in_queue=10,
            oldest_eta_usec=-1)

        taskqueue_utils.QueueInfo.get().AndReturn([queue1, queue2, queue3])
        request = webapp2.Request.blank('/taskqueue')
        response = webapp2.Response()

        handler = taskqueue_queues_handler.TaskQueueQueuesHandler(
            request, response)
        admin_request_handler.AdminRequestHandler(handler).get()
        handler.render('taskqueue_queues.html', {
            'push_queues': [queue1, queue2],
            'pull_queues': [queue3]
        })

        self.mox.ReplayAll()
        handler.get()
        self.mox.VerifyAll()
Example #26
0
    def test_post_cached_module(self):
        console.ConsoleRequestHandler._modulename_to_shell_module = {
            'default': self.interactive_command_module
        }

        request = webapp2.Request.blank('',
                                        POST={
                                            'code': 'print 5+5',
                                            'module_name': 'default'
                                        })
        response = webapp2.Response()

        handler = console.ConsoleRequestHandler(request, response)
        admin_request_handler.AdminRequestHandler(handler).post()
        handler.dispatcher = self.dispatcher
        self.interactive_command_module.send_interactive_command(
            'print 5+5').AndReturn('10\n')

        self.mox.ReplayAll()
        handler.post()
        self.mox.VerifyAll()
        self.assertEqual(200, response.status_int)
        self.assertEqual('10\n', response.body)