def test_component_remove_component_for_view(): mock_component = Mock() mock_child = Mock() Component._remove_component_for_view(mock_component, mock_child) mock_component.remove_component.assert_called_once_with(mock_child)
def test_component_detaches_from_child_after_child_is_remove(): component = Component(view=Mock(), presenter=Mock()) mock_cfactory = MockComponentFactory() new_child = component.new_component(mock_cfactory) component.remove_component(new_child) assert new_child.on_destroyed.num_connections == 0
def test_component_on_destroyed(): component = Component(view=Mock(), presenter=Mock()) callback = Mock() component.on_destroyed.connect(callback) component.destroy() callback.assert_called_once_with(component)
def test_component_destroy_destroys_child_components(): component = Component(view=Mock(), presenter=Mock()) mock_cfactories = [MockComponentFactory() for _ in range(3)] mock_children = [tcast(Mock, component.new_component(mock_cfactory)) for mock_cfactory in mock_cfactories] component.destroy() for mock_child in mock_children: mock_child.destroy.assert_called_once_with()
def test_component_destroy(): mock_view = Mock() mock_presenter = Mock() component = Component(view=mock_view, presenter=mock_presenter) component.destroy() assert component.is_destroyed mock_view._destroy.assert_called_once_with() mock_presenter._destroy.assert_called_once_with()
def test_component_new_component(): mock_view = Mock() mock_presenter = Mock() component = Component(view=mock_view, presenter=mock_presenter) mock_cfactory = MockComponentFactory() new_child = component.new_component(mock_cfactory) mock_cfactory.create.assert_called_once_with( view_env=mock_view.extend_env.return_value, presenter_env=mock_presenter.extend_env.return_value ) assert new_child == mock_cfactory.mock_child
def test_component_removes_child_if_child_is_destroyed(): component = Component(view=Mock(), presenter=Mock()) mock_cfactory = MockComponentFactory() new_child = tcast(MockComponent, component.new_component(mock_cfactory)) new_child.sim_destroy() # Should raise an error since child should have been automatically removed after it is destroyed. with pytest.raises(ValueError): component.remove_component(new_child) # Child should not be destroyed again by previous call to `component.remove_component()` new_child.destroy.assert_not_called()
def test_component_inits_view_and_presenter(): mock_view = Mock() mock_presenter = Mock() manager = Mock() manager.attach_mock(mock_view, 'mock_view') manager.attach_mock(mock_presenter, 'mock_presenter') component = Component(view=mock_view, presenter=mock_presenter) assert manager.mock_calls == [call.mock_presenter._init(mock_view), call.mock_view._init(mock_presenter)]
def test_component_remove_component(): component = Component(view=Mock(), presenter=Mock()) mock_cfactory = MockComponentFactory() mock_child = tcast(Mock, component.new_component(mock_cfactory)) component.remove_component(mock_child) mock_child.destroy.assert_called_once_with() # Should raise an error if we try to remove again. with pytest.raises(ValueError): component.remove_component(mock_child)
def test_component_new_component_for_view(): mock_component = Mock() mock_child = mock_component.new_component.return_value mock_cfactory = Mock() return_value = Component._new_component_for_view(mock_component, mock_cfactory) mock_component.new_component.assert_called_once_with(mock_cfactory) expected_return_value = ( mock_child, mock_child.view_rep, ) assert return_value == expected_return_value
def test_component_sets_view_component_hooks(): mock_view = Mock() component = Component(view=mock_view, presenter=Mock()) assert mock_view._component_hooks.new_component == component._new_component_for_view assert mock_view._component_hooks.remove_component == component._remove_component_for_view
def test_component_sets_presenter_component_hooks(): mock_presenter = Mock() component = Component(view=Mock(), presenter=mock_presenter) assert mock_presenter._component_hooks.component_destroy == component.destroy
def test_component_view_rep(): mock_view = Mock() component = Component(view=mock_view, presenter=Mock()) assert component.view_rep == mock_view._init.return_value