Ejemplo n.º 1
0
def test_course_success(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    create_course(flask_client, [str(id1), str(id2)])
Ejemplo n.º 2
0
    def setup(cls):
        cls.course1 = conftest.create_course(1)
        cls.course2 = conftest.create_course(2)
        cls.course_no_submissions = conftest.create_course(3)
        cls.course_no_exercises = conftest.create_course(4)

        cls.ex1_1 = conftest.create_exercise(cls.course1, 1, 1)
        cls.ex1_2 = conftest.create_exercise(cls.course1, 2, 2)
        cls.ex2_1 = conftest.create_exercise(cls.course2, 1, 3)
        cls.ex3_1 = conftest.create_exercise(cls.course_no_submissions, 1, 4)

        cls.user1 = conftest.create_user(index=1)
        cls.user2 = conftest.create_user(index=2)

        conftest.create_usercourse(cls.user1, cls.course1)
        conftest.create_usercourse(cls.user1, cls.course2)
        conftest.create_usercourse(cls.user2, cls.course1)

        solution = conftest.create_solution

        cls.s1 = solution(cls.ex1_1, cls.user1)
        cls.s2 = solution(cls.ex1_1, cls.user1, code='Other submission')
        cls.s3 = solution(cls.ex1_1, cls.user2)
        cls.s4 = solution(cls.ex1_2, cls.user1)

        cls.s5 = solution(cls.ex2_1, cls.user1)
Ejemplo n.º 3
0
    def test_courses_exercises(
        course: Course,
        student_user: User,
        captured_templates,
    ):
        course2 = conftest.create_course(index=1)
        conftest.create_usercourse(student_user, course)
        conftest.create_exercise(course2, 1)
        conftest.create_exercise(course2, 2)
        assert len(
            list(Exercise.get_objects(student_user.id,
                                      from_all_courses=True), )) == 0

        client = conftest.get_logged_user(username=student_user.username)
        client.get(f'course/{course.id}')
        template, _ = captured_templates[-1]
        assert template.name == 'exercises.html'
        conftest.create_exercise(course, 1, index=1)
        assert len(list(Exercise.get_objects(student_user.id))) == 1

        unregistered_response = client.get(f'course/{course2.id}')
        assert unregistered_response.status_code == 403

        fail_response = client.get('course/123456')
        assert fail_response.status_code == 404

        conftest.create_usercourse(student_user, course2)
        client.get(f'course/{course2.id}')
        template, _ = captured_templates[-1]
        assert template.name == 'exercises.html'
        assert len(list(Exercise.get_objects(student_user.id))) == 2
Ejemplo n.º 4
0
    def test_usercourse_on_save(student_user: User, course: Course):
        course2 = conftest.create_course(index=1)
        usercourse = conftest.create_usercourse(student_user, course)
        assert student_user.last_course_viewed == course

        conftest.create_usercourse(student_user, course2)
        assert student_user.last_course_viewed == course

        usercourse.delete_instance()
        assert student_user.last_course_viewed == course2
Ejemplo n.º 5
0
def test_add_grade(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    course_id = create_course(flask_client, [str(id1), str(id2)])
    res = create_grade(flask_client, 70, course_id, id1)
    assert res._status_code == status.HTTP_201_CREATED
    res = create_grade(flask_client, 80, course_id, '44')
    assert res._status_code == status.HTTP_400_BAD_REQUEST
Ejemplo n.º 6
0
def test_easy_course(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    course_id1 = create_course(flask_client, [str(id1), str(id2)])
    course_id2 = create_course(flask_client, [str(id1), str(id2)],
                               name='history')
    create_grade(flask_client, 70, course_id1, id1)
    create_grade(flask_client, 77, course_id1, id2)
    create_grade(flask_client, 70, course_id2, id1)
    create_grade(flask_client, 76, course_id2, id2)
    res = flask_client.get(
        f'/easy_course',
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_200_OK
    result = res.data.decode()
    course_name = json.loads(result)['name']
    assert course_name == 'history'
Ejemplo n.º 7
0
def test_course_update(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    course_id = create_course(flask_client, [str(id1), str(id2)])
    res = flask_client.put(
        f'/course/{course_id}',
        json=dict(name='history', students=','.join([str(id1)])),
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_200_OK
Ejemplo n.º 8
0
def test_best_student(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    course_id = create_course(flask_client, [str(id1), str(id2)])
    create_grade(flask_client, 70, course_id, id1)
    create_grade(flask_client, 77, course_id, id2)
    res = flask_client.get(
        f'/best_student',
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_200_OK
Ejemplo n.º 9
0
def test_update_grade(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    course_id = create_course(flask_client, [str(id1), str(id2)])
    res = create_grade(flask_client, 70, course_id, id1)
    assert res._status_code == status.HTTP_201_CREATED
    res = flask_client.put(
        '/grade',
        json=dict(grade=60, student=str(id1), course=course_id),
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_200_OK
Ejemplo n.º 10
0
    def test_upload_another_course(
        self,
        course: Course,
        student_user: User,
    ):
        course2 = conftest.create_course(index=1)
        conftest.create_exercise(course2, 1)
        conftest.create_usercourse(student_user, course)

        client = conftest.get_logged_user(username=student_user.username)
        fail_upload_response = client.post(f'/upload/{course2.id}',
                                           data={
                                               'file':
                                               self.pyfile_different_course,
                                           })
        assert fail_upload_response.status_code == 400
Ejemplo n.º 11
0
def test_course_get_delete(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    course_id = create_course(flask_client, [str(id1), str(id2)])
    res = flask_client.get(
        f'/course/{course_id}',
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_200_OK
    res = flask_client.delete(
        f'/course/{course_id}',
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_204_NO_CONTENT
Ejemplo n.º 12
0
    def test_send_page(
        student_user: User,
        course: Course,
        exercise: Exercise,
    ):
        course2 = conftest.create_course(2)
        exercise2 = conftest.create_exercise(course2, 1)
        conftest.create_usercourse(student_user, course)
        client = conftest.get_logged_user(student_user.username)
        success_send_response = client.get(f'send/{course.id}')
        assert success_send_response.status_code == 200

        success_send_response2 = client.get(f'send/{course.id}/{exercise.id}')
        assert success_send_response2.status_code == 200

        fail_send_response = client.get(f'send/{course2.id}')
        assert fail_send_response.status_code == 403

        fail_send_response = client.get(f'send/{course2.id}/{exercise2.id}')
        assert fail_send_response.status_code == 403
Ejemplo n.º 13
0
    def test_user_registered_to_course(student_user: User, course: Course):
        conftest.create_usercourse(student_user, course)
        assert course.has_user(student_user)

        course2 = conftest.create_course(index=1)
        assert not course2.has_user(student_user)