Esempio n. 1
0
    def test_act__two_middlewares__middlewares_are_called(self):
        sideeffect = Mock()

        def middleware1(next):
            def apply(action):
                sideeffect(1)
                next(action)

            return apply

        def middleware2(next):
            def apply(action):
                sideeffect(2)
                next(action)

            return apply

        target = Store(test_state, [middleware1, middleware2])
        test_action = Action()

        target.act(test_action)

        sideeffect.assert_has_calls([
            call(1),
            call(2)
        ])
Esempio n. 2
0
    def test_act__updates_state(self):
        expected = {'some': 'object'}
        target = Store(test_state)
        test_action = Action()
        test_action.act = Mock(return_value=expected)

        target.act(test_action)

        assert expected == target.state
Esempio n. 3
0
    def test_perform__query_gets_state(self):
        target = Store(test_state)

        test_query = Query()

        def assertion(state): assert test_state == state

        test_query.perform = assertion

        target.perform_query(test_query)
Esempio n. 4
0
    def test_act__action_gets_state(self):
        target = Store(test_state)

        test_action = Action()

        def assertion(state):
            assert test_state == state
            return state

        test_action.act = assertion

        target.act(test_action)
Esempio n. 5
0
    def test_act__one_middleware__middleware_is_called(self):
        sideeffect = Mock()

        def middleware(next):
            def apply(action):
                sideeffect()
                next(action)

            return apply

        target = Store(test_state, [middleware])
        test_action = Action()

        target.act(test_action)

        sideeffect.assert_called_once()
Esempio n. 6
0
    def test_act__state_not_changed__subscriber_not_triggered(self):
        target = Store(test_state)
        subscriber = Mock()
        target.subscribe(subscriber)
        test_action = Action()
        test_action.act = lambda state: state

        target.act(test_action)

        subscriber.assert_not_called()
Esempio n. 7
0
    def test_act__state_changed__subscriber_triggered(self):
        expected = {'some': 'object'}
        target = Store(test_state)
        subscriber = Mock()
        target.subscribe(subscriber)
        test_action = Action()
        test_action.act = Mock(return_value=expected)

        target.act(test_action)

        subscriber.assert_called_once()
Esempio n. 8
0
def create_store():
    store = Store(init_state, [restart_middleware])
    store.subscribe(render_state)
    return store