Skip to content

Commit

Permalink
Merge pull request #95 from huntflow/INT-595_update_SurveyTypeA_entity
Browse files Browse the repository at this point in the history
[INT-595] - Add get_applicant_answer() to SurveyTypeA entity.
  • Loading branch information
polina-koval authored May 17, 2024
2 parents f55c464 + c5a4194 commit 419c165
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
22 changes: 22 additions & 0 deletions huntflow_api_client/entities/survey_type_a.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from huntflow_api_client.entities.base import BaseEntity, GetEntityMixin, ListEntityMixin
from huntflow_api_client.models.response.survey import (
SurveyAnswerTypeAResponse,
SurveySchemasTypeAListResponse,
SurveySchemaTypeAResponse,
)
Expand Down Expand Up @@ -41,3 +42,24 @@ async def get(self, account_id: int, survey_id: int) -> SurveySchemaTypeARespons
f"/accounts/{account_id}/surveys/type_a/{survey_id}",
)
return SurveySchemaTypeAResponse.model_validate(response.json())

async def get_applicant_answer(
self,
account_id: int,
survey_id: int,
answer_id: int,
) -> SurveyAnswerTypeAResponse:
"""
API method reference
https://api.huntflow.ai/v2/docs#get-/accounts/-account_id-/surveys/type_a/-survey_id-/answers/-answer_id-
:param account_id: Organization ID
:param survey_id: Survey ID
:param answer_id: Answer ID
:return: Returns answer of applicant feedback form.
"""
response = await self._api.request(
"GET",
f"/accounts/{account_id}/surveys/type_a/{survey_id}/answers/{answer_id}",
)
return SurveyAnswerTypeAResponse.model_validate(response.json())
13 changes: 13 additions & 0 deletions huntflow_api_client/models/response/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,16 @@ class SurveySchemaTypeAResponse(BaseSurveySchemaTypeWithSchemas):
description="Type of survey",
frozen=True,
)


class SurveyTypeARespondent(BaseModel):
account_id: int = Field(..., description="Account ID")
name: str = Field(..., description="Name of the user who created the survey answer")


class SurveyAnswerTypeAResponse(BaseModel):
id: int = Field(..., description="Survey answer of type A ID")
created: datetime.datetime = Field(..., description="Date and time of creating an answer")
survey: SurveySchemaTypeAResponse = Field(..., description="Survey schema")
respondent: SurveyTypeARespondent = Field(..., description="Who created the survey answer")
data: dict = Field(..., description="Answer data")
38 changes: 38 additions & 0 deletions tests/test_entities/test_survey_type_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from huntflow_api_client import HuntflowAPI
from huntflow_api_client.entities.survey_type_a import SurveyTypeA
from huntflow_api_client.models.response.survey import (
SurveyAnswerTypeAResponse,
SurveySchemasTypeAListResponse,
SurveySchemaTypeAResponse,
)
Expand Down Expand Up @@ -35,6 +36,23 @@
"ui_schema": {},
}

SURVEY_ANSWER_RESPONSE = {
"id": 1,
"created": "2020-01-01T00:00:00+03:00",
"survey": {
"id": 1,
"name": "test_survey",
"type": "type_a",
"active": True,
"created": "2020-01-01T00:00:00+03:00",
"updated": "2020-01-01T00:00:00+03:00",
"schema": {},
"ui_schema": {},
},
"respondent": {"account_id": 1, "name": "John Joe"},
"data": {},
}


async def test_list(
httpx_mock: HTTPXMock,
Expand Down Expand Up @@ -69,3 +87,23 @@ async def test_get(
assert response == SurveySchemaTypeAResponse.model_validate(
SURVEY_FEEDBACK_SCHEMA_RESPONSE,
)


async def test_get_applicant_answer(
httpx_mock: HTTPXMock,
token_proxy: HuntflowTokenProxy,
) -> None:
survey_id = 1
answer_id = 2
httpx_mock.add_response(
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/surveys/type_a/"
f"{survey_id}/answers/{answer_id}",
json=SURVEY_ANSWER_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
feedback = SurveyTypeA(api_client)

response = await feedback.get_applicant_answer(ACCOUNT_ID, survey_id, answer_id)
assert response == SurveyAnswerTypeAResponse.model_validate(
SURVEY_ANSWER_RESPONSE,
)

0 comments on commit 419c165

Please sign in to comment.