How to use the canvasapi.exceptions.RequiredFieldMissing function in canvasapi

To help you get started, we’ve selected a few canvasapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ucfopen / canvasapi / tests / test_appointment_group.py View on Github external
def test_edit_appointment_group_fail(self, m):
        with self.assertRaises(RequiredFieldMissing):
            self.appointment_group.edit({})
github ucfopen / canvasapi / canvasapi / module.py View on Github external
:calls: `POST /api/v1/courses/:course_id/modules/:module_id/items \
        `_

        :param module_item: The attributes to create the module item with.
        :type module_item: dict
        :returns: The created module item.
        :rtype: :class:`canvasapi.module.ModuleItem`
        """
        if isinstance(module_item, dict) and 'type' in module_item:
            if 'content_id' in module_item:
                kwargs['module_item'] = module_item
            else:
                raise RequiredFieldMissing("Dictionary with key 'content_id' is required.")
        else:
            raise RequiredFieldMissing("Dictionary with key 'type' is required.")

        response = self._requester.request(
            'POST',
            'courses/{}/modules/{}/items'.format(self.course_id, self.id),
            _kwargs=combine_kwargs(**kwargs)
        )
        module_item_json = response.json()
        module_item_json.update({'course_id': self.course_id})

        return ModuleItem(self._requester, module_item_json)
github ucfopen / canvasapi / canvasapi / poll_choice.py View on Github external
"""
        Update an existing choice for this poll.

        :calls: `PUT /api/v1/polls/:poll_id/poll_choices/:id \
        `_

        :param poll_choice: List of arguments. 'text' is required and 'is_correct' and 'position' \
        are optional.
        :type poll_choice: list
        :rtype: :class:`canvasapi.poll_choice.PollChoice`
        """
        if (isinstance(poll_choice, list) and isinstance(poll_choice[0], dict)
                and 'text' in poll_choice[0]):
            kwargs['poll_choice'] = poll_choice
        else:
            raise RequiredFieldMissing(
                    "Dictionary with key 'text' is required."
                )

        response = self._requester.request(
            'PUT',
            'polls/{}/poll_choices/{}'.format(self.poll_id, self.id),
            _kwargs=combine_kwargs(**kwargs)
        )
        return PollChoice(self._requester, response.json()['poll_choices'][0])
github ucfopen / canvasapi / canvasapi / canvas.py View on Github external
:param planner_override: The override or the ID of the planner override to retrieve.
        :type planner_override: int or :class:`canvasapi.planner.PlannerOverride`

        :rtype: :class:`canvasapi.planner.PlannerOverride`
        """
        from canvasapi.planner import PlannerOverride

        if isinstance(planner_override, int) or isinstance(
            planner_override, PlannerOverride
        ):
            planner_override_id = obj_or_id(
                planner_override, "planner_override", (PlannerOverride,)
            )
        else:
            raise RequiredFieldMissing(
                "planner_override is required as an object or as an int."
            )

        response = self.__requester.request(
            "GET",
            "planner/overrides/{}".format(planner_override_id),
            _kwargs=combine_kwargs(**kwargs),
        )

        return PlannerOverride(self.__requester, response.json())
github ucfopen / canvasapi / canvasapi / canvas.py View on Github external
isinstance(appointment_group, dict)
            and "context_codes" in appointment_group
            and "title" in appointment_group
        ):
            kwargs["appointment_group"] = appointment_group

        elif (
            isinstance(appointment_group, dict)
            and "context_codes" not in appointment_group
        ):
            raise RequiredFieldMissing(
                "Dictionary with key 'context_codes' is missing."
            )

        elif isinstance(appointment_group, dict) and "title" not in appointment_group:
            raise RequiredFieldMissing("Dictionary with key 'title' is missing.")

        response = self.__requester.request(
            "POST", "appointment_groups", _kwargs=combine_kwargs(**kwargs)
        )

        return AppointmentGroup(self.__requester, response.json())
github ucfopen / canvasapi / canvasapi / group.py View on Github external
Create a new wiki page.

        :calls: `POST /api/v1/groups/:group_id/pages \
        `_

        :param wiki_page: Details about the page to create.
        :type wiki_page: dict
        :returns: The created page.
        :rtype: :class:`canvasapi.page.Page`
        """
        from canvasapi.course import Page

        if isinstance(wiki_page, dict) and "title" in wiki_page:
            kwargs["wiki_page"] = wiki_page
        else:
            raise RequiredFieldMissing("Dictionary with key 'title' is required.")

        response = self._requester.request(
            "POST", "groups/{}/pages".format(self.id), _kwargs=combine_kwargs(**kwargs)
        )

        page_json = response.json()
        page_json.update({"group_id": self.id})

        return Page(self._requester, page_json)
github ucfopen / canvasapi / canvasapi / account.py View on Github external
def create_subaccount(self, account, **kwargs):
        """
        Add a new sub-account to a given account.

        :calls: `POST /api/v1/accounts/:account_id/sub_accounts \
        `_

        :param account: The name of the account
        :type account: str

        :rtype: :class:`canvasapi.account.Account`
        """
        if isinstance(account, dict) and "name" in account:
            kwargs["account"] = account
        else:
            raise RequiredFieldMissing("Dictionary with key 'name' is required.")

        response = self._requester.request(
            "POST",
            "accounts/{}/sub_accounts".format(self.id),
            _kwargs=combine_kwargs(**kwargs),
        )
        return Account(self._requester, response.json())
github ucfopen / canvasapi / canvasapi / poll.py View on Github external
:calls: `POST /api/v1/polls/:poll_id/poll_choices \
        `_

        :param poll_choice: 'text' is required, 'is_correct' and 'position' are optional.
        :type poll_choice: list
        :rtype: :class:`canvasapi.poll_choice.PollChoice`
        """
        if (
            isinstance(poll_choice, list)
            and isinstance(poll_choice[0], dict)
            and 'text' in poll_choice[0]
        ):
            kwargs['poll_choice'] = poll_choice
        else:
            raise RequiredFieldMissing(
                    "Dictionary with key 'text' is required."
                )

        response = self._requester.request(
            'POST',
            'polls/{}/poll_choices'.format(self.id),
            _kwargs=combine_kwargs(**kwargs)
        )
        return PollChoice(self._requester, response.json()['poll_choices'][0])
github ucfopen / canvasapi / canvasapi / canvas.py View on Github external
"""
        Create a new Calendar Event.

        :calls: `POST /api/v1/calendar_events \
        `_

        :param calendar_event: The attributes of the calendar event.
        :type calendar_event: `dict`
        :rtype: :class:`canvasapi.calendar_event.CalendarEvent`
        """
        from canvasapi.calendar_event import CalendarEvent

        if isinstance(calendar_event, dict) and "context_code" in calendar_event:
            kwargs["calendar_event"] = calendar_event
        else:
            raise RequiredFieldMissing(
                "Dictionary with key 'context_codes' is required."
            )

        response = self.__requester.request(
            "POST", "calendar_events", _kwargs=combine_kwargs(**kwargs)
        )

        return CalendarEvent(self.__requester, response.json())
github ucfopen / canvasapi / canvasapi / poll_session.py View on Github external
:param poll_session: List of arguments. course_id (required): id of the course for the
            session, course_section_id (optional): id of the course section for this session,
            has_public_results (optional): whether the results are viewable by students.
        :type poll_session: list

        :rtype: :class:`canvasapi.poll_session.PollSession`
        """
        if (
            isinstance(poll_session, list)
            and isinstance(poll_session[0], dict)
            and 'course_id' in poll_session[0]
        ):
            kwargs['poll_session'] = poll_session
        else:
            raise RequiredFieldMissing(
                "Dictionary with key 'course_id' is required."
            )

        response = self._requester.request(
            'PUT',
            'polls/{}/poll_sessions/{}'.format(self.poll_id, self.id),
            _kwargs=combine_kwargs(**kwargs)
        )
        return PollSession(self._requester, response.json()['poll_sessions'][0])