Beispiel #1
0
 def clean_course(self):
     """
     Verify course ID and retrieve course details.
     """
     course_id = self.cleaned_data[self.Fields.COURSE].strip()
     if not course_id:
         return None
     try:
         client = EnrollmentApiClient()
         return client.get_course_details(course_id)
     except (HttpClientError, HttpServerError):
         raise ValidationError(ValidationMessages.INVALID_COURSE_ID.format(course_id=course_id))
Beispiel #2
0
    def clean_course(self):
        """
        Verify course ID has an associated course in LMS.
        """
        course_id = self.cleaned_data[self.Fields.COURSE].strip()
        client = EnrollmentApiClient()
        # Checks whether a course exist in lms with the given course id.
        if not client.get_course_details(course_id):
            raise ValidationError(
                ValidationMessages.INVALID_COURSE_ID.format(
                    course_id=course_id))

        # Checks whether a course exists in customer catalog.
        if not self.is_course_in_catalog(course_id):
            raise ValidationError(
                ValidationMessages.COURSE_NOT_EXIST_IN_CATALOG)
        return course_id