def test_reading_undocumented_feature_flags(self):
     """Reading undocumented feature flags records them as undocumented."""
     controller = NullFeatureController()
     # This test assumes there is no flag named "does-not-exist".
     assert 'does-not-exist' not in documented_flags
     controller.getFlag('does-not-exist')
     self.assertThat(undocumented_flags, Contains('does-not-exist'))
 def test_reading_undocumented_feature_flags(self):
     """Reading undocumented feature flags records them as undocumented."""
     controller = NullFeatureController()
     # This test assumes there is no flag named "does-not-exist".
     assert 'does-not-exist' not in documented_flags
     controller.getFlag('does-not-exist')
     self.assertThat(undocumented_flags, Contains('does-not-exist'))
 def test_reading_documented_feature_flags(self):
     """Reading documented flags does not record them as undocumented."""
     controller = NullFeatureController()
     # Make sure there is no flag named "documented-flag-name" before we
     # start testing.
     assert 'documented-flag-name' not in documented_flags
     documented_flags.update(['documented-flag-name'])
     controller.getFlag('documented-flag-name')
     self.assertThat(undocumented_flags,
                     Not(Contains('documented-flag-name')))
 def test_reading_documented_feature_flags(self):
     """Reading documented flags does not record them as undocumented."""
     controller = NullFeatureController()
     # Make sure there is no flag named "documented-flag-name" before we
     # start testing.
     assert 'documented-flag-name' not in documented_flags
     documented_flags.update(['documented-flag-name'])
     controller.getFlag('documented-flag-name')
     self.assertThat(
         undocumented_flags,
         Not(Contains('documented-flag-name')))
Ejemplo n.º 5
0
    def callObject(self, request, ob):
        """See `zope.publisher.interfaces.IPublication`.

        Our implementation make sure that no result is returned on
        redirect.

        It also sets the launchpad.userid and launchpad.pageid WSGI
        environment variables.
        """
        request._publicationticks_start = tickcount.tickcount()
        if request.response.getStatus() in [301, 302, 303, 307]:
            return ''

        request.setInWSGIEnvironment('launchpad.userid', request.principal.id)

        # The view may be security proxied
        view = removeSecurityProxy(ob)
        # It's possible that the view is a bound method.
        view = getattr(view, 'im_self', view)
        context = removeSecurityProxy(getattr(view, 'context', None))
        pageid = self.constructPageID(view, context)
        request.setInWSGIEnvironment('launchpad.pageid', pageid)
        # And spit the pageid out to our tracelog.
        tracelog(request, 'p', pageid)

        # For status URLs, where we really don't want to have any DB access
        # at all, ensure that all flag lookups will stop early.
        if pageid in ('RootObject:OpStats', 'RootObject:+opstats',
                      'RootObject:+haproxy'):
            request.features = NullFeatureController()
            features.install_feature_controller(request.features)

        # Calculate the hard timeout: needed because featureflags can be used
        # to control the hard timeout, and they trigger DB access, but our
        # DB tracers are not safe for reentrant use, so we must do this
        # outside of the SQL stack. We must also do it after traversal so that
        # the view is known and can be used in scope resolution. As we
        # actually stash the pageid after afterTraversal, we need to do this
        # even later.
        da.set_permit_timeout_from_features(True)
        da._get_request_timeout()

        if isinstance(removeSecurityProxy(ob), METHOD_WRAPPER_TYPE):
            # this is a direct call on a C-defined method such as __repr__ or
            # dict.__setitem__.  Apparently publishing this is possible and
            # acceptable, at least in the case of
            # lp.services.webapp.servers.PrivateXMLRPCPublication.
            # mapply cannot handle these methods because it cannot introspect
            # them.  We'll just call them directly.
            return ob(*request.getPositionalArguments())

        return mapply(ob, request.getPositionalArguments(), request)
Ejemplo n.º 6
0
    def __init__(self, context, request):
        super(SystemErrorView, self).__init__(context, request)
        self.request.response.removeAllNotifications()
        if self.response_code is not None:
            self.request.response.setStatus(self.response_code)
        if getattr(self.request, 'oopsid') is not None:
            self.request.response.addHeader('X-Lazr-OopsId',
                                            self.request.oopsid)

        # Need to neuter the feature flags on error output. The base template
        # checks for a feature flag, but they depend on db access which might
        # not have been setup yet.
        request.features = NullFeatureController()
        features.install_feature_controller(request.features)

        self.computeDebugOutput()
        if config.canonical.show_tracebacks:
            self.show_tracebacks = True
        if lp.layers.DebugLayer.providedBy(self.request):
            self.debugging = True
        self.specialuser = getUtility(ILaunchBag).developer
 def test_script_restores_feature_controller(self):
     previous_controller = NullFeatureController()
     install_feature_controller(previous_controller)
     FakeScript(name="mongo").run()
     self.assertEqual(
         previous_controller, get_relevant_feature_controller())