コード例 #1
0
def test_read_lab_time_correctness_nolab():
    """Test if read_lab_time() returns the right content if the course has no lab."""
    file_obj = check_file_open('tests/test_lab.json')
    each_course = file_obj['Test Data']['CourseData']['ACCT'][2]
    temp_course = course.Course()
    temp_course = read_lab_time(each_course, temp_course)
    assert len(temp_course.lab) == 0
コード例 #2
0
def test_insert_data_correctness():
    """Test if insert_data() returns the right content."""
    course_raw_data = check_file_open('tests/test.json')
    course_list, department_list, enrollment_dict = from_raw_to_list(
        course_raw_data, 'Test Data')
    insert_data(course_list, department_list, enrollment_dict, 'Test Data')
    db = get_db()
    assert (db['Test Data courses'].find_one({'crn': '32072'})) is not None
    assert (db['Test Data courses'].find_one({'crn': '35071'})) is not None
    assert (db['Test Data courses'].find_one({'crn': '31138'})) is not None
    assert (db['Test Data courses'].find_one({'crn': '00053'})) is not None
    assert (db['Test Data courses'].find_one({'crn': '00054'})) is not None
    assert (db['Test Data courses'].find_one({'crn': '35528'})) is not None
    assert (db['Test Data departments'].find_one({'deptName':
                                                  'ACCT'})) is not None
    assert (db['Test Data departments'].find_one({'deptName':
                                                  'ADMJ'})) is not None
    assert len(db['Test Data departments'].find_one({'deptName':
                                                     'ACCT'})['courses']) == 3
    assert len(db['Test Data departments'].find_one({'deptName':
                                                     'ADMJ'})['courses']) == 3
    assert (db['Test Data seats'].find_one({'UID': '32072'})) is not None
    assert (db['Test Data seats'].find_one({'UID': '35071'})) is not None
    assert (db['Test Data seats'].find_one({'UID': '31138'})) is not None
    assert (db['Test Data seats'].find_one({'UID': '00053'})) is not None
    assert (db['Test Data seats'].find_one({'UID': '00054'})) is not None
    assert (db['Test Data seats'].find_one({'UID': '35528'})) is not None
コード例 #3
0
def test_read_lab_time_correctness_lab():
    """Test if read_lab_time() returns the right content if the course has a lab."""
    file_obj = check_file_open('tests/test_lab.json')
    each_courses = file_obj['Test Data']['CourseData']['ACCT']
    for i in range(len(each_courses)):
        each_course = each_courses[i]
        temp_course = course.Course()
        temp_course = read_lab_time(each_course, temp_course)
        assert temp_course == target_output.labs[i]
コード例 #4
0
def test_from_raw_to_list_correctness():
    """Test if from_raw_to_list() returns the right content."""
    course_raw = check_file_open('tests/test.json')
    index = 0
    quarter_name = 'Test Data'
    course_list, department_list, enrollment_dict = from_raw_to_list(course_raw, quarter_name)
    assert len(course_list) == 6
    assert len(department_list) == 2
    for i in range(len(course_list)):
        assert course_list[i] == target_output.courseList[i]
    for i in range(len(department_list)):
        for j in range(3):
            assert department_list[i].courses[j] == target_output.departmentList[i].courses[j]
    for key in enrollment_dict.keys():
        assert enrollment_dict[key] == target_output.seats[index]
        index += 1
コード例 #5
0
def test_multi_upload_correctness():
    """Test if insert_data() returns the right content."""
    course_raw_data = check_file_open('tests/test.json')
    course_list, department_list, enrollment_dict = from_raw_to_list(
        course_raw_data, 'Test Data')
    insert_data(course_list, department_list, enrollment_dict, 'Test Data')

    ##change time stamp
    course_raw_data['Test Data']['FetchTime'] = 1620939965
    course_list, department_list, enrollment_dict = from_raw_to_list(
        course_raw_data, 'Test Data')
    insert_data(course_list, department_list, enrollment_dict, 'Test Data')
    db = get_db()

    seat = db['Test Data seats'].find_one({'UID': '32072'})
    del seat['_id']
    assert seat == target_output.secondTimeSeats[0]

    seat = db['Test Data seats'].find_one({'UID': '35071'})
    del seat['_id']
    assert seat == target_output.secondTimeSeats[1]

    seat = db['Test Data seats'].find_one({'UID': '31138'})
    del seat['_id']
    assert seat == target_output.secondTimeSeats[2]

    seat = db['Test Data seats'].find_one({'UID': '00053'})
    del seat['_id']
    assert seat == target_output.secondTimeSeats[3]

    seat = db['Test Data seats'].find_one({'UID': '00054'})
    del seat['_id']
    assert seat == target_output.secondTimeSeats[4]

    seat = db['Test Data seats'].find_one({'UID': '35528'})
    del seat['_id']
    assert seat == target_output.secondTimeSeats[5]

    db['Test Data courses'].drop()
    db['Test Data departments'].drop()
    db['Test Data seats'].drop()
コード例 #6
0
def test_read_course_proto_correctness():
    """Test if read_course_proto() returns the right content with/without lab."""
    course_raw_data = check_file_open('tests/test.json')
    json_obj = course_raw_data['Test Data']
    course_list = []
    enrollment_dict = {}
    index = 0
    department_name = 'ACCT'
    each_department = read_course_proto(json_obj, course_list, department_name,
                                        enrollment_dict)
    assert each_department.deptName == 'ACCT'
    assert len(each_department.courses) == 3
    assert len(course_list) == 3
    for i in range(len(each_department.courses)):
        assert each_department.courses[
            i] == target_output.department_acct.courses[i]
    for i in range(len(course_list)):
        assert course_list[i] == target_output.courseList[i]
    for key in enrollment_dict.keys():
        assert enrollment_dict[key] == target_output.seats[index]
        index += 1

    course_list = []
    department_name = 'ADMJ'
    enrollment_dict = {}
    each_department = read_course_proto(json_obj, course_list, department_name,
                                        enrollment_dict)
    assert each_department.deptName == 'ADMJ'
    assert len(each_department.courses) == 3
    assert len(course_list) == 3
    for i in range(len(each_department.courses)):
        assert each_department.courses[
            i] == target_output.department_admj.courses[i]
    for i in range(len(course_list)):
        assert course_list[i] == target_output.courseList[i + 3]
    for key in enrollment_dict.keys():
        assert enrollment_dict[key] == target_output.seats[index]
        index += 1
コード例 #7
0
def test_check_file_open_not_exist():
    """Test if check_file_open() handles correctly with a nonexistent file."""
    with pytest.raises(FileNotFoundError):
        result = check_file_open('tests/nonexistent.json')
コード例 #8
0
def test_check_file_open_existence_and_correctness():
    """Test if check_file_open() return the correct type and the returned dict has the right content."""
    result = check_file_open('tests/test.json')
    assert isinstance(result, dict)
    assert result
コード例 #9
0
def test_from_raw_to_list_with_invalid_file():
    """Test if from_raw_to_list() throws the right exception if the json file is invalid."""
    with pytest.raises(FileNotFoundError):
        course_raw = check_file_open('tests/nonexistent.json')
        quarter_name = 'Test Data'
        course_list, department_list, enrollment_dict = from_raw_to_list(course_raw, quarter_name)
コード例 #10
0
def test_from_raw_to_list_with_invalid_quarter_name():
    """Test if from_raw_to_list() throws the right exception if the quarter name is invalid."""
    with pytest.raises(KeyError):
        course_raw = check_file_open('tests/test.json')
        quarter_name = 'Invalid quarter name'
        course_list, department_list, enrollment_dict = from_raw_to_list(course_raw, quarter_name)