def test_login_invalid_email(user, client):
    resp = client.post("/login", data={
        "email": "*****@*****.**",
        "password": "******"
    });

    assert_api_error(resp, 403, meta={ "email": "*****@*****.**" })
def test_login_invalid_password(user, client):
    resp = client.post("/login", data={
        "email": user.email,
        "password": "******"
    });

    assert_api_error(resp, 403, "Invalid credentials")
def test_paper_get_invalid_paper(auth_client, course_with_papers):
    course = course_with_papers
    paper = course.papers[0]
    resp = auth_client.get("/course/{code}/paper/{year}/{period}".format(
        code=course.code, year=2020, period=paper.period.lower()))

    assert_api_error(resp, 404, message="Paper not found.")
def test_create_missing_param(client):
    """POST /user with missing parameter"""
    resp = client.post("/user", data={
        "name": USER_NAME,
        "email": USER_EMAIL
    })

    assert_api_error(resp, 422, meta={ "field": "password" })
def test_paper_get_invalid_period(auth_client):
    resp = auth_client.get("/course/{code}/paper/{year}/{period}".format(
        code="CT360", 
        year="2014",
        period="non-period"
    ))

    assert_api_error(resp, 422, meta={"field": "period"})
def test_create_unknown_institution(client):
    """POST /user { name, email, password }"""
    resp = client.post("/user", data={
        "name": USER_NAME,
        "email": "*****@*****.**",
        "password": USER_PASSWORD
    })

    assert_api_error(resp, 422, "Institution with domain 'gmail.com'")
def test_auth_check_expired_key(auth_client, user, session):
    currentSession = user.sessions[0]
    currentSession.active = False

    session.add(currentSession)
    session.commit()

    resp = auth_client.get("/auth")
    assert_api_error(resp, 401, "Unauthorized")
def test_create_used_email(user, client):
    """POST /user with used email."""
    resp = client.post("/user", data={
        "name": USER_NAME,
        "email": USER_EMAIL,
        "password": USER_PASSWORD
    })

    assert_api_error(resp, 409)
Example #9
0
def test_create_unknown_institution(client):
    """POST /user { name, email, password }"""
    resp = client.post("/user",
                       data={
                           "name": USER_NAME,
                           "email": "*****@*****.**",
                           "password": USER_PASSWORD
                       })

    assert_api_error(resp, 422, "Institution with domain 'gmail.com'")
def test_paper_get_invalid_paper(auth_client, course_with_papers):
    course = course_with_papers
    paper = course.papers[0]
    resp = auth_client.get("/course/{code}/paper/{year}/{period}".format(
        code=course.code, 
        year=2020,
        period=paper.period.lower()
    ))

    assert_api_error(resp, 404, message="Paper not found.")
Example #11
0
def test_create_used_email(user, client):
    """POST /user with used email."""
    resp = client.post("/user",
                       data={
                           "name": USER_NAME,
                           "email": USER_EMAIL,
                           "password": USER_PASSWORD
                       })

    assert_api_error(resp, 409)
def test_comment_update_not_owner(users, second_auth_client, session, questions):
    author = users[0]
    non_author = users[1]
    entity = questions[0]

    comment = author.comment(entity, "Hello world!")
    session.add(comment)
    session.flush()

    resp = second_auth_client.delete("/comment/%d/%d" % (entity.id, comment.id))

    assert_api_error(resp, 401)
def test_question_delete_parent(auth_client, paper_with_course_and_questions, session):
    paper = paper_with_course_and_questions
    question = paper.questions[0]

    resp = auth_client.delete("/course/{code}/paper/{year}/{period}/q/{question}".format(
        code=paper.course.code.lower(), 
        year=paper.year_start,
        period=paper.period.lower(),
        question=".".join(map(str, question.path))
    ))

    assert_api_error(resp, 403) 
Example #14
0
def test_question_delete_parent(auth_client, paper_with_course_and_questions,
                                session):
    paper = paper_with_course_and_questions
    question = paper.questions[0]

    resp = auth_client.delete(
        "/course/{code}/paper/{year}/{period}/q/{question}".format(
            code=paper.course.code.lower(),
            year=paper.year_start,
            period=paper.period.lower(),
            question=".".join(map(str, question.path))))

    assert_api_error(resp, 403)
def test_question_create_error_without_index(auth_client, session, course_with_papers):
    course = course_with_papers
    paper = course.papers[0]

    resp = auth_client.post("/course/{code}/paper/{year}/{period}/q/".format(
        code=paper.course.code.lower(), 
        year=paper.year_start,
        period=paper.period.lower()
    ), data={
        "index_type": "alpha",
        "content": "Hello world"
    })

    assert_api_error(resp, 422)
Example #16
0
def test_comment_update_not_owner(users, second_auth_client, session,
                                  questions):
    author = users[0]
    non_author = users[1]
    entity = questions[0]

    comment = author.comment(entity, "Hello world!")
    session.add(comment)
    session.flush()

    resp = second_auth_client.delete("/comment/%d/%d" %
                                     (entity.id, comment.id))

    assert_api_error(resp, 401)
Example #17
0
def test_question_create_error_without_index(auth_client, session,
                                             course_with_papers):
    course = course_with_papers
    paper = course.papers[0]

    resp = auth_client.post("/course/{code}/paper/{year}/{period}/q/".format(
        code=paper.course.code.lower(),
        year=paper.year_start,
        period=paper.period.lower()),
                            data={
                                "index_type": "alpha",
                                "content": "Hello world"
                            })

    assert_api_error(resp, 422)
def test_question_create_as_child_error_path_exists(auth_client, session, paper_with_course_and_questions):
    paper = paper_with_course_and_questions
    course = paper.course
    question = paper.questions[0]

    resp = auth_client.post("/course/{code}/paper/{year}/{period}/q/{question}".format(
        code=paper.course.code.lower(), 
        year=paper.year_start,
        period=paper.period.lower(),
        question=".".join(map(str, question.path))
    ), data={
        "index": 1,
        "index_type": "alpha",
        "content": "Hello world"
    })

    assert_api_error(resp, 409)
Example #19
0
def test_question_create_as_child_error_path_exists(
        auth_client, session, paper_with_course_and_questions):
    paper = paper_with_course_and_questions
    course = paper.course
    question = paper.questions[0]

    resp = auth_client.post(
        "/course/{code}/paper/{year}/{period}/q/{question}".format(
            code=paper.course.code.lower(),
            year=paper.year_start,
            period=paper.period.lower(),
            question=".".join(map(str, question.path))),
        data={
            "index": 1,
            "index_type": "alpha",
            "content": "Hello world"
        })

    assert_api_error(resp, 409)
def test_institution_search_no_institutions(client):
    resp = client.get("/institution/search?domain=foo.com")
    assert_api_error(resp, 404)
Example #21
0
def test_create_missing_param(client):
    """POST /user with missing parameter"""
    resp = client.post("/user", data={"name": USER_NAME, "email": USER_EMAIL})

    assert_api_error(resp, 422, meta={"field": "password"})
def test_paper_get_invalid_period(auth_client):
    resp = auth_client.get("/course/{code}/paper/{year}/{period}".format(
        code="CT360", year="2014", period="non-period"))

    assert_api_error(resp, 422, meta={"field": "period"})
def test_institution_get_not_found(institution, client):
    resp = client.get("/institution/24097")
    assert_api_error(resp, 404)
def test_course_search_no_login(client):
    assert_api_error(client.get("/course/search?q=foo"), 401)
def test_auth_check_invalid_key(client):
    resp = client.get("/auth", headers=[(AUTH_HEADER_NAME, "INVALID_LOL")])
    assert_api_error(resp, 401, "Unauthorized")
def test_institution_search_no_domain(client):
    assert_api_error(client.get("/institution/search"), 422, meta={"field": "domain"})
def test_course_search_no_query(auth_client):
    assert_api_error(auth_client.get("/course/search"), 422, meta={"field": "q"})
def test_auth_check_no_key(client):
    resp = client.get("/auth")
    assert_api_error(resp, 422, "Missing", meta={ "field": AUTH_HEADER_NAME })
def test_course_get_not_found(auth_client):
    resp = auth_client.get("/course/foobar")
    assert_api_error(resp, 404)
def test_login_missing_params(client):
    resp = client.post("/login", data={ "email": "*****@*****.**" })
    assert_api_error(resp, 422, meta={"field": "password"})
def test_institution_search_no_domain(client):
    assert_api_error(client.get("/institution/search"),
                     422,
                     meta={"field": "domain"})
def test_institution_get_not_found(institution, client):
    resp = client.get("/institution/24097")
    assert_api_error(resp, 404)
def test_institution_search_no_institutions(client):
    resp = client.get("/institution/search?domain=foo.com")
    assert_api_error(resp, 404)