~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/features/tests/test_xmlrpc.py

  • Committer: Curtis Hovey
  • Date: 2011-09-21 14:38:47 UTC
  • mto: This revision was merged to the branch mainline in revision 14011.
  • Revision ID: curtis.hovey@canonical.com-20110921143847-zxits7qrww028c6f
Rollback r13986 because team scopes are broken.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2011 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Tests for FeatureFlagApplication."""
5
 
 
6
 
__metaclass__ = type
7
 
 
8
 
import xmlrpclib
9
 
 
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 (
16
 
    DefaultScope,
17
 
    FixedScope,
18
 
    MultiScopeHandler,
19
 
    )
20
 
from lp.services.features.xmlrpc import FeatureFlagApplication
21
 
from lp.testing import (
22
 
    feature_flags,
23
 
    set_feature_flag,
24
 
    TestCaseWithFactory,
25
 
    )
26
 
from lp.testing.xmlrpc import XMLRPCTestTransport
27
 
 
28
 
 
29
 
class TestGetFeatureFlag(TestCaseWithFactory):
30
 
 
31
 
    layer = DatabaseFunctionalLayer
32
 
 
33
 
    def setUp(self):
34
 
        TestCaseWithFactory.setUp(self)
35
 
        self.endpoint = FeatureFlagApplication()
36
 
 
37
 
    def installFeatureController(self, feature_controller):
38
 
        old_features = features.get_relevant_feature_controller()
39
 
        features.install_feature_controller(feature_controller)
40
 
        self.addCleanup(
41
 
            features.install_feature_controller, old_features)
42
 
 
43
 
    def test_getFeatureFlag_returns_None_by_default(self):
44
 
        self.assertIs(None, self.endpoint.getFeatureFlag(u'unknown'))
45
 
 
46
 
    def test_getFeatureFlag_returns_true_for_set_flag(self):
47
 
        flag_name = u'flag'
48
 
        with feature_flags():
49
 
            set_feature_flag(flag_name, u'1')
50
 
            self.assertEqual(u'1', self.endpoint.getFeatureFlag(flag_name))
51
 
 
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
55
 
        # request itself.
56
 
        flag_name = u'flag'
57
 
        scope_name = u'scope'
58
 
        self.installFeatureController(
59
 
            FeatureController(
60
 
                MultiScopeHandler(
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))
65
 
 
66
 
    def test_getFeatureFlag_considers_supplied_scope(self):
67
 
        flag_name = u'flag'
68
 
        scope_name = u'scope'
69
 
        with feature_flags():
70
 
            set_feature_flag(flag_name, u'value', scope_name)
71
 
            self.assertEqual(
72
 
                u'value',
73
 
                self.endpoint.getFeatureFlag(flag_name, [scope_name]))
74
 
 
75
 
    def test_getFeatureFlag_turns_user_into_team_scope(self):
76
 
        flag_name = u'flag'
77
 
        person = self.factory.makePerson()
78
 
        team = self.factory.makeTeam(members=[person])
79
 
        with feature_flags():
80
 
            set_feature_flag(flag_name, u'value', u'team:' + team.name)
81
 
            self.assertEqual(
82
 
                u'value',
83
 
                self.endpoint.getFeatureFlag(
84
 
                    flag_name, ['user:' + person.name]))
85
 
 
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'))
91
 
 
92
 
    def test_xmlrpc_interface_set(self):
93
 
        sp = xmlrpclib.ServerProxy(
94
 
            config.launchpad.feature_flags_endpoint,
95
 
            transport=XMLRPCTestTransport(), allow_none=True)
96
 
        flag_name = u'flag'
97
 
        with feature_flags():
98
 
            set_feature_flag(flag_name, u'1')
99
 
            self.assertEqual(u'1', sp.getFeatureFlag(flag_name))