Skip to content

Commit 419c165

Browse files
authored
Merge pull request #95 from huntflow/INT-595_update_SurveyTypeA_entity
[INT-595] - Add get_applicant_answer() to SurveyTypeA entity.
2 parents f55c464 + c5a4194 commit 419c165

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

huntflow_api_client/entities/survey_type_a.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from huntflow_api_client.entities.base import BaseEntity, GetEntityMixin, ListEntityMixin
22
from huntflow_api_client.models.response.survey import (
3+
SurveyAnswerTypeAResponse,
34
SurveySchemasTypeAListResponse,
45
SurveySchemaTypeAResponse,
56
)
@@ -41,3 +42,24 @@ async def get(self, account_id: int, survey_id: int) -> SurveySchemaTypeARespons
4142
f"/accounts/{account_id}/surveys/type_a/{survey_id}",
4243
)
4344
return SurveySchemaTypeAResponse.model_validate(response.json())
45+
46+
async def get_applicant_answer(
47+
self,
48+
account_id: int,
49+
survey_id: int,
50+
answer_id: int,
51+
) -> SurveyAnswerTypeAResponse:
52+
"""
53+
API method reference
54+
https://api.huntflow.ai/v2/docs#get-/accounts/-account_id-/surveys/type_a/-survey_id-/answers/-answer_id-
55+
56+
:param account_id: Organization ID
57+
:param survey_id: Survey ID
58+
:param answer_id: Answer ID
59+
:return: Returns answer of applicant feedback form.
60+
"""
61+
response = await self._api.request(
62+
"GET",
63+
f"/accounts/{account_id}/surveys/type_a/{survey_id}/answers/{answer_id}",
64+
)
65+
return SurveyAnswerTypeAResponse.model_validate(response.json())

huntflow_api_client/models/response/survey.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,16 @@ class SurveySchemaTypeAResponse(BaseSurveySchemaTypeWithSchemas):
7777
description="Type of survey",
7878
frozen=True,
7979
)
80+
81+
82+
class SurveyTypeARespondent(BaseModel):
83+
account_id: int = Field(..., description="Account ID")
84+
name: str = Field(..., description="Name of the user who created the survey answer")
85+
86+
87+
class SurveyAnswerTypeAResponse(BaseModel):
88+
id: int = Field(..., description="Survey answer of type A ID")
89+
created: datetime.datetime = Field(..., description="Date and time of creating an answer")
90+
survey: SurveySchemaTypeAResponse = Field(..., description="Survey schema")
91+
respondent: SurveyTypeARespondent = Field(..., description="Who created the survey answer")
92+
data: dict = Field(..., description="Answer data")

tests/test_entities/test_survey_type_a.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from huntflow_api_client import HuntflowAPI
44
from huntflow_api_client.entities.survey_type_a import SurveyTypeA
55
from huntflow_api_client.models.response.survey import (
6+
SurveyAnswerTypeAResponse,
67
SurveySchemasTypeAListResponse,
78
SurveySchemaTypeAResponse,
89
)
@@ -35,6 +36,23 @@
3536
"ui_schema": {},
3637
}
3738

39+
SURVEY_ANSWER_RESPONSE = {
40+
"id": 1,
41+
"created": "2020-01-01T00:00:00+03:00",
42+
"survey": {
43+
"id": 1,
44+
"name": "test_survey",
45+
"type": "type_a",
46+
"active": True,
47+
"created": "2020-01-01T00:00:00+03:00",
48+
"updated": "2020-01-01T00:00:00+03:00",
49+
"schema": {},
50+
"ui_schema": {},
51+
},
52+
"respondent": {"account_id": 1, "name": "John Joe"},
53+
"data": {},
54+
}
55+
3856

3957
async def test_list(
4058
httpx_mock: HTTPXMock,
@@ -69,3 +87,23 @@ async def test_get(
6987
assert response == SurveySchemaTypeAResponse.model_validate(
7088
SURVEY_FEEDBACK_SCHEMA_RESPONSE,
7189
)
90+
91+
92+
async def test_get_applicant_answer(
93+
httpx_mock: HTTPXMock,
94+
token_proxy: HuntflowTokenProxy,
95+
) -> None:
96+
survey_id = 1
97+
answer_id = 2
98+
httpx_mock.add_response(
99+
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/surveys/type_a/"
100+
f"{survey_id}/answers/{answer_id}",
101+
json=SURVEY_ANSWER_RESPONSE,
102+
)
103+
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
104+
feedback = SurveyTypeA(api_client)
105+
106+
response = await feedback.get_applicant_answer(ACCOUNT_ID, survey_id, answer_id)
107+
assert response == SurveyAnswerTypeAResponse.model_validate(
108+
SURVEY_ANSWER_RESPONSE,
109+
)

0 commit comments

Comments
 (0)