예제 #1
0
    def Get(self):
        link_error_tests = ('broken_links', 'orphaned_pages', 'link_errors')

        if not self._request.path in link_error_tests:
            return Response.NotFound(
                'Test %s not found. Available tests are: %s' %
                (self._request.path, ','.join(link_error_tests)))

        constructor = InstanceServlet.GetConstructor(self._delegate)

        def renderer(path):
            return constructor(Request(path, '', self._request.headers)).Get()

        link_tester = BrokenLinkTester(
            InstanceServletRenderServletDelegate(
                self._delegate).CreateServerInstance(), renderer)
        if self._request.path == 'broken_links':
            errors, content = link_tester.TestBrokenLinks()
        elif self._request.path == 'orphaned_pages':
            errors, content = link_tester.TestOrphanedPages()
        else:
            link_errors, link_content = link_tester.TestBrokenLinks()
            orphaned_errors, orphaned_content = link_tester.TestOrphanedPages()
            errors = link_errors + orphaned_errors
            content = "%s\n%s" % (link_content, orphaned_content)

        if errors:
            return Response.InternalError(content=content)

        return Response.Ok(content="%s test passed." % self._request.path)
예제 #2
0
 def testHostFileSystemNotAccessed(self):
   delegate = _TestDelegate(FailOnAccessFileSystem)
   constructor = InstanceServlet.GetConstructor(delegate_for_test=delegate)
   def test_path(path, status=404):
     response = constructor(Request.ForTest(path)).Get()
     self.assertEqual(status, response.status)
   test_path('extensions/storage.html')
   test_path('apps/storage.html')
   test_path('extensions/examples/foo.zip')
   test_path('extensions/examples/foo.html')
   test_path('static/foo.css')
   test_path('beta/extensions/storage.html', status=301)
   test_path('beta/apps/storage.html', status=301)
   test_path('beta/extensions/examples/foo.zip', status=301)
   test_path('beta/extensions/examples/foo.html', status=301)
   test_path('beta/static/foo.css', status=301)
예제 #3
0
 def __init__(self, request, delegate=None):
     self._request = request
     self._delegate = delegate or InstanceServlet.Delegate()
예제 #4
0
 def __init__(self, request, delegate_for_test=None):
     Servlet.__init__(self, request)
     self._delegate = delegate_for_test or InstanceServlet.Delegate()
예제 #5
0
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from cron_servlet import CronServlet
from instance_servlet import InstanceServlet
from patch_servlet import PatchServlet
from servlet import Servlet, Request, Response
from test_servlet import TestServlet

_DEFAULT_SERVLET = InstanceServlet.GetConstructor()
_SERVLETS = {
    'cron': CronServlet,
    'patch': PatchServlet,
    'test': TestServlet,
}


class Handler(Servlet):
    def Get(self):
        path = self._request.path

        if path.startswith('_'):
            servlet_path = path[1:]
            if not '/' in servlet_path:
                servlet_path += '/'
            servlet_name, servlet_path = servlet_path.split('/', 1)
            servlet = _SERVLETS.get(servlet_name)
            if servlet is None:
                return Response.NotFound('"%s" servlet not found' %
                                         servlet_path)