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_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_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_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_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