1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Tests for FeatureFlagApplication."""
10
from canonical.testing.layers import DatabaseFunctionalLayer
11
from canonical.config import config
12
from lp.services import features
13
from lp.services.features.flags import FeatureController
14
from lp.services.features.rulesource import StormFeatureRuleSource
15
from lp.services.features.scopes import (
20
from lp.services.features.xmlrpc import FeatureFlagApplication
21
from lp.testing import (
26
from lp.testing.xmlrpc import XMLRPCTestTransport
29
class TestGetFeatureFlag(TestCaseWithFactory):
31
layer = DatabaseFunctionalLayer
34
TestCaseWithFactory.setUp(self)
35
self.endpoint = FeatureFlagApplication()
37
def installFeatureController(self, feature_controller):
38
old_features = features.get_relevant_feature_controller()
39
features.install_feature_controller(feature_controller)
41
features.install_feature_controller, old_features)
43
def test_getFeatureFlag_returns_None_by_default(self):
44
self.assertIs(None, self.endpoint.getFeatureFlag(u'unknown'))
46
def test_getFeatureFlag_returns_true_for_set_flag(self):
49
set_feature_flag(flag_name, u'1')
50
self.assertEqual(u'1', self.endpoint.getFeatureFlag(flag_name))
52
def test_getFeatureFlag_ignores_relevant_feature_controller(self):
53
# getFeatureFlag should only consider the scopes it is asked to
54
# consider, not any that happen to be active due to the XML-RPC
58
self.installFeatureController(
61
[DefaultScope(), FixedScope(scope_name)]).lookup,
62
StormFeatureRuleSource()))
63
set_feature_flag(flag_name, u'1', scope_name)
64
self.assertEqual(None, self.endpoint.getFeatureFlag(flag_name))
66
def test_getFeatureFlag_considers_supplied_scope(self):
70
set_feature_flag(flag_name, u'value', scope_name)
73
self.endpoint.getFeatureFlag(flag_name, [scope_name]))
75
def test_getFeatureFlag_turns_user_into_team_scope(self):
77
person = self.factory.makePerson()
78
team = self.factory.makeTeam(members=[person])
80
set_feature_flag(flag_name, u'value', u'team:' + team.name)
83
self.endpoint.getFeatureFlag(
84
flag_name, ['user:' + person.name]))
86
def test_xmlrpc_interface_unset(self):
87
sp = xmlrpclib.ServerProxy(
88
config.launchpad.feature_flags_endpoint,
89
transport=XMLRPCTestTransport(), allow_none=True)
90
self.assertEqual(None, sp.getFeatureFlag(u'flag'))
92
def test_xmlrpc_interface_set(self):
93
sp = xmlrpclib.ServerProxy(
94
config.launchpad.feature_flags_endpoint,
95
transport=XMLRPCTestTransport(), allow_none=True)
98
set_feature_flag(flag_name, u'1')
99
self.assertEqual(u'1', sp.getFeatureFlag(flag_name))