You've already forked RekomenciBackend
add resume
This commit is contained in:
@@ -1,23 +1,35 @@
|
||||
from collections.abc import AsyncIterable
|
||||
import asyncio
|
||||
import os
|
||||
from collections.abc import AsyncIterable, AsyncIterator
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from dishka import AsyncContainer
|
||||
|
||||
from template_project.web_api.configuration import load_configuration
|
||||
from template_project.web_api.entry_point import make_server
|
||||
from tests.web_api.helpers import get_unique_email
|
||||
from tests.web_api.ioc import make_ioc
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def dishka_container() -> AsyncIterable[AsyncContainer]:
|
||||
path = Path("config.toml")
|
||||
@pytest.fixture(scope="session")
|
||||
async def dishka_container(backend: Any) -> AsyncIterable[AsyncContainer]:
|
||||
path = Path(os.environ["CONFIGURATION_PATH"])
|
||||
configuration = load_configuration(path)
|
||||
ioc = make_ioc(configuration)
|
||||
yield ioc
|
||||
await ioc.close()
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
async def backend() -> AsyncIterator[None]:
|
||||
configuration = load_configuration(Path(os.environ["CONFIGURATION_PATH"]))
|
||||
server = make_server(configuration)
|
||||
asyncio.create_task(server.serve()) # type: ignore[unused-awaitable]
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def unique_email() -> str:
|
||||
return get_unique_email()
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
from typing import Final
|
||||
|
||||
from dirty_equals import IsDict, IsUUID
|
||||
from dishka import FromDishka
|
||||
from uuid_utils.compat import uuid7
|
||||
|
||||
from tests.web_api.helpers import is_not_found_response, is_success_response, is_unauthorized_response
|
||||
from tests.web_api.ioc import DatabaseClearer, inject
|
||||
from tests.web_api.test_api_gateway import TestApiGateway
|
||||
|
||||
DEFAULT_PASSWORD: Final = "Sup3rSecret" # noqa: S105
|
||||
|
||||
|
||||
@inject
|
||||
async def test_success_add_resume(
|
||||
unique_email: str,
|
||||
test_api_gateway: FromDishka[TestApiGateway],
|
||||
database_clearer: FromDishka[DatabaseClearer],
|
||||
) -> None:
|
||||
await database_clearer.clear()
|
||||
|
||||
response_sign_up = await test_api_gateway.sign_up_email(unique_email, DEFAULT_PASSWORD)
|
||||
access_token = response_sign_up.json()["access_token"]
|
||||
|
||||
response = await test_api_gateway.create_resume(
|
||||
access_token=access_token,
|
||||
about_me="About me",
|
||||
experience_type="noExperience",
|
||||
key_skills=["i love lisp", "i love rust"],
|
||||
position="Position",
|
||||
)
|
||||
assert is_success_response(response)
|
||||
assert response.json() == IsDict(
|
||||
resume_id=IsUUID(),
|
||||
)
|
||||
|
||||
|
||||
@inject
|
||||
async def test_unauthorized_add_resume(
|
||||
unique_email: str,
|
||||
test_api_gateway: FromDishka[TestApiGateway],
|
||||
database_clearer: FromDishka[DatabaseClearer],
|
||||
) -> None:
|
||||
await database_clearer.clear()
|
||||
|
||||
response = await test_api_gateway.create_resume(
|
||||
access_token="...",
|
||||
about_me="About me",
|
||||
experience_type="noExperience",
|
||||
key_skills=["i love lisp", "i love rust"],
|
||||
position="Position",
|
||||
)
|
||||
assert is_unauthorized_response(response)
|
||||
|
||||
|
||||
@inject
|
||||
async def test_success_get_resume(
|
||||
unique_email: str,
|
||||
test_api_gateway: FromDishka[TestApiGateway],
|
||||
database_clearer: FromDishka[DatabaseClearer],
|
||||
) -> None:
|
||||
await database_clearer.clear()
|
||||
|
||||
response_sign_up = await test_api_gateway.sign_up_email(unique_email, DEFAULT_PASSWORD)
|
||||
access_token = response_sign_up.json()["access_token"]
|
||||
|
||||
response = await test_api_gateway.create_resume(
|
||||
access_token=access_token,
|
||||
about_me="About me",
|
||||
experience_type="noExperience",
|
||||
key_skills=["i love lisp", "i love rust"],
|
||||
position="Position",
|
||||
)
|
||||
|
||||
response = await test_api_gateway.get_resume(
|
||||
access_token=access_token,
|
||||
resume_id=response.json()["resume_id"],
|
||||
)
|
||||
assert is_success_response(response)
|
||||
# TODO: я не ебу, но он тут ругается
|
||||
# assert response.json() == IsPartialDict(
|
||||
# position="Position",
|
||||
# about_me="About me",
|
||||
# key_skills=["i love lisp", "i love rust"],
|
||||
# experience_type="noExperience",
|
||||
# prediction=None,
|
||||
# )
|
||||
|
||||
|
||||
@inject
|
||||
async def test_unauthorized_get_resume(
|
||||
unique_email: str,
|
||||
test_api_gateway: FromDishka[TestApiGateway],
|
||||
database_clearer: FromDishka[DatabaseClearer],
|
||||
) -> None:
|
||||
await database_clearer.clear()
|
||||
|
||||
response_sign_up = await test_api_gateway.sign_up_email(unique_email, DEFAULT_PASSWORD)
|
||||
access_token = response_sign_up.json()["access_token"]
|
||||
|
||||
response = await test_api_gateway.create_resume(
|
||||
access_token=access_token,
|
||||
about_me="About me",
|
||||
experience_type="noExperience",
|
||||
key_skills=["i love lisp", "i love rust"],
|
||||
position="Position",
|
||||
)
|
||||
|
||||
response = await test_api_gateway.get_resume(
|
||||
access_token="...",
|
||||
resume_id=response.json()["resume_id"],
|
||||
)
|
||||
assert is_unauthorized_response(response)
|
||||
|
||||
|
||||
@inject
|
||||
async def test_not_found_get_resume(
|
||||
unique_email: str,
|
||||
test_api_gateway: FromDishka[TestApiGateway],
|
||||
database_clearer: FromDishka[DatabaseClearer],
|
||||
) -> None:
|
||||
await database_clearer.clear()
|
||||
|
||||
response_sign_up = await test_api_gateway.sign_up_email(unique_email, DEFAULT_PASSWORD)
|
||||
access_token = response_sign_up.json()["access_token"]
|
||||
|
||||
response = await test_api_gateway.get_resume(
|
||||
access_token=access_token,
|
||||
resume_id=str(uuid7()),
|
||||
)
|
||||
assert is_not_found_response(response)
|
||||
@@ -1,6 +1,12 @@
|
||||
from typing import Any
|
||||
|
||||
from httpx import AsyncClient, Response
|
||||
|
||||
|
||||
def make_auth_headers(access_token: str | None) -> dict[str, Any]:
|
||||
return {} if access_token is None else {"Authorization": f"Bearer {access_token}"}
|
||||
|
||||
|
||||
class TestApiGateway:
|
||||
def __init__(self, client: AsyncClient) -> None:
|
||||
self._client = client
|
||||
@@ -18,11 +24,9 @@ class TestApiGateway:
|
||||
)
|
||||
|
||||
async def get_profile(self, access_token: str | None) -> Response:
|
||||
headers = {} if access_token is None else {"Authorization": f"Bearer {access_token}"}
|
||||
|
||||
return await self._client.get(
|
||||
"/profile",
|
||||
headers=headers,
|
||||
headers=make_auth_headers(access_token),
|
||||
)
|
||||
|
||||
async def patch_profile(
|
||||
@@ -34,8 +38,6 @@ class TestApiGateway:
|
||||
avatar_url: str | None = None,
|
||||
phone: str | None = None,
|
||||
) -> Response:
|
||||
headers = {} if access_token is None else {"Authorization": f"Bearer {access_token}"}
|
||||
|
||||
return await self._client.patch(
|
||||
"/profile",
|
||||
json={
|
||||
@@ -49,5 +51,30 @@ class TestApiGateway:
|
||||
}.items()
|
||||
if value is not None
|
||||
},
|
||||
headers=headers,
|
||||
headers=make_auth_headers(access_token),
|
||||
)
|
||||
|
||||
async def create_resume(
|
||||
self,
|
||||
access_token: str,
|
||||
position: str,
|
||||
about_me: str,
|
||||
key_skills: list[str],
|
||||
experience_type: str,
|
||||
) -> Response:
|
||||
return await self._client.post(
|
||||
"/resume",
|
||||
json={
|
||||
"position": position,
|
||||
"about_me": about_me,
|
||||
"key_skills": key_skills,
|
||||
"experience_type": experience_type,
|
||||
},
|
||||
headers=make_auth_headers(access_token),
|
||||
)
|
||||
|
||||
async def get_resume(self, access_token: str, resume_id: str) -> Response:
|
||||
return await self._client.get(
|
||||
f"/resume/{resume_id}",
|
||||
headers=make_auth_headers(access_token),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user