Пример #1
0
    def test_grade_reporting_post_assignment_500s(self):
        """
        Test that the client raises the appropriate error if Canvas returns an error after the client posts an
        assignment.
        """
        with responses.RequestsMock() as rsps:
            rsps.add(responses.GET, self.canvas_assignment_url, json=[])
            rsps.add(responses.POST,
                     self.canvas_assignment_url,
                     json={
                         'errors': [{
                             'message':
                             'The specified resource does not exist.'
                         }]
                     })
            canvas_api_client = CanvasAPIClient(self.enterprise_config)

            # Creating a Canvas assignment will require the session to be created
            rsps.add(responses.POST,
                     self.oauth_url,
                     json=self._token_response(),
                     status=200)
            canvas_api_client._create_session()  # pylint: disable=protected-access

            with pytest.raises(ClientError) as client_error:
                canvas_api_client._handle_canvas_assignment_retrieval(  # pylint: disable=protected-access
                    'integration_id_1', self.canvas_course_id,
                    'assignment_name')

            assert client_error.value.message == 'Something went wrong creating an assignment on Canvas. Got ' \
                                                 'response: {"errors": [{"message": "The specified resource does not ' \
                                                 'exist."}]}'
Пример #2
0
    def test_grade_reporting_get_assignment_500s(self):
        """
        Test that the client raises the appropriate error if Canvas responds with an error after the client requests
        course assignments.
        """
        with responses.RequestsMock() as rsps:
            rsps.add(responses.GET,
                     self.canvas_assignment_url,
                     json={'error': 'something went wrong'},
                     status=400)
            canvas_api_client = CanvasAPIClient(self.enterprise_config)

            # Creating a Canvas assignment will require the session to be created
            rsps.add(responses.POST,
                     self.oauth_url,
                     json=self._token_response(),
                     status=200)
            canvas_api_client._create_session()  # pylint: disable=protected-access

            with pytest.raises(ClientError) as client_error:
                canvas_api_client._handle_canvas_assignment_retrieval(  # pylint: disable=protected-access
                    'integration_id_1', self.canvas_course_id,
                    'assignment_name')

            assert client_error.value.message == 'Something went wrong retrieving assignments from Canvas. Got' \
                                                 ' response: {"error": "something went wrong"}'