Compare commits
No commits in common. "d8b62983a302eb03c16d86885955ef7802a984e1" and "f3a34b4c9e793ffc65e5d3bfbcc5402ed5d526ac" have entirely different histories.
d8b62983a3
...
f3a34b4c9e
4 changed files with 34 additions and 183 deletions
130
poetry.lock
generated
130
poetry.lock
generated
|
|
@ -168,19 +168,6 @@ docs = ["cogapp", "furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphi
|
|||
tests = ["cloudpickle ; platform_python_implementation == \"CPython\"", "hypothesis", "mypy (>=1.11.1) ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", "pytest-xdist[psutil]"]
|
||||
tests-mypy = ["mypy (>=1.11.1) ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", "pytest-mypy-plugins ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\""]
|
||||
|
||||
[[package]]
|
||||
name = "colorama"
|
||||
version = "0.4.6"
|
||||
description = "Cross-platform colored terminal text."
|
||||
optional = false
|
||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
||||
groups = ["test"]
|
||||
markers = "sys_platform == \"win32\""
|
||||
files = [
|
||||
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
|
||||
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "frozenlist"
|
||||
version = "1.7.0"
|
||||
|
|
@ -310,18 +297,6 @@ files = [
|
|||
[package.extras]
|
||||
all = ["flake8 (>=7.1.1)", "mypy (>=1.11.2)", "pytest (>=8.3.2)", "ruff (>=0.6.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "iniconfig"
|
||||
version = "2.1.0"
|
||||
description = "brain-dead simple config-ini parsing"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["test"]
|
||||
files = [
|
||||
{file = "iniconfig-2.1.0-py3-none-any.whl", hash = "sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760"},
|
||||
{file = "iniconfig-2.1.0.tar.gz", hash = "sha256:3abbd2e30b36733fee78f9c7f7308f2d0050e88f0087fd25c2645f63c773e1c7"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "multidict"
|
||||
version = "6.6.4"
|
||||
|
|
@ -442,34 +417,6 @@ files = [
|
|||
{file = "multidict-6.6.4.tar.gz", hash = "sha256:d2d4e4787672911b48350df02ed3fa3fffdc2f2e8ca06dd6afdf34189b76a9dd"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "packaging"
|
||||
version = "25.0"
|
||||
description = "Core utilities for Python packages"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["test"]
|
||||
files = [
|
||||
{file = "packaging-25.0-py3-none-any.whl", hash = "sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484"},
|
||||
{file = "packaging-25.0.tar.gz", hash = "sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pluggy"
|
||||
version = "1.6.0"
|
||||
description = "plugin and hook calling mechanisms for python"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
groups = ["test"]
|
||||
files = [
|
||||
{file = "pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746"},
|
||||
{file = "pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
dev = ["pre-commit", "tox"]
|
||||
testing = ["coverage", "pytest", "pytest-benchmark"]
|
||||
|
||||
[[package]]
|
||||
name = "propcache"
|
||||
version = "0.3.2"
|
||||
|
|
@ -712,90 +659,17 @@ files = [
|
|||
[package.dependencies]
|
||||
typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0"
|
||||
|
||||
[[package]]
|
||||
name = "pygments"
|
||||
version = "2.19.2"
|
||||
description = "Pygments is a syntax highlighting package written in Python."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["test"]
|
||||
files = [
|
||||
{file = "pygments-2.19.2-py3-none-any.whl", hash = "sha256:86540386c03d588bb81d44bc3928634ff26449851e99741617ecb9037ee5ec0b"},
|
||||
{file = "pygments-2.19.2.tar.gz", hash = "sha256:636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
windows-terminal = ["colorama (>=0.4.6)"]
|
||||
|
||||
[[package]]
|
||||
name = "pytest"
|
||||
version = "8.4.2"
|
||||
description = "pytest: simple powerful testing with Python"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
groups = ["test"]
|
||||
files = [
|
||||
{file = "pytest-8.4.2-py3-none-any.whl", hash = "sha256:872f880de3fc3a5bdc88a11b39c9710c3497a547cfa9320bc3c5e62fbf272e79"},
|
||||
{file = "pytest-8.4.2.tar.gz", hash = "sha256:86c0d0b93306b961d58d62a4db4879f27fe25513d4b969df351abdddb3c30e01"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
colorama = {version = ">=0.4", markers = "sys_platform == \"win32\""}
|
||||
iniconfig = ">=1"
|
||||
packaging = ">=20"
|
||||
pluggy = ">=1.5,<2"
|
||||
pygments = ">=2.7.2"
|
||||
|
||||
[package.extras]
|
||||
dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "requests", "setuptools", "xmlschema"]
|
||||
|
||||
[[package]]
|
||||
name = "pytest-asyncio"
|
||||
version = "1.2.0"
|
||||
description = "Pytest support for asyncio"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
groups = ["test"]
|
||||
files = [
|
||||
{file = "pytest_asyncio-1.2.0-py3-none-any.whl", hash = "sha256:8e17ae5e46d8e7efe51ab6494dd2010f4ca8dae51652aa3c8d55acf50bfb2e99"},
|
||||
{file = "pytest_asyncio-1.2.0.tar.gz", hash = "sha256:c609a64a2a8768462d0c99811ddb8bd2583c33fd33cf7f21af1c142e824ffb57"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
pytest = ">=8.2,<9"
|
||||
typing-extensions = {version = ">=4.12", markers = "python_version < \"3.13\""}
|
||||
|
||||
[package.extras]
|
||||
docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1)"]
|
||||
testing = ["coverage (>=6.2)", "hypothesis (>=5.7.1)"]
|
||||
|
||||
[[package]]
|
||||
name = "pytest-randomly"
|
||||
version = "3.16.0"
|
||||
description = "Pytest plugin to randomly order tests and control random.seed."
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
groups = ["test"]
|
||||
files = [
|
||||
{file = "pytest_randomly-3.16.0-py3-none-any.whl", hash = "sha256:8633d332635a1a0983d3bba19342196807f6afb17c3eef78e02c2f85dade45d6"},
|
||||
{file = "pytest_randomly-3.16.0.tar.gz", hash = "sha256:11bf4d23a26484de7860d82f726c0629837cf4064b79157bd18ec9d41d7feb26"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
pytest = "*"
|
||||
|
||||
[[package]]
|
||||
name = "typing-extensions"
|
||||
version = "4.15.0"
|
||||
description = "Backported and Experimental Type Hints for Python 3.9+"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
groups = ["main", "test"]
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "typing_extensions-4.15.0-py3-none-any.whl", hash = "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548"},
|
||||
{file = "typing_extensions-4.15.0.tar.gz", hash = "sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466"},
|
||||
]
|
||||
markers = {test = "python_version < \"3.13\""}
|
||||
|
||||
[[package]]
|
||||
name = "typing-inspection"
|
||||
|
|
@ -934,4 +808,4 @@ propcache = ">=0.2.1"
|
|||
[metadata]
|
||||
lock-version = "2.1"
|
||||
python-versions = ">=3.11"
|
||||
content-hash = "8ad261ff9b638f6a43a53816d78da99ecb5fa8f32397e8fcb142ce7e7260e9bc"
|
||||
content-hash = "11201d4008a14740f88f3639c07c98395d62f610d89918beae58e58453da20fc"
|
||||
|
|
|
|||
|
|
@ -15,10 +15,6 @@ dependencies = [
|
|||
[tool.poetry]
|
||||
packages = [{include = "TaxisLibrary", from = "src"}]
|
||||
|
||||
[tool.poetry.group.test.dependencies]
|
||||
pytest-randomly = "^3.15.0"
|
||||
pytest = "^8.2.0"
|
||||
pytest-asyncio = "^1.2.0"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
||||
|
|
|
|||
|
|
@ -209,19 +209,16 @@ class HTTPValidationError(BaseModel):
|
|||
detail: List[ValidationError]
|
||||
|
||||
# Resolve forward references
|
||||
CarOut.model_rebuild()
|
||||
ClientOut.model_rebuild()
|
||||
DriverOut.model_rebuild()
|
||||
OrderOut.model_rebuild()
|
||||
CarOut.update_forward_refs()
|
||||
ClientOut.update_forward_refs()
|
||||
DriverOut.update_forward_refs()
|
||||
OrderOut.update_forward_refs()
|
||||
|
||||
# Client
|
||||
class TaxisClient:
|
||||
def __init__(self, base_url: str, api_key: Optional[str] = None):
|
||||
self.base_url = base_url.rstrip('/')
|
||||
self.api_key = api_key
|
||||
self.headers={
|
||||
"Authorization": f"Bearer {self.api_key}" if self.api_key else ""
|
||||
}
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
|
@ -230,11 +227,15 @@ class TaxisClient:
|
|||
pass
|
||||
|
||||
|
||||
async def _request(self, method: str, endpoint: str, **kwargs) -> Any:
|
||||
async def _request(self, method: str, endpoint: str, params: Dict[str, Any] = None, json_data: Dict[str, Any] = None) -> Any:
|
||||
url = f"{self.base_url}/{endpoint.strip('/')}"
|
||||
|
||||
async with aiohttp.ClientSession(headers=self.headers) as session:
|
||||
async with session.request(method, url, **kwargs) as resp:
|
||||
params = params or {}
|
||||
json_data = json_data or {}
|
||||
headers={
|
||||
"Authorization": f"Bearer {self.api_key}" if self.api_key else None
|
||||
}
|
||||
async with aiohttp.ClientSession(headers=headers) as session:
|
||||
async with session.request(method, url, params=params, json=json_data) as resp:
|
||||
if resp.status == 401:
|
||||
raise Exception("Unauthorized")
|
||||
resp.raise_for_status()
|
||||
|
|
@ -244,18 +245,19 @@ class TaxisClient:
|
|||
return await resp.text()
|
||||
|
||||
async def login(self, username: str, password: str, grant_type: str = "password",
|
||||
scope: str = "") -> 'ApiKeyOut':
|
||||
scope: str = "", client_id: Optional[str] = None,
|
||||
client_secret: Optional[str] = None) -> 'ApiKeyOut':
|
||||
data = {
|
||||
"grant_type": grant_type,
|
||||
"username": username,
|
||||
"password": password,
|
||||
"scope": scope,
|
||||
"client_id": "taxi",
|
||||
"client_secret": "taxi"
|
||||
"client_id": client_id,
|
||||
"client_secret": client_secret
|
||||
}
|
||||
result = await self._request("POST", "/auth/login", data=data)
|
||||
self.api_key = result["api_key"]
|
||||
self.headers.update({"Authorization": f"Bearer {self.api_key}"})
|
||||
self.session.headers.update({"Authorization": f"Bearer {self.api_key}"})
|
||||
return ApiKeyOut(**result)
|
||||
|
||||
# Prompts
|
||||
|
|
@ -264,7 +266,7 @@ class TaxisClient:
|
|||
return [PromptOut(**item) for item in result]
|
||||
|
||||
async def create_prompt(self, prompt: 'PromptIn') -> 'PromptOut':
|
||||
result = await self._request("POST", "/prompts/", json=prompt.dict())
|
||||
result = await self._request("POST", "/prompts/", json_data=prompt.dict())
|
||||
return PromptOut(**result)
|
||||
|
||||
async def get_prompt(self, prompt_id: int, **params) -> 'PromptOut':
|
||||
|
|
@ -272,7 +274,7 @@ class TaxisClient:
|
|||
return PromptOut(**result)
|
||||
|
||||
async def update_prompt(self, prompt_id: int, prompt: 'PromptIn') -> 'PromptOut':
|
||||
result = await self._request("PUT", f"/prompts/{prompt_id}", json=prompt.dict())
|
||||
result = await self._request("PUT", f"/prompts/{prompt_id}", json_data=prompt.dict())
|
||||
return PromptOut(**result)
|
||||
|
||||
async def delete_prompt(self, prompt_id: int) -> None:
|
||||
|
|
@ -284,7 +286,7 @@ class TaxisClient:
|
|||
return [CarOut(**item) for item in result]
|
||||
|
||||
async def create_car(self, car: 'CarIn') -> 'CarOut':
|
||||
result = await self._request("POST", "/cars/", json=car.dict())
|
||||
result = await self._request("POST", "/cars/", json_data=car.dict())
|
||||
return CarOut(**result)
|
||||
|
||||
async def get_car(self, car_id: int, **params) -> 'CarOut':
|
||||
|
|
@ -292,7 +294,7 @@ class TaxisClient:
|
|||
return CarOut(**result)
|
||||
|
||||
async def update_car(self, car_id: int, car: 'CarIn') -> 'CarOut':
|
||||
result = await self._request("PUT", f"/cars/{car_id}", json=car.dict())
|
||||
result = await self._request("PUT", f"/cars/{car_id}", json_data=car.dict())
|
||||
return CarOut(**result)
|
||||
|
||||
async def delete_car(self, car_id: int) -> None:
|
||||
|
|
@ -304,7 +306,7 @@ class TaxisClient:
|
|||
return [DriverOut(**item) for item in result]
|
||||
|
||||
async def create_driver(self, driver: 'DriverIn') -> 'DriverOut':
|
||||
result = await self._request("POST", "/drivers/", json=driver.dict())
|
||||
result = await self._request("POST", "/drivers/", json_data=driver.dict())
|
||||
return DriverOut(**result)
|
||||
|
||||
async def get_driver(self, driver_id: int, **params) -> 'DriverOut':
|
||||
|
|
@ -316,14 +318,14 @@ class TaxisClient:
|
|||
return DriverOut(**result)
|
||||
|
||||
async def update_driver(self, driver_id: int, driver: 'DriverIn') -> 'DriverOut':
|
||||
result = await self._request("PUT", f"/drivers/{driver_id}", json=driver.dict())
|
||||
result = await self._request("PUT", f"/drivers/{driver_id}", json_data=driver.dict())
|
||||
return DriverOut(**result)
|
||||
|
||||
async def delete_driver(self, driver_id: int) -> None:
|
||||
await self._request("DELETE", f"/drivers/{driver_id}")
|
||||
|
||||
async def update_driver_address(self, driver_id: int, address: 'DriverAddressUpdate') -> 'DriverOut':
|
||||
result = await self._request("PUT", f"/drivers/{driver_id}/address", json=address.dict())
|
||||
result = await self._request("PUT", f"/drivers/{driver_id}/address", json_data=address.dict())
|
||||
return DriverOut(**result)
|
||||
|
||||
async def update_driver_status(self, driver_id: int, status: 'DriverStatus') -> 'DriverOut':
|
||||
|
|
@ -352,7 +354,7 @@ class TaxisClient:
|
|||
return [ClientOut(**item) for item in result]
|
||||
|
||||
async def create_client(self, client: 'ClientIn') -> 'ClientOut':
|
||||
result = await self._request("POST", "/clients/", json=client.dict())
|
||||
result = await self._request("POST", "/clients/", json_data=client.dict())
|
||||
return ClientOut(**result)
|
||||
|
||||
async def get_client(self, client_id: int, **params) -> 'ClientOut':
|
||||
|
|
@ -364,7 +366,7 @@ class TaxisClient:
|
|||
return ClientOut(**result)
|
||||
|
||||
async def update_client(self, client_id: int, client: 'ClientIn') -> 'ClientOut':
|
||||
result = await self._request("PUT", f"/clients/{client_id}", json=client.dict())
|
||||
result = await self._request("PUT", f"/clients/{client_id}", json_data=client.dict())
|
||||
return ClientOut(**result)
|
||||
|
||||
async def delete_client(self, client_id: int) -> None:
|
||||
|
|
@ -376,7 +378,7 @@ class TaxisClient:
|
|||
return [OrderOut(**item) for item in result]
|
||||
|
||||
async def create_order(self, order: 'OrderIn') -> 'OrderOut':
|
||||
result = await self._request("POST", "/orders/", json=order.dict())
|
||||
result = await self._request("POST", "/orders/", json_data=order.dict())
|
||||
return OrderOut(**result)
|
||||
|
||||
async def get_order(self, order_id: int, **params) -> 'OrderOut':
|
||||
|
|
@ -384,7 +386,7 @@ class TaxisClient:
|
|||
return OrderOut(**result)
|
||||
|
||||
async def update_order(self, order_id: int, order: 'OrderInUpdate') -> 'OrderOut':
|
||||
result = await self._request("PUT", f"/orders/{order_id}", json=order.dict())
|
||||
result = await self._request("PUT", f"/orders/{order_id}", json_data=order.dict())
|
||||
return OrderOut(**result)
|
||||
|
||||
async def delete_order(self, order_id: int) -> None:
|
||||
|
|
@ -408,7 +410,7 @@ class TaxisClient:
|
|||
return [OrderNotificationsOut(**item) for item in result]
|
||||
|
||||
async def create_order_notification(self, notification: 'OrderNotificationsIn') -> 'OrderNotificationsOut':
|
||||
result = await self._request("POST", "/order_notifications/", json=notification.dict())
|
||||
result = await self._request("POST", "/order_notifications/", json_data=notification.dict())
|
||||
return OrderNotificationsOut(**result)
|
||||
|
||||
async def get_order_notification(self, notification_id: int, **params) -> 'OrderNotificationsOut':
|
||||
|
|
@ -428,7 +430,7 @@ class TaxisClient:
|
|||
return GlobalSettingsOut(**result)
|
||||
|
||||
async def update_global_settings(self, settings: 'GlobalSettingsUpdate') -> 'GlobalSettingsOut':
|
||||
result = await self._request("PUT", "/settings/global", json=settings.dict())
|
||||
result = await self._request("PUT", "/settings/global", json_data=settings.dict())
|
||||
return GlobalSettingsOut(**result)
|
||||
|
||||
async def get_nominatium_settings(self, nominatium_id: int, **params) -> 'NominatiumSettingsOut':
|
||||
|
|
@ -447,9 +449,9 @@ class TaxisClient:
|
|||
return Geocode(**result)
|
||||
|
||||
async def get_distance(self, request: 'DistanceRequest') -> float:
|
||||
result = await self._request("POST", "/union/distance", json=request.dict())
|
||||
result = await self._request("POST", "/union/distance", json_data=request.dict())
|
||||
return float(result)
|
||||
|
||||
async def get_distance_by_address(self, request: 'AddressRequest') -> float:
|
||||
result = await self._request("POST", "/union/distance_by_address", json=request.dict())
|
||||
result = await self._request("POST", "/union/distance_by_address", json_data=request.dict())
|
||||
return float(result)
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
import asyncio
|
||||
|
||||
import pytest
|
||||
from TaxisLibrary.taxis_client import TaxisClient, ApiKeyOut
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
return TaxisClient("http://127.0.0.1:7000")
|
||||
|
||||
class TestLogin:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login(self, client):
|
||||
result = await client.login(username="root", password="12345")
|
||||
assert isinstance(result, ApiKeyOut)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_error(self, client):
|
||||
with pytest.raises(Exception):
|
||||
await client.login(username="root", password="123456")
|
||||
Loading…
Add table
Reference in a new issue