def signin(browser, student, new=False):
    email = student.student.email

    browser.get("{}{}".format(browser.server_url, reverse("login")))

    login_link = browser.find_element_by_link_text("LOGIN")
    login_link.click()

    input_ = browser.find_element_by_name("email")
    input_.clear()
    input_.send_keys(email)
    input_.send_keys(Keys.ENTER)

    username, _ = get_student_username_and_password(email)
    token = create_student_token(username, email)

    signin_link = "{}{}?token={}".format(browser.server_url,
                                         reverse("student-page"), token)

    browser.get(signin_link)

    if new:
        assert re.search(
            r"/(\w{2})/tos/tos/student/\?next=/\1/student/",
            browser.current_url,
        )
    else:
        assert re.search(r"/en/student/\?token=", browser.current_url)
Example #2
0
def test_index_student_not_logged_in_token(client, student):
    token = create_student_token(student.student.username,
                                 student.student.email)

    resp = client.get(reverse("student-page") + "?token={}".format(token))
    assert resp.status_code == 200
    assert any(t.name == "peerinst/student/index.html" for t in resp.templates)
    assert student.student.email in resp.content
Example #3
0
def test_index_student_logged_in_token_different_user(client, students):
    assert login_student(client, students[0])

    token = create_student_token(students[1].student.username,
                                 students[1].student.email)

    resp = client.get(reverse("student-page") + "?token={}".format(token))
    assert resp.status_code == 200
    assert any(t.name == "peerinst/student/index.html" for t in resp.templates)
    assert students[1].student.email in resp.content.decode()
    assert not students[0].student.email in resp.content.decode()
Example #4
0
def test_index_new_student(client, student):
    student.student.is_active = False
    student.student.save()

    token = create_student_token(student.student.username,
                                 student.student.email)

    assert not Student.objects.get(student=student.student).student.is_active

    resp = client.get(reverse("student-page") + "?token={}".format(token))
    assert resp.status_code == 200
    assert any(t.name == "peerinst/student/index.html" for t in resp.templates)
    assert student.student.email in resp.content
    assert Student.objects.get(student=student.student).student.is_active
def test_fake_link(browser):
    email = "*****@*****.**"
    username, _ = get_student_username_and_password(email)
    token = create_student_token(username, email)

    signin_link = "{}{}?token={}".format(browser.server_url,
                                         reverse("student-page"), token)

    browser.get(signin_link)

    assert re.search(r"student/", browser.current_url)

    err = ("There is no user corresponding to the given link. "
           "You may try asking for another one.")
    browser.find_element_by_xpath("//*[contains(text(), '{}')]".format(err))
Example #6
0
def test_add_assignment(student, group_assignment):
    student.join_group(group_assignment.group)

    StudentAssignment.objects.filter(
        student=student, group_assignment=group_assignment
    ).delete()
    StudentNotification.objects.filter(
        student=student, notification__type="new_assignment"
    ).delete()

    student.add_assignment(group_assignment)

    assert StudentAssignment.objects.filter(
        student=student, group_assignment=group_assignment
    ).exists()
    assert StudentNotification.objects.filter(
        student=student, notification__type="new_assignment"
    ).exists()
    assert (
        StudentNotification.objects.get(
            student=student, notification__type="new_assignment"
        ).link.split("/")[-1]
        == reverse(
            "live",
            kwargs={
                "assignment_hash": group_assignment.hash,
                "token": create_student_token(
                    student.student.username, student.student.email
                ),
            },
        ).split("/")[-1]
    )

    assert len(mail.outbox) == 1

    assert mail.outbox[0].subject == "New assignment for group {}".format(
        group_assignment.group.title
    )
Example #7
0
def test_add_assignment__assignment_exists(student, group_assignment):
    group_assignment.distribute()
    student.join_group(group_assignment.group)

    assert StudentAssignment.objects.filter(
        student=student, group_assignment=group_assignment
    ).exists()
    assert StudentNotification.objects.filter(
        student=student, notification__type="new_assignment"
    ).exists()

    student.add_assignment(group_assignment)

    assert (
        StudentAssignment.objects.filter(
            student=student, group_assignment=group_assignment
        ).count()
        == 1
    )
    assert StudentNotification.objects.filter(
        student=student, notification__type="new_assignment"
    ).exists()
    assert (
        StudentNotification.objects.get(
            student=student, notification__type="new_assignment"
        ).link.split("/")[-1]
        == reverse(
            "live",
            kwargs={
                "assignment_hash": group_assignment.hash,
                "token": create_student_token(
                    student.student.username, student.student.email
                ),
            },
        ).split("/")[-1]
    )