# -*- coding: utf-8 -*-
from collective.cover.testing import INTEGRATION_TESTING

import unittest


class PermissionsTestCase(unittest.TestCase):

    layer = INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer["portal"]

    def test_setup_permission(self):
        permission = "collective.cover: Setup"
        roles = self.portal.rolesOfPermission(permission)
        roles = [r["name"] for r in roles if r["selected"]]
        expected = ["Manager", "Site Administrator"]
        self.assertListEqual(roles, expected)

    def test_can_export_layout_permission(self):
        permission = "collective.cover: Can Export Layout"
        roles = self.portal.rolesOfPermission(permission)
        roles = [r["name"] for r in roles if r["selected"]]
        expected = ["Manager", "Site Administrator"]
        self.assertListEqual(roles, expected)

    def test_can_edit_layout_permission(self):
        permission = "collective.cover: Can Edit Layout"
        roles = self.portal.rolesOfPermission(permission)
        roles = [r["name"] for r in roles if r["selected"]]
        expected = ["Manager", "Site Administrator"]
        self.assertListEqual(roles, expected)

    def test_embed_code_permission(self):
        permission = "collective.cover: Embed Code"
        roles = self.portal.rolesOfPermission(permission)
        roles = [r["name"] for r in roles if r["selected"]]
        expected = ["Manager", "Site Administrator"]
        self.assertListEqual(roles, expected)
