Exemplo n.º 1
0
 def test_course_completion_grade_submission_500s(self):
     """Test that we raise the error if Canvas experiences a 500 while posting course completion data"""
     with responses.RequestsMock() as rsps:
         rsps.add(responses.POST,
                  self.oauth_url,
                  json={"access_token": self.access_token},
                  status=200)
         rsps.add(responses.GET,
                  self.canvas_users_url,
                  json=[{
                      'sortable_name': 'test user',
                      'login_id': self.canvas_email,
                      'id': self.canvas_user_id
                  }],
                  status=200)
         rsps.add(responses.GET,
                  self.canvas_user_courses_url,
                  json=[{
                      'integration_id': self.integration_id,
                      'id': self.canvas_course_id
                  }])
         rsps.add(responses.GET,
                  self.canvas_course_assignments_url,
                  json=[{
                      'integration_id': self.integration_id,
                      'id': self.canvas_assignment_id
                  }])
         rsps.add(responses.PUT,
                  self.canvas_assignment_url,
                  body=Exception('something went wrong'))
         canvas_api_client = CanvasAPIClient(self.enterprise_config)
         with pytest.raises(Exception) as client_error:
             canvas_api_client.create_course_completion(
                 self.canvas_email, self.course_completion_payload)
         assert client_error.value.__str__() == 'something went wrong'
Exemplo n.º 2
0
    def test_course_completion_with_no_matching_canvas_course(self):
        """Test that we properly raise exceptions for when a course is not found in canvas."""
        with responses.RequestsMock() as rsps:
            rsps.add(responses.POST,
                     self.oauth_url,
                     json={"access_token": self.access_token},
                     status=200)
            rsps.add(responses.GET,
                     self.canvas_users_url,
                     json=[{
                         'sortable_name': 'test user',
                         'login_id': self.canvas_email,
                         'id': self.canvas_user_id
                     }],
                     status=200)
            rsps.add(responses.GET, self.canvas_user_courses_url, json=[])
            canvas_api_client = CanvasAPIClient(self.enterprise_config)
            with pytest.raises(CanvasClientError) as client_error:
                canvas_api_client.create_course_completion(
                    self.canvas_email, self.course_completion_payload)

            assert client_error.value.__str__() == \
                "Canvas Client Error: Course: {course_id} not found registered in Canvas for Edx " \
                "learner: {canvas_email}/Canvas learner: {canvas_user_id}.".format(
                    course_id=self.course_id,
                    canvas_email=self.canvas_email,
                    canvas_user_id=self.canvas_user_id
                )  # noqa
Exemplo n.º 3
0
    def test_course_completion_with_no_canvas_user(self):
        """Test that we properly raise exceptions if the client can't find the edx user in Canvas"""

        with responses.RequestsMock() as rsps:
            rsps.add(
                responses.GET,
                self.canvas_users_url,
                body="[]",
                status=200
            )
            rsps.add(
                responses.POST,
                self.oauth_url,
                json=self._token_response(),
                status=200
            )
            canvas_api_client = CanvasAPIClient(self.enterprise_config)

            with pytest.raises(ClientError) as client_error:
                canvas_api_client.create_course_completion(self.canvas_email, self.course_completion_payload)
                assert client_error.value.message == \
                    "Course: {course_id} not found registered in Canvas for Edx " \
                    "learner: {canvas_email}/Canvas learner: {canvas_user_id}.".format(
                        course_id=self.course_id,
                        canvas_email=self.canvas_email,
                        canvas_user_id=self.canvas_user_id
                    )
Exemplo n.º 4
0
    def test_course_completion_with_no_canvas_user(self):
        """Test that we properly raise exceptions if the client can't find the edx user in Canvas"""

        with responses.RequestsMock() as rsps:
            rsps.add(responses.GET,
                     self.canvas_users_url,
                     body="[]",
                     status=200)
            rsps.add(responses.POST,
                     self.oauth_url,
                     json={"access_token": self.access_token},
                     status=200)
            canvas_api_client = CanvasAPIClient(self.enterprise_config)
            with pytest.raises(CanvasClientError) as client_error:
                canvas_api_client.create_course_completion(
                    self.canvas_email, self.course_completion_payload)

            assert client_error.value.__str__() == 'Canvas Client Error: No Canvas user ID ' \
                                                   'found associated with email: {}'.format(self.canvas_email)