Exemplo n.º 1
0
    def test_page_desc_not_struct_warn(self):
        with mock.patch("warnings.warn") as mock_warn:
            PageBase(None, "", "abcd")
            self.assertTrue(mock_warn.call_count >= 1)

            expected_warn_msg = (
                "Not passing page_desc to PageBase.__init__ is deprecated")

            warned_with_expected_msg = False

            for args in mock_warn.call_args_list:
                if expected_warn_msg in args[0]:
                    warned_with_expected_msg = True
                    break

            if not warned_with_expected_msg:
                self.fail("'%s' is not warned as expected" % expected_warn_msg)
Exemplo n.º 2
0
    def test_get_modified_permissions_for_page(self):
        access_rule_permissions_list = [
            "view", "submit_answer", "end_session", "see_session_time",
            "lock_down_as_exam_session"]
        access_rule_permissions = frozenset(access_rule_permissions_list)

        with self.subTest(access_rules="Not present"):
            page_desc = dict_to_struct(
                {
                    "id": "abcd",
                    "type": "SomePageType",
                }
            )
            page = PageBase(None, "", page_desc)
            self.assertSetEqual(
                page.get_modified_permissions_for_page(access_rule_permissions),
                access_rule_permissions)

        with self.subTest(access_rules={}):
            page_desc = dict_to_struct(
                {
                    "id": "abcd",
                    "type": "SomePageType",
                    "access_rules": {}
                }
            )
            page = PageBase(None, "", page_desc)
            self.assertSetEqual(
                page.get_modified_permissions_for_page(access_rule_permissions),
                access_rule_permissions)

        with self.subTest(access_rules={"add_permissions": [],
                                        "remove_permissions": []}):
            page_desc = dict_to_struct(
                {
                    "id": "abcd",
                    "type": "SomePageType",
                    "access_rules": {"add_permissions": [],
                                     "remove_permissions": []}
                }
            )
            page = PageBase(None, "", page_desc)
            self.assertSetEqual(
                page.get_modified_permissions_for_page(access_rule_permissions),
                access_rule_permissions)

        with self.subTest(access_rules={"add_permissions": ["some_perm"],
                                        "remove_permissions": []}):
            page_desc = dict_to_struct(
                {
                    "id": "abcd",
                    "type": "SomePageType",
                    "access_rules": {"add_permissions": ["some_perm"],
                                     "remove_permissions": []}
                }
            )
            page = PageBase(None, "", page_desc)
            self.assertSetEqual(
                page.get_modified_permissions_for_page(access_rule_permissions),
                frozenset(access_rule_permissions_list + ["some_perm"]))

        with self.subTest(access_rules={"remove_permissions": ["none_exist_perm"]}):
            page_desc = dict_to_struct(
                {
                    "id": "abcd",
                    "type": "SomePageType",
                    "access_rules": {"remove_permissions": ["none_exist_perm"]}
                }
            )
            page = PageBase(None, "", page_desc)

            self.assertSetEqual(
                page.get_modified_permissions_for_page(access_rule_permissions),
                access_rule_permissions)

        with self.subTest(access_rules={
                "remove_permissions": [access_rule_permissions_list[0]]}):
            page_desc = dict_to_struct(
                {
                    "id": "abcd",
                    "type": "SomePageType",
                    "access_rules": {
                        "remove_permissions": [access_rule_permissions_list[0]]}
                }
            )
            page = PageBase(None, "", page_desc)

            self.assertSetEqual(
                page.get_modified_permissions_for_page(access_rule_permissions),
                frozenset(access_rule_permissions_list[1:]))
Exemplo n.º 3
0
    def test_get_modified_permissions_for_page(self):
        access_rule_permissions_list = [
            "view", "submit_answer", "end_session", "see_session_time",
            "lock_down_as_exam_session"]
        access_rule_permissions = frozenset(access_rule_permissions_list)

        with self.subTest(access_rules="Not present"):
            page_desc = dict_to_struct(
                {
                    "id": "abcd",
                    "type": "SomePageType",
                }
            )
            page = PageBase(None, "", page_desc)
            self.assertSetEqual(
                page.get_modified_permissions_for_page(access_rule_permissions),
                access_rule_permissions)

        with self.subTest(access_rules={}):
            page_desc = dict_to_struct(
                {
                    "id": "abcd",
                    "type": "SomePageType",
                    "access_rules": {}
                }
            )
            page = PageBase(None, "", page_desc)
            self.assertSetEqual(
                page.get_modified_permissions_for_page(access_rule_permissions),
                access_rule_permissions)

        with self.subTest(access_rules={"add_permissions": [],
                                        "remove_permissions": []}):
            page_desc = dict_to_struct(
                {
                    "id": "abcd",
                    "type": "SomePageType",
                    "access_rules": {"add_permissions": [],
                                     "remove_permissions": []}
                }
            )
            page = PageBase(None, "", page_desc)
            self.assertSetEqual(
                page.get_modified_permissions_for_page(access_rule_permissions),
                access_rule_permissions)

        with self.subTest(access_rules={"add_permissions": ["some_perm"],
                                        "remove_permissions": []}):
            page_desc = dict_to_struct(
                {
                    "id": "abcd",
                    "type": "SomePageType",
                    "access_rules": {"add_permissions": ["some_perm"],
                                     "remove_permissions": []}
                }
            )
            page = PageBase(None, "", page_desc)
            self.assertSetEqual(
                page.get_modified_permissions_for_page(access_rule_permissions),
                frozenset(access_rule_permissions_list + ["some_perm"]))

        with self.subTest(access_rules={"remove_permissions": ["none_exist_perm"]}):
            page_desc = dict_to_struct(
                {
                    "id": "abcd",
                    "type": "SomePageType",
                    "access_rules": {"remove_permissions": ["none_exist_perm"]}
                }
            )
            page = PageBase(None, "", page_desc)

            self.assertSetEqual(
                page.get_modified_permissions_for_page(access_rule_permissions),
                access_rule_permissions)

        with self.subTest(access_rules={
                "remove_permissions": [access_rule_permissions_list[0]]}):
            page_desc = dict_to_struct(
                {
                    "id": "abcd",
                    "type": "SomePageType",
                    "access_rules": {
                        "remove_permissions": [access_rule_permissions_list[0]]}
                }
            )
            page = PageBase(None, "", page_desc)

            self.assertSetEqual(
                page.get_modified_permissions_for_page(access_rule_permissions),
                frozenset(access_rule_permissions_list[1:]))