def test_can_count_like_others():
    comment = utils.comment.lazy_add_comment()
    course = Course(comment.problem.course)
    task = utils.task.lazy_add(course=course)
    req = requirement.LikeOthersComment.add(
        task=task,
        required_number=1,
    )
    liker = utils.user.Factory.student()
    course.add_student(liker)
    comment.like(user=liker)
    assert req.reload().is_completed(liker)
def test_progress():
    comment = utils.comment.lazy_add_comment()
    course = Course(comment.problem.course)
    task = utils.task.lazy_add(course=course)
    req = requirement.LikeOthersComment.add(
        task=task,
        required_number=1,
    )
    liker = utils.user.Factory.student()
    course.add_student(liker)
    assert req.progress(liker) == (0, 1)
    comment.like(user=liker)
    assert req.reload().progress(liker) == (1, 1)
Beispiel #3
0
def test_edit_task(forge_client: Callable[[str], FlaskClient]):
    now = datetime.now()
    reply = utils.comment.lazy_add_reply()
    course = Course(reply.problem.course)
    task = utils.task.lazy_add(
        course=course,
        starts_at=now - timedelta(days=1),
        ends_at=now,
    )
    user = reply.author
    client = forge_client(task.course.teacher.username)

    req = requirement.ReplyToComment.add(
        task=task,
        required_number=1,
    )
    assert req.progress(user) == (0, 1)

    data = {
        'title': 'My task',
        'content': 'haha',
        'startsAt': (now - timedelta(days=2)).isoformat(),
        'endsAt': (now + timedelta(days=1)).isoformat(),
    }
    rv = client.put(
        f'/task/{task.id}',
        json=data,
    )
    assert rv.status_code == 200, rv.get_json()
    rv = client.get(f'/task/{task.id}')
    assert rv.status_code == 200, rv.get_json()
    for key in ('title', 'content'):
        assert data[key] == rv.get_json()['data'][key]
    assert req.reload().progress(user) == (1, 1)
Beispiel #4
0
def test_leave_comment_requirement(
    forge_client: Callable[[str], FlaskClient],
    config_app,
):
    config_app(env='test')
    client = forge_client('teacher1')
    course = Course.get_by_name('course_108-1')
    cid = course.pk
    tid = str(utils.task.lazy_add(course=cid).id)
    pid = int(
        utils.problem.lazy_add(
            course=course,
            allow_multiple_comments=True,
        ).id)
    rv = client.post(
        f'/task/{tid}/leave-comment',
        json={'problem': pid},
    )
    assert rv.status_code == 200, rv.get_json()

    rv = client.get(f'/task/{tid}')
    rid = rv.get_json()['data']['requirements'][0]
    assert rv.status_code == 200, rv.get_json()
    assert rv.get_json()['data']['course'] == str(cid)

    rv = client.get(f'/requirement/{rid}')
    assert rv.status_code == 200, rv.get_json()
    assert rv.get_json()['data']['task'] == str(tid)
def test_wont_count_like_self():
    comment = utils.comment.lazy_add_comment()
    course = Course(comment.problem.course)
    task = utils.task.lazy_add(course=course)
    req = requirement.LikeOthersComment.add(
        task=task,
        required_number=1,
    )
    comment.like(user=comment.author)
    assert not req.reload().is_completed(comment.author)
Beispiel #6
0
def test_progress():
    task = utils.task.lazy_add()
    user = utils.user.Factory.student()
    course = Course(task.course)
    course.add_student(user)
    assert task.progress(user) == (0, 0)
    problem = utils.problem.lazy_add(
        course=course,
        is_oj=True,
    )
    # Reload to ensure that course data is up to date
    task.reload('course')
    requirement.SolveOJProblem.add(
        task=task,
        problems=[problem],
    )
    assert task.reload().progress(user) == (0, 1)
    submission = utils.submission.lazy_add_new(user=user, problem=problem)
    submission.complete(judge_result=submission.engine.JudgeResult.AC)
    assert task.reload().progress(user) == (1, 1)
Beispiel #7
0
def test_get_course_task(
    forge_client: Callable[[str], FlaskClient],
    config_app,
):
    config_app(env='test')
    client = forge_client('teacher1')
    cid = Course.get_by_name('course_108-1').pk
    tid = str(utils.task.lazy_add(course=cid).id)
    rv = client.get(f'/course/{cid}/tasks')
    assert rv.status_code == 200, rv.get_json()
    assert tid in rv.get_json()['data']
Beispiel #8
0
def test_sync():
    reply = utils.comment.lazy_add_reply()
    course = Course(reply.problem.course)
    task = utils.task.lazy_add(course=course)
    req = requirement.ReplyToComment.add(
        task=task,
        required_number=1,
    )
    user = reply.author
    assert req.progress(user) == (0, 1)
    req.sync(users=[user])
    assert req.reload().progress(user) == (1, 1)
Beispiel #9
0
def test_extend_task_due_can_update_requirement():
    now = datetime.now()
    reply = utils.comment.lazy_add_reply()
    course = Course(reply.problem.course)
    task = utils.task.lazy_add(course=course, ends_at=now)
    req = requirement.ReplyToComment.add(
        task=task,
        required_number=1,
    )
    user = reply.author
    assert req.progress(user) == (0, 1)
    task.update(ends_at=now + timedelta(days=1))
    assert req.reload().progress(user) == (1, 1)
def test_sync():
    comment = utils.comment.lazy_add_comment()
    course = Course(comment.problem.course)
    user = utils.course.student(course=course)
    comment.like(user=user)
    user.reload()
    task = utils.task.lazy_add(course=course)
    req = requirement.LikeOthersComment.add(
        task=task,
        required_number=1,
    )
    assert req.progress(user) == (0, 1)
    req.sync(users=[user])
    assert req.reload().progress(user) == (1, 1)
def test_progress():
    task = utils.task.lazy_add()
    problem = utils.problem.lazy_add(is_oj=False, course=task.course)
    task.reload('course')
    req = requirement.LeaveComment.add(
        task=task,
        problem=problem,
    )
    user = utils.user.Factory.student()
    Course(problem.course).add_student(user)
    assert req.progress(user) == (0, 1)
    utils.comment.lazy_add_comment(
        problem=problem,
        author=user,
    )
    assert req.reload().progress(user) == (1, 1)
Beispiel #12
0
def test_delete_task(forge_client: Callable[[str], FlaskClient]):
    reply = utils.comment.lazy_add_reply()
    course = Course(reply.problem.course)
    task = utils.task.lazy_add(course=course)
    client = forge_client(task.course.teacher.username)
    req = requirement.ReplyToComment.add(
        task=task,
        required_number=1,
    )

    rv = client.delete(f'/task/{task.id}')
    assert rv.status_code == 200, rv.get_json()
    rv = client.get(f'/task/{task.id}')
    assert rv.status_code == 404, rv.get_json()
    rv = client.get(f'/requirement/{req.id}')
    assert rv.status_code == 404, rv.get_json()
def test_extend_task_due_can_update_requirement():
    # Create a comment and like it
    now = datetime.now()
    comment = utils.comment.lazy_add_comment()
    course = Course(comment.problem.course)
    user = utils.course.student(course=course)
    comment.like(user=user)
    user.reload()
    # Create a task ends immediately
    task = utils.task.lazy_add(course=course, ends_at=now)
    req = requirement.LikeOthersComment.add(
        task=task,
        required_number=1,
    )
    assert req.progress(user) == (0, 1)
    task.update(ends_at=now + timedelta(days=1))
    assert req.reload().progress(user) == (1, 1)
Beispiel #14
0
def test_progress():
    problem = utils.problem.lazy_add()
    task = utils.task.lazy_add(course=problem.course)
    req = requirement.ReplyToComment.add(
        task=task,
        required_number=1,
    )
    user = utils.user.Factory.student()
    Course(problem.course).add_student(user)
    assert req.progress(user) == (0, 1)
    comment = utils.comment.lazy_add_comment(
        problem=problem,
        author=user,
    )
    utils.comment.lazy_add_reply(
        author=user,
        comment=comment,
    )
    assert req.reload().progress(user) == (1, 1)
Beispiel #15
0
def test_can_count_reply(required_number: int):
    problem = utils.problem.lazy_add()
    task = utils.task.lazy_add(course=problem.course)
    req = requirement.ReplyToComment.add(
        task=task,
        required_number=required_number,
    )
    user = utils.user.Factory.student()
    Course(problem.course).add_student(user)
    comment = utils.comment.lazy_add_comment(
        problem=problem,
        author=user,
    )
    for _ in range(required_number):
        assert not req.reload().is_completed(user)
        utils.comment.lazy_add_reply(
            comment=comment,
            author=user,
        )
    assert req.reload().is_completed(user)
def test_can_count_comment():
    task = utils.task.lazy_add()
    problem = utils.problem.lazy_add(is_oj=False, course=task.course)
    task.reload('course')
    req = requirement.LeaveComment.add(
        task=task,
        problem=problem,
    )
    user = utils.user.Factory.student()
    Course(problem.course).add_student(user)
    assert not req.is_completed(user)
    # Add unrelated comment won't affect task
    utils.comment.lazy_add_comment()
    assert not req.reload().is_completed(user)
    # And reply, neither
    utils.comment.lazy_add_reply()
    assert not req.reload().is_completed(user)
    utils.comment.lazy_add_comment(
        problem=problem,
        author=user,
    )
    assert req.reload().is_completed(user)
Beispiel #17
0
def test_reply_to_comment_requirement(
    forge_client: Callable[[str], FlaskClient],
    config_app,
):
    config_app(env='test')
    client = forge_client('teacher1')
    cid = Course.get_by_name('course_108-1').pk
    tid = str(utils.task.lazy_add(course=cid).id)
    rv = client.post(
        f'/task/{tid}/reply-to-comment',
        json={'requiredNumber': 3},
    )
    assert rv.status_code == 200, rv.get_json()

    rv = client.get(f'/task/{tid}')
    rid = rv.get_json()['data']['requirements'][0]
    assert rv.status_code == 200, rv.get_json()
    assert rv.get_json()['data']['course'] == str(cid)

    rv = client.get(f'/requirement/{rid}')
    assert rv.status_code == 200, rv.get_json()
    assert rv.get_json()['data']['task'] == str(tid)
Beispiel #18
0
def test_add_task(forge_client: Callable[[str], FlaskClient], config_app):
    config_app(env='test')
    client = forge_client('teacher1')
    cid = Course.get_by_name('course_108-1').pk
    rv = client.post(
        '/task',
        json={
            'course': cid,
            'title': 'My task',
        },
    )
    assert rv.status_code == 200, rv.get_json()
    tid = rv.get_json()['data']['id']
    assert Task(tid).course.id == cid

    rv = client.get(f'/task/{tid}')
    assert rv.status_code == 200, rv.get_json()
    for key in ('id', 'endsAt', 'startsAt'):
        assert key in rv.get_json()['data']
    # The timestamps should be ISO string
    for key in ('endsAt', 'startsAt'):
        assert isinstance(rv.get_json()['data'][key], str)