Example #1
0
 def test_success(self, mock_role, mock_assign):
     mock_role.side_effect = lambda _, el_id: "{0}_el".format(el_id)
     cmd_acl._assign_roles_to_element(self.cib, "el", ["role1", "role2", "role3"])
     mock_role.assert_has_calls(
         [mock.call(self.cib, "role1"), mock.call(self.cib, "role2"), mock.call(self.cib, "role3")]
     )
     mock_assign.assert_has_calls(
         [mock.call("el", "role1_el"), mock.call("el", "role2_el"), mock.call("el", "role3_el")]
     )
Example #2
0
 def test_success(self, mock_role, mock_assign):
     mock_role.side_effect = lambda _, el_id: "{0}_el".format(el_id)
     cmd_acl._assign_roles_to_element(self.cib, "el",
                                      ["role1", "role2", "role3"])
     mock_role.assert_has_calls([
         mock.call(self.cib, "role1"),
         mock.call(self.cib, "role2"),
         mock.call(self.cib, "role3")
     ])
     mock_assign.assert_has_calls([
         mock.call("el", "role1_el"),
         mock.call("el", "role2_el"),
         mock.call("el", "role3_el")
     ])
Example #3
0
    def test_failure(self, mock_role, mock_assign):
        def _mock_role(_, el_id):
            if el_id in ["role1", "role3"]:
                raise acl_lib.AclRoleNotFound(el_id)
            elif el_id == "role2":
                return "role2_el"
            else:
                raise AssertionError("unexpected input")

        mock_role.side_effect = _mock_role
        assert_raise_library_error(
            lambda: cmd_acl._assign_roles_to_element(
                self.cib, "el", ["role1", "role2", "role3"]),
            (Severities.ERROR, report_codes.ID_NOT_FOUND, {
                "id": "role1",
                "id_description": "role",
            }), (Severities.ERROR, report_codes.ID_NOT_FOUND, {
                "id": "role3",
                "id_description": "role",
            }))
        mock_role.assert_has_calls([
            mock.call(self.cib, "role1"),
            mock.call(self.cib, "role2"),
            mock.call(self.cib, "role3")
        ])
        mock_assign.assert_called_once_with("el", "role2_el")
Example #4
0
    def test_failure(self, mock_role, mock_assign):
        def _mock_role(_, el_id):
            if el_id in ["role1", "role3"]:
                raise acl_lib.AclRoleNotFound(el_id)
            elif el_id == "role2":
                return "role2_el"
            else:
                raise AssertionError("unexpected input")

        mock_role.side_effect = _mock_role
        assert_raise_library_error(
            lambda: cmd_acl._assign_roles_to_element(self.cib, "el", ["role1", "role2", "role3"]),
            (Severities.ERROR, report_codes.ID_NOT_FOUND, {"id": "role1", "id_description": "role"}),
            (Severities.ERROR, report_codes.ID_NOT_FOUND, {"id": "role3", "id_description": "role"}),
        )
        mock_role.assert_has_calls(
            [mock.call(self.cib, "role1"), mock.call(self.cib, "role2"), mock.call(self.cib, "role3")]
        )
        mock_assign.assert_called_once_with("el", "role2_el")