from plone import api
from ploneintranet.network.interfaces import INetworkGraph
from ploneintranet.network.interfaces import INetworkTool
from ploneintranet.network.testing import IntegrationTestCase
from Products.CMFPlone.utils import get_installer
from zope.component import queryUtility


class TestNetworkTool(IntegrationTestCase):
    def setUp(self):
        self.portal = self.layer["portal"]
        self.installer = get_installer(self.portal, self.layer["request"])

    def test_network_tool_available(self):
        tool = queryUtility(INetworkTool)
        self.assertTrue(INetworkGraph.providedBy(tool))

    def test_network_tool_uninstalled(self):
        with api.env.adopt_roles(["Manager"]):
            self.installer.uninstall_product("ploneintranet.network")
        self.assertNotIn("ploneintranet_network", self.portal)
        tool = queryUtility(INetworkTool)
        self.assertIsNone(tool)
