Ejemplo n.º 1
0
    def test_activate_group_for_non_existent_group(self):
        FeatureFactory(name='my_feature')

        try:
            self.feature_flip.activate_group('my_feature', 'non_existent_group')
        except FeatureFlip.FeatureFlipError as error:
            self.assertEqual(error.message, 'Group non_existent_group does not exist')
Ejemplo n.º 2
0
    def test_group_registration(self):
        FeatureFactory(name='my_feature', totally_enabled=False)
        FeatureFactory(name='my_other_feature', totally_enabled=True)

        # we register a group of all actors with flip_id() > 5
        self.feature_flip.register('flip_id_gt_5', lambda obj: obj.flip_id() > 5)

        # we register a group of all actors with flip_id() <= 5
        self.feature_flip.register('flip_id_lte_5', lambda obj: obj.flip_id() <= 5)

        disabled_actor = self._actor(1)
        enabled_actor = self._actor(6)

        self.feature_flip.activate_group('my_feature', 'flip_id_gt_5')
        self.feature_flip.activate_group('my_other_feature', 'flip_id_lte_5')

        self.assertTrue(FeatureFlip().enabled('my_feature', enabled_actor))
        self.assertFalse(FeatureFlip().enabled('my_feature', disabled_actor))
Ejemplo n.º 3
0
    def test_enabled_for_totally_disabled_time_percentage(self):
        FeatureFactory(name='time_percentage_feature', time_percentage=0)
        actor = self._actor(1)

        self.assertFalse(self.feature_flip.enabled('time_percentage_feature', actor))
Ejemplo n.º 4
0
    def test_uniqueness_of_name(self):
        FeatureFactory(name='repeated_name')

        with self.assertRaises(IntegrityError):
            FeatureFactory(name='repeated_name')
Ejemplo n.º 5
0
    def test_enabled_for_totally_enabled_feature(self):
        FeatureFactory(name='my_disabled_feature', totally_enabled=True)
        actor = self._actor(1)

        self.assertTrue(self.feature_flip.enabled('my_disabled_feature', actor))
Ejemplo n.º 6
0
    def test_enabled_for_not_totally_enabled_feature(self):
        FeatureFactory(name='my_enabled_feature')
        actor = self._actor(1)

        self.assertFalse(self.feature_flip.enabled('my_enabled_feature', actor))
Ejemplo n.º 7
0
 def test_max_of_100_validation_for_time_percentage(self):
     with self.assertRaises(ValidationError):
         FeatureFactory(time_percentage=101).clean_fields()
Ejemplo n.º 8
0
 def test_max_of_40_characters_of_name(self):
     with self.assertRaises(DataError):
         FeatureFactory(name='This is a very large name, features should have short names')
Ejemplo n.º 9
0
    def test_enable_with_invalid_time_percentage(self):
        FeatureFactory(name='time_percentage_feature', time_percentage=10)

        with self.assertRaises(ValidationError):
            self.feature_flip.enable_time_percentage('time_percentage_feature', 200)
Ejemplo n.º 10
0
    def test_enable_time_percentage(self):
        feature = FeatureFactory(name='time_percentage_feature', time_percentage=10)
        self.feature_flip.enable_time_percentage('time_percentage_feature', 20)

        feature.refresh_from_db()
        self.assertEqual(feature.time_percentage, 20)