def test_hashing_is_consistent(self):
     percentage = Percentage(value=0.67001)
     bucketer = ConsistentHashPercentageBucketer(percentage=percentage)
     for _ in range(10):
         self.assertTrue(
             bucketer.check(foo="bar", herp=99, derp=False)  # score = 0.67
         )
 def test_sets_correct_data(self):
     percentage = Percentage(value=0.5)
     data = {
         "type": PercentageBucketer.get_type(),
         "percentage": percentage.to_dict(),
     }
     bucketer = PercentageBucketer.from_dict(data)
     self.assertEqual(data, bucketer.to_dict())
 def test_returns_correct_data(self):
     percentage = Percentage(value=0.5)
     bucketer = PercentageBucketer(percentage=percentage)
     expected = {
         "type": PercentageBucketer.get_type(),
         "percentage": percentage.to_dict(),
     }
     self.assertEqual(expected, bucketer.to_dict())
Exemplo n.º 4
0
 def test_passes_arguments_through_to_created_bucketer(self):
     percentage = 0.21
     bucketer = BucketerFactory.create(
         {
             "type": PercentageBucketer.get_type(),
             "percentage": Percentage(value=percentage).to_dict(),
         }
     )
     self.assertEqual(percentage, bucketer.percentage)
 def test_sets_correct_data(self):
     percentage = Percentage(value=0.5)
     key_whitelist = ["foo"]
     data = {
         "type": ConsistentHashPercentageBucketer.get_type(),
         "key_whitelist": key_whitelist,
         "percentage": percentage.to_dict(),
     }
     bucketer = ConsistentHashPercentageBucketer.from_dict(data)
     self.assertEqual(data, bucketer.to_dict())
Exemplo n.º 6
0
    def test_bucketer_gets_included_in_meta(self):
        percentage_value = 0.1
        bucketer = PercentageBucketer(percentage=Percentage(percentage_value))

        self.store.create(self.name)
        self.flag.set_bucketer(bucketer)

        meta = self.flag.get_meta()

        self.assertEqual(bucketer.to_dict(), meta["bucketer"])
 def test_returns_correct_data(self):
     percentage = Percentage(value=0.5)
     key_whitelist = ["foo"]
     bucketer = ConsistentHashPercentageBucketer(
         key_whitelist=key_whitelist, percentage=percentage)
     expected = {
         "type": ConsistentHashPercentageBucketer.get_type(),
         "key_whitelist": key_whitelist,
         "percentage": percentage.to_dict(),
     }
     self.assertEqual(expected, bucketer.to_dict())
Exemplo n.º 8
0
    def test_bucketer_gets_included_in_meta(self):
        feature_name = self.txt()

        percentage_value = 0.1
        bucketer = PercentageBucketer(percentage=Percentage(percentage_value))

        self.client.create(feature_name)
        self.client.set_bucketer(feature_name, bucketer)

        meta = self.client.get_meta(feature_name)

        self.assertEqual(bucketer.to_dict(), meta["bucketer"])
Exemplo n.º 9
0
    def test_emits_post_set_bucketer_event(self):
        feature_name = self.txt()
        events = FlipperEventEmitter()

        listener = MagicMock()

        events.on(EventType.POST_SET_BUCKETER, f=listener)

        percentage_value = 0.1
        bucketer = PercentageBucketer(percentage=Percentage(percentage_value))

        self.client.events = events
        self.store.create(feature_name)
        self.client.set_bucketer(feature_name, bucketer)

        listener.assert_called_once_with(feature_name, bucketer)
Exemplo n.º 10
0
 def test_sets_bucketer(self):
     percentage_value = 0.1
     bucketer = PercentageBucketer(percentage=Percentage(percentage_value))
     meta = FeatureFlagStoreMeta(self.now)
     meta.update(bucketer=bucketer)
     self.assertEqual(percentage_value, meta.bucketer.percentage)
 def test_always_returns_false_when_percentage_is_zero_when_including_conditions(
         self):  # noqa: E501
     percentage = Percentage(value=0.0)
     bucketer = ConsistentHashPercentageBucketer(percentage=percentage)
     self.assertFalse(bucketer.check(foo="bar"))  # score = 0.79
 def test_returns_true_when_conditions_hash_to_value_equal_to_percentage(
         self):  # noqa: E501
     percentage = Percentage(value=0.79)
     bucketer = ConsistentHashPercentageBucketer(percentage=percentage)
     self.assertTrue(bucketer.check(foo="bar"))  # score = 0.79
Exemplo n.º 13
0
 def test_matches_value_provided_in_constructor(self):
     value = 0.8
     percentage = Percentage(value=value)
     self.assertEqual(value, percentage.value)
 def test_always_returns_false_when_percentage_is_zero(self):
     percentage = Percentage(value=0.0)
     bucketer = PercentageBucketer(percentage=percentage)
     randomizer = MagicMock(return_value=0.0)
     self.assertFalse(bucketer.check(randomizer=randomizer))
 def test_returns_true_when_randomized_is_equal_to_percentage(self):
     percentage = Percentage(value=0.5)
     bucketer = PercentageBucketer(percentage=percentage)
     randomizer = MagicMock(return_value=0.5)
     self.assertTrue(bucketer.check(randomizer=randomizer))
 def test_returns_true_when_randomized_is_equal_to_percentage(self):
     percentage = Percentage(value=0.32)
     bucketer = ConsistentHashPercentageBucketer(percentage=percentage)
     self.assertTrue(bucketer.check())  # score = 0.32
Exemplo n.º 17
0
 def test_is_correct_value(self):
     percentage = Percentage()
     self.assertEqual("Percentage", percentage.get_type())
Exemplo n.º 18
0
 def test_returns_correct_values(self):
     value = 0.8
     percentage = Percentage(value=value)
     expected = {"value": value, "type": Percentage.get_type()}
     self.assertEqual(expected, percentage.to_dict())
Exemplo n.º 19
0
 def test_defaults_to_1_dot_0(self):
     percentage = Percentage()
     self.assertEqual(1.0, percentage.value)
 def test_returns_percentage_value_as_float(self):
     percentage_raw_value = 0.5
     percentage = Percentage(value=percentage_raw_value)
     bucketer = PercentageBucketer(percentage=percentage)
     self.assertEqual(percentage_raw_value, bucketer.percentage)
Exemplo n.º 21
0
 def test_includes_currect_bucketer(self):
     bucketer = PercentageBucketer(percentage=Percentage(0.3))
     meta = FeatureFlagStoreMeta(self.now, bucketer=bucketer)
     self.assertEqual(bucketer.to_dict(), meta.to_dict()["bucketer"])
 def test_returns_false_when_randomized_is_greater_than_percentage(self):
     percentage = Percentage(value=0.5)
     bucketer = PercentageBucketer(percentage=percentage)
     randomizer = MagicMock(return_value=0.6)
     self.assertFalse(bucketer.check(randomizer=randomizer))
Exemplo n.º 23
0
    def test_when_comparison_is_less_then_value_it_returns_true(self):
        percentage = Percentage(0.5)

        self.assertTrue(0.4 <= percentage)
 def test_returns_false_when_randomized_is_greater_than_percentage(self):
     percentage = Percentage(value=0.2)
     bucketer = ConsistentHashPercentageBucketer(percentage=percentage)
     self.assertFalse(bucketer.check())  # score = 0.32
Exemplo n.º 25
0
 def test_can_create_with_bucketer(self):
     bucketer = PercentageBucketer(percentage=Percentage(0.3))
     json = {"created_date": self.now, "bucketer": bucketer.to_dict()}
     meta = FeatureFlagStoreMeta.from_dict(json)
     self.assertEqual(bucketer.to_dict(), meta.bucketer.to_dict())
Exemplo n.º 26
0
    def test_when_comparison_is_equal_to_value_it_returns_true(self):
        percentage = Percentage(0.5)

        self.assertTrue(0.5 <= percentage)
 def test_always_returns_false_when_percentage_is_zero(self):
     percentage = Percentage(value=0.0)
     bucketer = ConsistentHashPercentageBucketer(percentage=percentage)
     self.assertFalse(bucketer.check())  # score = 0.32
Exemplo n.º 28
0
    def test_when_comparison_is_greater_than_value_it_returns_false(self):
        percentage = Percentage(0.5)

        self.assertFalse(0.6 <= percentage)
 def test_returns_false_when_conditions_hash_to_value_greater_than_percentage(
         self):  # noqa: E501
     percentage = Percentage(value=0.5)
     bucketer = ConsistentHashPercentageBucketer(percentage=percentage)
     self.assertFalse(bucketer.check(foo="bar"))  # score = 0.79