diff --git a/huntflow_api_client/entities/survey_type_a.py b/huntflow_api_client/entities/survey_type_a.py index 87efb5c..b251450 100644 --- a/huntflow_api_client/entities/survey_type_a.py +++ b/huntflow_api_client/entities/survey_type_a.py @@ -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, ) @@ -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()) diff --git a/huntflow_api_client/models/response/survey.py b/huntflow_api_client/models/response/survey.py index 8bd4321..7588e1a 100644 --- a/huntflow_api_client/models/response/survey.py +++ b/huntflow_api_client/models/response/survey.py @@ -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") diff --git a/pyproject.toml b/pyproject.toml index f62ac8b..6335b2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = "developer@huntflow.ru"}, diff --git a/tests/test_entities/test_survey_type_a.py b/tests/test_entities/test_survey_type_a.py index e8a9aea..4be42c4 100644 --- a/tests/test_entities/test_survey_type_a.py +++ b/tests/test_entities/test_survey_type_a.py @@ -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, ) @@ -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, @@ -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, + )