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())
示例#3
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"])
示例#4
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"])
示例#5
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)
示例#6
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)
 def test_is_correct_value(self):
     bucketer = PercentageBucketer()
     self.assertEqual("PercentageBucketer", bucketer.get_type())
 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_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))
 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_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)
示例#12
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())
示例#13
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"])
示例#14
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)
示例#15
0
 def test_creates_percentage_bucketer(self):
     bucketer = BucketerFactory.create({"type": PercentageBucketer.get_type()})
     self.assertIsInstance(bucketer, PercentageBucketer)