← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~stub/launchpad/trivial into lp:launchpad

 

Stuart Bishop has proposed merging lp:~stub/launchpad/trivial into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #673252 server.* scope not robust on misspelt scopes
  https://bugs.launchpad.net/bugs/673252


A mistyped feature flag shouldn't trigger OOPSes. Make server.* flags robust, returning False for non-existent keys. Fixes Bug #673252.
-- 
https://code.launchpad.net/~stub/launchpad/trivial/+merge/43177
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stub/launchpad/trivial into lp:launchpad.
=== modified file 'lib/lp/services/features/tests/test_webapp.py'
--- lib/lp/services/features/tests/test_webapp.py	2010-12-01 11:26:57 +0000
+++ lib/lp/services/features/tests/test_webapp.py	2010-12-09 10:12:00 +0000
@@ -5,6 +5,9 @@
 
 __metaclass__ = type
 
+from textwrap import dedent
+
+from canonical.config import config
 from canonical.testing import layers
 from lp.services.features import webapp
 from lp.testing import (
@@ -17,6 +20,8 @@
 
 class TestScopesFromRequest(TestCase):
 
+    layer = layers.BaseLayer
+
     def test_pageid_scope_normal(self):
         request = LaunchpadTestRequest()
         request.setInWSGIEnvironment('launchpad.pageid', 'foo:bar')
@@ -44,6 +49,30 @@
         self.assertFalse(scopes.lookup('pageid:foo'))
         self.assertFalse(scopes.lookup('pageid:foo:bar'))
 
+    def test_default(self):
+        request = LaunchpadTestRequest()
+        scopes = webapp.ScopesFromRequest(request)
+        self.assertTrue(scopes.lookup('default'))
+
+    def test_server(self):
+        request = LaunchpadTestRequest()
+        scopes = webapp.ScopesFromRequest(request)
+        self.assertFalse(scopes.lookup('server.lpnet'))
+        config.push('ensure_lpnet', dedent("""\
+            [launchpad]
+            is_lpnet: True
+            """))
+        try:
+            self.assertTrue(scopes.lookup('server.lpnet'))
+        finally:
+            config.pop('ensure_lpnet')
+
+    def test_server_missing_key(self):
+        request = LaunchpadTestRequest()
+        scopes = webapp.ScopesFromRequest(request)
+        # There is no such key in the config, so this returns False.
+        self.assertFalse(scopes.lookup('server.pink'))
+
 
 class TestDBScopes(TestCaseWithFactory):
 

=== modified file 'lib/lp/services/features/webapp.py'
--- lib/lp/services/features/webapp.py	2010-11-04 07:23:20 +0000
+++ lib/lp/services/features/webapp.py	2010-12-09 10:12:00 +0000
@@ -50,7 +50,11 @@
         parts = scope_name.split('.')
         if len(parts) == 2:
             if parts[0] == 'server':
-                return canonical.config.config['launchpad']['is_' + parts[1]]
+                lp_config = canonical.config.config['launchpad']
+                try:
+                    return lp_config['is_' + parts[1]]
+                except KeyError:
+                    return False
 
     def _lookup_pageid(self, pageid_scope):
         """Lookup a pageid as a scope.


Follow ups