Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INT-595] - Add get_applicant_answer() to SurveyTypeA entity. #95

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[project]
name = "huntflow-api-client"
version = "2.1.0"
version = "2.2.0"
description = "Huntflow API Client for Python"
authors = [
{name = "Developers huntflow", email = "[email protected]"},
Expand Down
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,
)
Loading