def courses(): courses_list = [ Course(1, "Course1", True, 3, None, 1.3, 4, 5, 1), Course(2, "Course2", False, 2, None, 3.5, 2, 13, 5), Course(3, "Course3", False, 1, None, 2, 2.5, 2, 0) ] for course in courses_list: course.save() return courses_list
def generate_data(apps, schema_editor): from homepage.models import Course from homepage.models import Prerequisites test_data_course = [ (10231, 'UnFogging the Future', True, 4, 'Currently Unavailable', 3.25, 1.5, 12, 12), (10221, 'Grammatica in Arithmancy', False, 3, 'Currently Unavailable', 4.25, 4.5, 10, 9), (10111, 'Resonance in Runes and Signs', True, 3, 'Currently Unavailable', 2.25, 2.0, 13, 13), (12357, 'Numerology', False, 5, 'Currently Unavailable', 3.5, 2.5, 7, 3), ] courses = [Course(*tdc) for tdc in test_data_course] test_data_prerequisites = [ (courses[3], courses[0], 1), (courses[2], courses[1], 0), ] with transaction.atomic(): for course in courses: course.save() for preq in test_data_prerequisites: Prerequisites(course_id=preq[0], req_course_id=preq[1], req_code=preq[2]).save()
def generate_data(apps, schema_editor): from homepage.models import Course from homepage.models import Prerequisites test_data_course = [ (10340, 'No Return - through the Lense', True, 4, None), (10341, 'Open Source 101', False, 3, "https://www.github.com", 4.25, 4.5, 10, 9), (10342, 'Normalized Spatial Schemes', True, 3, None, 3, 5, 1, 0), (12343, 'Easier than Zoology', False, 5, None, 3.5, 2.5, 7, 3), ] courses = [Course(*tdc) for tdc in test_data_course] test_data_prerequisites = [ (courses[3], courses[0], 1), (courses[2], courses[1], 0), ] with transaction.atomic(): for course in courses: course.save() for preq in test_data_prerequisites: Prerequisites(course_id=preq[0], req_course_id=preq[1], req_code=preq[2]).save()
def test_course_validation_invalids(invalid_courses): flag = False try: Course(*invalid_courses).full_clean() except ValidationError: flag = True assert flag
def test_create_multiple_courses(): details = [(1, "Linear Algebra 1", True, 4, "please contribute", 3.5, 4, 13, 7), (2, "Project Management", False, 3, "please contribute", 1.5, 3.5, 15, 3)] for args in details: Course(*args).save() # make sure that multiple courses are saved accurately courses = [Course.objects.get(pk=arg[0]).get_details() for arg in details] assert courses == details
def test_course_validation_valids(valid_courses): flag = True # check that valid input doesn't raise exception try: Course(*valid_courses).clean_fields() except ValidationError: flag = False assert flag
def test_course_print_details(capsys): course = (1, "Linear Algebra 1", True, 4, None, 3.500, 4.000, 13, 7) Course(*course).save() msg = ( "------------------------------------------------------------\n" "Course indentifier: 1 \nName: Linear Algebra 1\nMandatory? yes\n" "Credit Points: 4\nSyllabi: N/A\n" "Average Rating: 4.000 \tAverage Load: 3.500\t" "13 Raters\nNumber Of Reviews: 7\n" ) # make sure that message comes out as expected Course.objects.get(pk=1).print_details() assert capsys.readouterr().out == msg
def test_course_save_course(valid_courses): course = Course(*valid_courses) course.save() # check that it's the same object db_course = Course.objects.get(pk=course.course_id) assert db_course == course
def test_course_get_details(): course = (1, "Linear Algebra 1", True, 4, "please contribute", 3.500, 4.000, 13, 7) Course(*course).save() # make sure details are saved accurately assert Course.objects.get(pk=course[0]).get_details() == course
def test_invalid_course_creation(invalid_courses): course = Course(*invalid_courses) course.save() assert Course.objects.filter(pk=course.course_id).count() == 0
def courses(self): course0 = Course(course_id=100231, name='course0', mandatory=True, credit_points=1) course0.save() course1 = Course(course_id=100400, name='course1', mandatory=True, credit_points=1) course1.save() return (course0, course1)