Skip to content

Commit

Permalink
Merge pull request #77 from huntflow/INT-438_add_api_version_to_consts
Browse files Browse the repository at this point in the history
[INT-438] add api version to consts
  • Loading branch information
KlochkovHF authored Dec 15, 2023
2 parents ff9754d + 5ea1792 commit 65d956f
Show file tree
Hide file tree
Showing 35 changed files with 216 additions and 167 deletions.
2 changes: 1 addition & 1 deletion examples/api_client_with_simple_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def parse_args():
default=3,
help="Number of concurrent requests",
)
parser.add_argument("--url", type=str, help="https://<api domain>/v2")
parser.add_argument("--url", type=str, help="https://<api domain>")
parser.add_argument(
"--token-file",
type=str,
Expand Down
12 changes: 7 additions & 5 deletions huntflow_api_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@

logger = logging.getLogger(__name__)

API_VERSION_PATH = "/v2"


class HuntflowAPI:
def __init__(
self,
base_url: str = "https://api.huntflow.dev/v2",
base_url: str = "https://api.huntflow.dev",
# Specify one of this: token or token_proxy
token: Optional[ApiToken] = None,
token_proxy: Optional[AbstractTokenProxy] = None,
auto_refresh_tokens: bool = False,
):
"""API client.
:param base_url: Base url for API (including schema and version prefix),
like 'https://<api domain>/v2'
:param base_url: Base url for API (including schema),
like 'https://<api domain>'
:param token: Optional token structure with access token.
Use it if you don't care about token refreshing
:param token_proxy: Alternative way (see `token` param) to provide token.
Expand All @@ -39,13 +41,13 @@ def __init__(
raise ValueError("Parameters token and token_proxy can't be None at the same time")
token_proxy = DummyHuntflowTokenProxy(token)
self._token_proxy: AbstractTokenProxy = token_proxy
self.base_url = base_url
self.api_url = base_url + API_VERSION_PATH

self._autorefresh_tokens = auto_refresh_tokens

@property
def http_client(self) -> httpx.AsyncClient:
http_client = httpx.AsyncClient(base_url=self.base_url)
http_client = httpx.AsyncClient(base_url=self.api_url)
http_client.event_hooks["response"] = [raise_for_status]
return http_client

Expand Down
7 changes: 4 additions & 3 deletions tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import respx
from respx.types import URLPatternTypes

from huntflow_api_client.api import API_VERSION_PATH
from huntflow_api_client.tokens.storage import HuntflowTokenFileStorage

BASE_URL = "https://api.huntflow.dev/v2"
BASE_URL = "https://api.huntflow.dev"
VERSIONED_BASE_URL = BASE_URL + API_VERSION_PATH
ACCESS_TOKEN_EXPIRES_IN = 86400 * 7
REFRESH_TOKEN_EXPIRES_IN = 86400 * 14

Expand Down Expand Up @@ -37,15 +39,14 @@ def inner(*args: Any, **kwargs: Any) -> Any:

respx.request(
method=self.method,
url=f"{BASE_URL}{self.url}",
url=f"{VERSIONED_BASE_URL}{self.url}",
name=self.name,
).mock(side_effect=inner)

return inner


class FakeAPIServer:
base_url = BASE_URL
token_pair: TokenPair
is_expired_token: bool

Expand Down
8 changes: 4 additions & 4 deletions tests/test_entities/test_account_divisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
DivisionsListResponse,
)
from huntflow_api_client.tokens.proxy import HuntflowTokenProxy
from tests.api import BASE_URL
from tests.api import BASE_URL, VERSIONED_BASE_URL

ACCOUNT_ID = 1
COWORKER_ID = 1
Expand Down Expand Up @@ -72,7 +72,7 @@ async def test_list_account_division(
) -> None:
only_available = True
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/divisions?only_available=true",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/divisions?only_available=true",
json=ACCOUNT_DIVISIONS_LIST_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand All @@ -82,7 +82,7 @@ async def test_list_account_division(
assert response == DivisionsListResponse.model_validate(ACCOUNT_DIVISIONS_LIST_RESPONSE)

httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/coworkers/{COWORKER_ID}/divisions",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/coworkers/{COWORKER_ID}/divisions",
json=ACCOUNT_DIVISIONS_LIST_RESPONSE,
)
response = await divisions.list(ACCOUNT_ID, COWORKER_ID)
Expand All @@ -97,7 +97,7 @@ async def test_create_account_division(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/divisions/batch",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/divisions/batch",
json=BATCH_ACCOUNT_DIVISIONS_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_entities/test_account_offers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
AccountOffersListResponse,
)
from huntflow_api_client.tokens.proxy import HuntflowTokenProxy
from tests.api import BASE_URL
from tests.api import BASE_URL, VERSIONED_BASE_URL

ACCOUNT_ID = 1
OFFER_ID = 2
Expand Down Expand Up @@ -119,7 +119,7 @@ async def test_list(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/offers",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/offers",
json=GET_ORG_OFFERS_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand All @@ -134,7 +134,7 @@ async def test_get(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/offers/{OFFER_ID}",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/offers/{OFFER_ID}",
json=GET_ORG_OFFERS_WITH_SCHEMA_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand Down
9 changes: 6 additions & 3 deletions tests/test_entities/test_account_vacancy_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
AccountVacancyRequestsListResponse,
)
from huntflow_api_client.tokens.proxy import HuntflowTokenProxy
from tests.api import BASE_URL
from tests.api import BASE_URL, VERSIONED_BASE_URL

ACCOUNT_ID = 1

Expand Down Expand Up @@ -100,7 +100,10 @@ async def test_list_schemas(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/account_vacancy_requests?only_active=true",
url=(
f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}"
"/account_vacancy_requests?only_active=true"
),
json=VACANCY_REQUEST_SCHEMAS_LIST,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand All @@ -117,7 +120,7 @@ async def test_get_schema(
) -> None:
schema_id = 1
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/account_vacancy_requests/{schema_id}",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/account_vacancy_requests/{schema_id}",
json=VACANCY_REQUEST_SCHEMA,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_entities/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
OrganizationsListResponse,
)
from huntflow_api_client.tokens.proxy import HuntflowTokenProxy
from tests.api import BASE_URL
from tests.api import BASE_URL, VERSIONED_BASE_URL

ACCOUNT_ID = 1
GET_USER_RESPONSE: Dict[str, Any] = {
Expand Down Expand Up @@ -46,7 +46,7 @@ async def test_get_current_user(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/me",
url=f"{VERSIONED_BASE_URL}/me",
json=GET_USER_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand All @@ -61,7 +61,7 @@ async def test_available_org_list(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts",
url=f"{VERSIONED_BASE_URL}/accounts",
json=ORG_LIST_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand All @@ -76,7 +76,7 @@ async def test_get_org_info(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}",
json=GET_ORG_INFO_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_entities/test_action_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from huntflow_api_client.entities.action_logs import ActionLog
from huntflow_api_client.models.response.action_logs import ActionLogsResponse
from huntflow_api_client.tokens.proxy import HuntflowTokenProxy
from tests.api import BASE_URL
from tests.api import BASE_URL, VERSIONED_BASE_URL

ACCOUNT_ID = 1
ACTION_LOGS_LIST_RESPONSE: Dict[str, Any] = {
Expand Down Expand Up @@ -36,7 +36,7 @@ async def test_action_log_list(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/action_logs?count=30",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/action_logs?count=30",
json=ACTION_LOGS_LIST_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_entities/test_applicant_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
CreateApplicantLogResponse,
)
from huntflow_api_client.tokens.proxy import HuntflowTokenProxy
from tests.api import BASE_URL
from tests.api import BASE_URL, VERSIONED_BASE_URL

ACCOUNT_ID = 1
APPLICANT_ID = 2
Expand Down Expand Up @@ -173,7 +173,7 @@ async def test_applicant_log_list(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/applicants/{APPLICANT_ID}/logs?"
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/applicants/{APPLICANT_ID}/logs?"
f"vacancy={VACANCY_ID}&&type={ApplicantLogType.ADD.value}&&personal=true"
f"&&page=1&&count=30&&personal=false",
status_code=200,
Expand All @@ -197,7 +197,7 @@ async def test_create_log(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/applicants/{APPLICANT_ID}/logs",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/applicants/{APPLICANT_ID}/logs",
status_code=200,
json=APPLICANT_CREATE_LOG_RESPONSE,
)
Expand Down
14 changes: 10 additions & 4 deletions tests/test_entities/test_applicant_offers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from huntflow_api_client.models.request.applicant_offers import ApplicantOfferUpdate
from huntflow_api_client.models.response.applicant_offers import ApplicantVacancyOfferResponse
from huntflow_api_client.tokens.proxy import HuntflowTokenProxy
from tests.api import BASE_URL
from tests.api import BASE_URL, VERSIONED_BASE_URL

ACCOUNT_ID = 1
OFFER_ID = 2
Expand All @@ -34,7 +34,10 @@ async def test_update(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/applicants/{APPLICANT_ID}/offers/{OFFER_ID}",
url=(
f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}"
f"/applicants/{APPLICANT_ID}/offers/{OFFER_ID}"
),
json=OFFER_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand Down Expand Up @@ -63,7 +66,7 @@ async def test_get_applicant_on_vacancy_offer(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/applicants/{APPLICANT_ID}"
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/applicants/{APPLICANT_ID}"
f"/vacancy_frames/{VACANCY_FRAME_ID}/offer?normalize=false",
json=OFFER_RESPONSE,
)
Expand All @@ -83,7 +86,10 @@ async def test_get_offer_pdf(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/applicants/{APPLICANT_ID}/offers/{OFFER_ID}/pdf",
url=(
f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}"
f"/applicants/{APPLICANT_ID}/offers/{OFFER_ID}/pdf"
),
content=GET_PDF_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_entities/test_applicant_on_vacancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ApplicantVacancySplitResponse,
)
from huntflow_api_client.tokens.proxy import HuntflowTokenProxy
from tests.api import BASE_URL
from tests.api import BASE_URL, VERSIONED_BASE_URL

ACCOUNT_ID = 1
APPLICANT_ID = 1
Expand Down Expand Up @@ -51,7 +51,7 @@ async def test_attach_applicant_to_vacancy(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/applicants/{APPLICANT_ID}/vacancy",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/applicants/{APPLICANT_ID}/vacancy",
json=ATTACH_APPLICANT_TO_VAC_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand All @@ -73,7 +73,7 @@ async def test_update_vacancy_status_for_applicant(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/applicants/{APPLICANT_ID}/vacancy",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/applicants/{APPLICANT_ID}/vacancy",
json=UPDATE_STATUS_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand All @@ -95,7 +95,7 @@ async def test_move_applicant_to_child_vacancy(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/applicants/vacancy/{VACANCY_ID}/split",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/applicants/vacancy/{VACANCY_ID}/split",
json=MOVE_APPLICANT_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_entities/test_applicant_on_vacancy_statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from huntflow_api_client.entities.applicant_on_vacancy_status import ApplicantOnVacancyStatus
from huntflow_api_client.models.response.applicant_on_vacancy_status import VacancyStatusesResponse
from huntflow_api_client.tokens.proxy import HuntflowTokenProxy
from tests.api import BASE_URL
from tests.api import BASE_URL, VERSIONED_BASE_URL

ACCOUNT_ID = 1
APPLICANT_ON_VAC_STATUS_LIST_RESPONSE: Dict[str, Any] = {
Expand All @@ -28,7 +28,7 @@ async def test_list(
token_proxy: HuntflowTokenProxy,
) -> None:
httpx_mock.add_response(
url=f"{BASE_URL}/accounts/{ACCOUNT_ID}/vacancies/statuses",
url=f"{VERSIONED_BASE_URL}/accounts/{ACCOUNT_ID}/vacancies/statuses",
json=APPLICANT_ON_VAC_STATUS_LIST_RESPONSE,
)
api_client = HuntflowAPI(BASE_URL, token_proxy=token_proxy)
Expand Down
Loading

0 comments on commit 65d956f

Please sign in to comment.