Skip to content

Commit

Permalink
[#213] Add test for crud_answer append_value func
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Oct 10, 2022
1 parent 6893967 commit 690b463
Showing 1 changed file with 72 additions and 2 deletions.
74 changes: 72 additions & 2 deletions backend/tests/test_04_submission.py
Expand Up @@ -5,6 +5,9 @@
from httpx import AsyncClient
from tests.test_01_auth import Acc
from sqlalchemy.orm import Session
import db.crud_answer as crud_answer
from models.answer import Answer
from models.question import QuestionType

pytestmark = pytest.mark.asyncio
sys.path.append("..")
Expand Down Expand Up @@ -143,9 +146,76 @@ async def test_get_form(self, app: FastAPI, session: Session,
}]
}

@pytest.mark.asynio
async def test_append_value_crud_answer_func(
self, app: FastAPI, session: Session, client: AsyncClient) -> None:
answer = Answer(question=1, created_by=1, created=None)
# option
value = ["Option 1"]
res = crud_answer.append_value(
answer=answer, value=value, type=QuestionType.option)
assert res.question == answer.question
assert res.options == value
assert res.text is None
assert res.value is None
# administration
answer = Answer(question=2, created_by=1, created=None)
value = 10
res = crud_answer.append_value(
answer=answer, value=value, type=QuestionType.administration)
assert res.question == answer.question
assert res.value == value
assert res.text is None
assert res.options is None
# geo
answer = Answer(question=3, created_by=1, created=None)
value = [-7.836114, 110.331143]
res = crud_answer.append_value(
answer=answer, value=value, type=QuestionType.geo)
assert res.question == answer.question
assert res.text == ("{}|{}").format(value[0], value[1])
assert res.value is None
assert res.options is None
# text
answer = Answer(question=4, created_by=1, created=None)
value = "Test"
res = crud_answer.append_value(
answer=answer, value=value, type=QuestionType.text)
assert res.question == answer.question
assert res.text == value
assert res.value is None
assert res.options is None
# number
answer = Answer(question=5, created_by=1, created=None)
value = 99
res = crud_answer.append_value(
answer=answer, value=value, type=QuestionType.number)
assert res.question == answer.question
assert res.value == value
assert res.text is None
assert res.options is None
# date
answer = Answer(question=6, created_by=1, created=None)
value = "2021-12-21"
res = crud_answer.append_value(
answer=answer, value=value, type=QuestionType.date)
assert res.question == answer.question
assert res.text == value
assert res.value is None
assert res.options is None
# multiple option
answer = Answer(question=7, created_by=1, created=None)
value = ["Multiple Option 1", "Multiple Option 2"]
res = crud_answer.append_value(
answer=answer, value=value, type=QuestionType.multiple_option)
assert res.question == answer.question
assert res.options == value
assert res.text is None
assert res.value is None

@pytest.mark.asyncio
async def test_submit_data(self, app: FastAPI, session: Session,
client: AsyncClient) -> None:
async def test_submit_data(
self, app: FastAPI, session: Session, client: AsyncClient) -> None:
res = await client.post(
app.url_path_for("data:create", form_id=1),
json=[{
Expand Down

0 comments on commit 690b463

Please sign in to comment.