def test_invalid_get_course_from_id(self): """ Tests whether a course not in test data is not retrieved by id. """ try: get_course_from_id(id=2) # We expect this exception as documented. except ObjectDoesNotExist: return True
def test_extreme_invalid_get_course_from_id(self): """ Tests whether a course in test data is not retrieved by id passed a more extreme value. """ try: get_course_from_id(id=-1) # We expect this exception as documented. except AssertionError: return True self.fail()
def get_course(course_id: int): """ Gets a course from an id. :param course_id: An integer representing the course id. :return: Returns the Courses object. :raises: Raises CourseNotFoundException if the course does not exist. """ try: return get_course_from_id(course_id) except ObjectDoesNotExist: raise CourseNotFoundException
def get_leaders_course(course_id: int, user: User): """ Given a course id and a leader will return the courses object for that leader. :param course_id: The id of the Course :param user: The User object representing the leader. :return: Returns a Courses object. :raises: Raises a CourseNotFoundException if the course cannot be found. """ try: course = get_course_from_id(course_id) if not course.author == user: raise CourseNotFoundException return course except ObjectDoesNotExist: raise CourseNotFoundException
def test_valid_get_course_from_id(self): """ Tests whether the course in test data can be retrieved by id. """ self.assertTrue(get_course_from_id(id=1))