Пример #1
0
    def __init__(self, feature_string, nodelist):
        self.feature_string = feature_string
        self.nodelist = nodelist

        # We expect Redis to be on localhost at the standard port.
        r = Redis()
        self.proclaim = Proclaim(r)
Пример #2
0
class ProclaimNode(Node):
    def __init__(self, feature_string, nodelist):
        self.feature_string = feature_string
        self.nodelist = nodelist

        # We expect Redis to be on localhost at the standard port.
        r = Redis()
        self.proclaim = Proclaim(r)

    def render(self, context):
        feature = self.feature_string
        user = resolve_variable('user', context)
        if not user.is_authenticated:
            return ''
        is_active = self.proclaim.is_active(feature, user)
        if is_active:
            return self.nodelist.render(context)
        return ''
Пример #3
0
 def setUp(self):
     self.redis = redis.Redis(host='localhost', port=6379)
     self.proclaim = Proclaim(self.redis)
     self.proclaim.define_group("a", jim, joan)
     self.proclaim.define_group("b", jim, joan, bob)
Пример #4
0
class TestProclaim(unittest.TestCase):
    def setUp(self):
        self.redis = redis.Redis(host='localhost', port=6379)
        self.proclaim = Proclaim(self.redis)
        self.proclaim.define_group("a", jim, joan)
        self.proclaim.define_group("b", jim, joan, bob)

    def test_groups(self):
        assert len(self.proclaim.groups["b"]) == 3
        assert jim.id in self.proclaim.groups["a"]

    def test_activate_group(self):
        self.proclaim.activate_group("f1", "b")
        assert self.proclaim.is_active("f1", jim)

    def test_deactivate_group(self):
        self.proclaim.deactivate_group("f1", "b")
        assert not self.proclaim.is_active("f1", jim)

    def test_activate_user(self):
        self.proclaim.activate_user("f2", joan)
        assert self.proclaim.is_active("f2", joan)

    def test_deactivate_user(self):
        self.proclaim.deactivate_user("f2", joan)
        assert not self.proclaim.is_active("f2", joan)

    def test_activate_percentage(self):
        self.proclaim.activate_percentage("f3", 25)
        assert self.proclaim.is_active("f3", jim)
        assert self.proclaim.is_active("f3", joan)
        assert not self.proclaim.is_active("f3", bob)

    def test_deactivate_percentage(self):
        self.proclaim.deactivate_percentage("f3", 25)
        assert not self.proclaim.is_active("f3", jim)
Пример #5
0
 def setUp(self):
     self.redis = redis.Redis(host='localhost', port=6379)
     self.proclaim = Proclaim(self.redis)
     self.proclaim.define_group("a", jim, joan)
     self.proclaim.define_group("b", jim, joan, bob)
Пример #6
0
class TestProclaim(unittest.TestCase):

    def setUp(self):
        self.redis = redis.Redis(host='localhost', port=6379)
        self.proclaim = Proclaim(self.redis)
        self.proclaim.define_group("a", jim, joan)
        self.proclaim.define_group("b", jim, joan, bob)

    def test_groups(self):
        assert len(self.proclaim.groups["b"]) == 3
        assert jim.id in self.proclaim.groups["a"]

    def test_activate_group(self):
        self.proclaim.activate_group("f1", "b")
        assert self.proclaim.is_active("f1", jim)

    def test_deactivate_group(self):
        self.proclaim.deactivate_group("f1", "b")
        assert not self.proclaim.is_active("f1", jim)

    def test_activate_user(self):
        self.proclaim.activate_user("f2", joan)
        assert self.proclaim.is_active("f2", joan)

    def test_deactivate_user(self):
        self.proclaim.deactivate_user("f2", joan)
        assert not self.proclaim.is_active("f2", joan)

    def test_activate_percentage(self):
        self.proclaim.activate_percentage("f3", 25)
        assert self.proclaim.is_active("f3", jim)
        assert self.proclaim.is_active("f3", joan)
        assert not self.proclaim.is_active("f3", bob)

    def test_deactivate_percentage(self):
        self.proclaim.deactivate_percentage("f3", 25)
        assert not self.proclaim.is_active("f3", jim)
Пример #7
0
class TemplateTagTest(TestCase):
    fixtures = ['users']
    
    def setUp(self):
        self.proclaim = Proclaim(Redis())
        self.active_user = User.objects.get(username="******")
        self.proclaim.activate_user("newfeature", self.active_user)
        self.inactive_user = User.objects.get(username="******")
        self.proclaim.deactivate_user("newfeature", self.inactive_user)
    
    def test_anonymous_user(self):
        t = Template("""{% load rollout %}
        {% rollout newfeature %}
            You should not see this feature.
        {% endrollout %}""")
        context = Context({
            'user': AnonymousUser()
        })
        content = t.render(context)
        self.assertTrue("feature" not in content)
    
    def test_inactive_user(self):
        t = Template("""{% load rollout %}
        {% rollout newfeature %}
          You should not see this feature.
        {% endrollout %}
        """)
        context = Context({
            'user': self.inactive_user
        })
        content = t.render(context)
        self.assertTrue("feature" not in content)
    
    def test_active_user(self):
        t = Template("""{% load rollout %}
        {% rollout "newfeature" %}
          You should not see this feature.
        {% endrollout %}
        """)
        context = Context({
            'user': self.active_user
        })
        content = t.render(context)
        self.assertTrue("feature" in content)
    
    def test_active_user_with_template(self):
        t = Template("""{% load rollout %}
        {% rollout newfeature "newfeature.html" %}""")
        context = Context({
            'user': self.active_user
        })
        content = t.render(context)
        self.assertTrue("feature" in content)
    
    def test_inactive_user_with_template(self):
        t = Template("""{% load rollout %}
        {% rollout newfeature "newfeature.html" %}""")
        context = Context({
            'user': self.inactive_user
        })
        content = t.render(context)
        self.assertTrue("feature" not in content)
    
    def test_anonymous_user_with_template(self):
        t = Template("""{% load rollout %}
        {% rollout newfeature "newfeature.html" %}""")
        context = Context({
            'user': AnonymousUser()
        })
        content = t.render(context)
        self.assertTrue("feature" not in content)
    
    def tearDown(self):
        self.proclaim.deactivate_all("newfeature")
Пример #8
0
 def setUp(self):
     self.proclaim = Proclaim(Redis())
     self.active_user = User.objects.get(username="******")
     self.proclaim.activate_user("newfeature", self.active_user)
     self.inactive_user = User.objects.get(username="******")
     self.proclaim.deactivate_user("newfeature", self.inactive_user)