Esempio n. 1
0
    def test_emits_post_disable_event(self):
        feature_name = self.txt()
        events = FlipperEventEmitter()

        listener = MagicMock()

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

        self.client.events = events
        self.client.create(feature_name)
        self.client.disable(feature_name)

        listener.assert_called_once_with(feature_name)
Esempio n. 2
0
    def test_emits_pre_destroy_event(self):
        feature_name = self.txt()
        events = FlipperEventEmitter()

        listener = MagicMock()

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

        self.client.events = events
        self.client.create(feature_name)
        self.client.destroy(feature_name)

        listener.assert_called_once_with(feature_name)
Esempio n. 3
0
 def test_all_listeners_get_removed(self, event_type):
     mock = MagicMock()
     subscriber = DummySubscriber(mock)
     events = FlipperEventEmitter()
     events.register_subscriber(subscriber)
     events.remove_subscriber(subscriber)
     events.emit(event_type)
     getattr(mock, "on_%s" % event_type.value).assert_not_called()
Esempio n. 4
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)
Esempio n. 5
0
    def test_emits_post_add_condition_event(self):
        feature_name = self.txt()
        events = FlipperEventEmitter()

        listener = MagicMock()

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

        condition_checks = {self.txt(): True}
        condition = Condition(**condition_checks)

        self.client.events = events
        self.store.create(feature_name)
        self.client.add_condition(feature_name, condition)

        listener.assert_called_once_with(feature_name, condition)
Esempio n. 6
0
    def test_emits_post_set_client_data_event(self):
        feature_name = self.txt()
        events = FlipperEventEmitter()

        listener = MagicMock()

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

        existing_data = {"existing_key": self.txt()}

        self.client.events = events
        self.client.create(feature_name, client_data=existing_data)

        new_data = {"existing_key": self.txt(), "new_key": self.txt()}
        self.client.set_client_data(feature_name, new_data)

        listener.assert_called_once_with(feature_name, new_data)
Esempio n. 7
0
    def test_emits_post_create_event_with_correct_args(self):
        events = FlipperEventEmitter()

        listener = MagicMock()

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

        feature_name = self.txt()
        client_data = {"x": 10}

        self.client.events = events
        self.client.create(feature_name,
                           is_enabled=True,
                           client_data=client_data)

        listener.assert_called_with(feature_name,
                                    is_enabled=True,
                                    client_data=client_data)