from plone import api
from ploneintranet.workspace.tests.base import BaseTestCase


class TestSetupHandlers(BaseTestCase):
    """Check that the setuphandlers code sets the site up correctly"""

    def test_workspace_groups_hidden(self):
        """collective.workspace groups should be hidden when enumerating"""
        self.login_as_portal_owner()
        workspace_folder = api.content.create(
            self.workspace_container,
            "ploneintranet.workspace.workspacefolder",
            "example-workspace",
            title="Welcome to my workspace",
        )
        groupname = "Members:%s" % workspace_folder.UID()
        self.assertIsNotNone(api.group.get(groupname=groupname))
        # Use pas search to mimic the control panel groups views
        pas_search = api.content.get_view("pas_search", self.portal, self.request)
        group_info = pas_search.searchGroups()
        self.assertNotIn(groupname, [x["id"] for x in group_info])

    def test_placeful_workflow_policy(self):
        """globally addable types should be configured to use the default
        chain in the ploneintranet policy"""

        pwftool = api.portal.get_tool("portal_placeful_workflow")
        policy = pwftool["ploneintranet_policy"]
        default_chain = policy.getDefaultChain(None)

        default_types = ["Collection", "Document", "File", "Image", "Link", "News Item"]
        for portal_type in default_types:
            self.assertEqual(default_chain, policy.getChainFor(portal_type))
