Exemple #1
0
def test_not_author_delete_survey(client):
    create_user(login="******", id=1)
    create_user(login="******", id=2)
    client.login(username="******", password="******")
    create_survey_area("TestSurveyArea")
    create_survey(name="TestSurvey", author_id=1, area_id=1)
    response = client.post(
        get_survey_delete_url(),
        {"survey_id": 1},  # fmt off  # fmt on
        content_type="application/json",
    )
    assert response.status_code == 403
Exemple #2
0
def test_delete_survey_no_such_survey(client):
    create_user(login="******")
    client.login(username="******", password="******")
    create_survey_area("TestSurveyArea")
    create_survey(name="TestSurvey", author_id=1, area_id=1)
    response = client.post(
        get_survey_delete_url(),
        {
            "session_id": "test_session_id",
            "survey_id": 0
        },
        content_type="application/json",
    )
    assert response.status_code == 404
Exemple #3
0
def test_successful_get_one_survey(client):
    create_user(login="******")
    client.login(username="******", password="******")
    create_survey_area("Anything")
    create_survey(name="Survey", author_id=1, area_id=1)
    response = client.get(get_survey_get_one_url(1))
    assert response.status_code == 200
    survey = parse_survey(get_survey(survey_id=1))
    assert survey == {
        "id": 1,
        "name": "Survey",
        "author_id": 1,
        "area_id": 1,
        "type": "Formal",
    }
Exemple #4
0
def test_del_answer_successful(client):
    create_user(login="******")
    client.login(username="******", password="******")
    create_question(content="TestQuestion", author_id=1)
    create_answer(content="TestAnswer")
    create_survey_area(name="TestSurveyArea")
    create_survey(name="TestSurvey", author_id=1, area_id=1)
    response = client.post(
        get_answer_delete_url(),
        {
            "answer_id": 1,
            "survey_id": 1
        },
        content_type="application/json",
    )
    assert response.status_code == 200
Exemple #5
0
def test_complete_survey_successful(client):
    create_user(login="******")
    create_survey_area(name="TestSurveyArea")
    create_survey(name="TestSurvey", author_id=1, area_id=1)
    create_answer(content="TestAnswer1", id=1)
    create_question(content="TestQuestion1", author_id=1, id=1)
    create_answer(content="TestAnswer2", id=2)
    create_question(content="TestQuestion2", author_id=1, id=2)
    client.login(username="******", password="******")
    test_data = {
        "questions": [
            {"question_id": 1, "answer_id": 1, "complete_survey": 1},
            {"question_id": 2, "answer_id": 2, "complete_survey": 1},
        ],
        "user_id": 1,
        "survey_id": 1,
    }
    response = client.post(
        get_login_url(),
        test_data,
        content_type="application/json",
    )
    assert response.status_code == 200
Exemple #6
0
def test_delete_question_used(client):
    create_user(login="******")
    client.login(username="******", password="******")
    create_answer(content="TestAnswer")
    question = create_question(  # fmt: off
        content="TestQuestion?", author_id=1)  # fmt: on
    create_survey_area(name="Anything")
    create_survey(name="Survey", author_id=1, area_id=1)
    create_survey_question(survey_id=1, question_id=1)
    respone = client.post(
        question_delete_url(),
        {  # fmt: off
            "question_id": 1,
        },  # fmt: on
        content_type="application/json",
    )
    assert respone.status_code == 403
    question_obj = parse_question(get_question(question_id=question.id))
    assert question_obj == {  # fmt: off
        "id": 1,
        "content": "TestQuestion?",
        "author_id": 1,
    }  # fmt: on
Exemple #7
0
def test_successful_delete_survey(client):
    create_user(login="******")
    client.login(username="******", password="******")
    create_survey_area("TestSurveyArea")
    survey = create_survey(name="TestSurvey", author_id=1, area_id=1)
    response = client.post(
        get_survey_delete_url(),
        {  # fmt off
            "survey_id": 1,
        },  # fmt on
        content_type="application/json",
    )
    assert response.status_code == 200
    survey_obj = get_survey(survey_id=survey.id)
    assert survey_obj is None