Compare commits
No commits in common. "0bc6e7ab04fe22832c45cd27d04356dcaaaae0b3" and "381f11ccaf0064f3006b57995f028ab8a4669c12" have entirely different histories.
0bc6e7ab04
...
381f11ccaf
7 changed files with 4 additions and 229 deletions
|
|
@ -168,9 +168,9 @@ class OrderOut(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class OrderNotificationsIn(BaseModel):
|
class OrderNotificationsIn(BaseModel):
|
||||||
order_id: int
|
order: int
|
||||||
notify_side: OrderNotifySide = Field(default=OrderNotifySide.CLIENT)
|
notify_side: OrderNotifySide
|
||||||
notify_type: OrderNotifyType = Field(default=OrderNotifyType.DRIVER_ARRIVED)
|
notify_type: OrderNotifyType
|
||||||
processed: Optional[bool] = False
|
processed: Optional[bool] = False
|
||||||
|
|
||||||
class OrderNotificationsOut(BaseModel):
|
class OrderNotificationsOut(BaseModel):
|
||||||
|
|
@ -416,7 +416,7 @@ class TaxisClient:
|
||||||
return OrderNotificationsOut(**result)
|
return OrderNotificationsOut(**result)
|
||||||
|
|
||||||
async def mark_order_notification_processed(self, notification_id: int, processed: bool) -> 'OrderNotificationsOut':
|
async def mark_order_notification_processed(self, notification_id: int, processed: bool) -> 'OrderNotificationsOut':
|
||||||
result = await self._request("PATCH", f"/order_notifications/{notification_id}/processed", params={"processed": str(processed).lower()})
|
result = await self._request("PATCH", f"/order_notifications/{notification_id}/processed", params={"processed": processed})
|
||||||
return OrderNotificationsOut(**result)
|
return OrderNotificationsOut(**result)
|
||||||
|
|
||||||
async def delete_order_notification(self, notification_id: int) -> None:
|
async def delete_order_notification(self, notification_id: int) -> None:
|
||||||
|
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
import pytest
|
|
||||||
import asyncio
|
|
||||||
from TaxisLibrary.taxis_client import TaxisClient, CarIn, CarOut
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def client():
|
|
||||||
client = TaxisClient("http://127.0.0.1:7000")
|
|
||||||
asyncio.run(client.login("root", "12345"))
|
|
||||||
return client
|
|
||||||
|
|
||||||
class TestCars:
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_create_car(self, client):
|
|
||||||
car = CarIn(mark="Test", model="Model", color="Red", number="ABC123")
|
|
||||||
result = await client.create_car(car)
|
|
||||||
assert isinstance(result, CarOut)
|
|
||||||
await client.delete_car(result.id)
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_list_cars(self, client):
|
|
||||||
result = await client.list_cars()
|
|
||||||
assert isinstance(result, list)
|
|
||||||
if result:
|
|
||||||
assert all(isinstance(c, CarOut) for c in result)
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_get_car(self, client):
|
|
||||||
car = CarIn(mark="Test", model="Model", color="Blue", number="XYZ123")
|
|
||||||
created = await client.create_car(car)
|
|
||||||
got = await client.get_car(created.id)
|
|
||||||
assert isinstance(got, CarOut)
|
|
||||||
await client.delete_car(created.id)
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_update_car(self, client):
|
|
||||||
car = CarIn(mark="Test", model="Model", color="Black", number="QWE123")
|
|
||||||
created = await client.create_car(car)
|
|
||||||
updated_data = CarIn(mark="Upd", model="Model2", color="White", number="QWE124")
|
|
||||||
updated = await client.update_car(created.id, updated_data)
|
|
||||||
assert isinstance(updated, CarOut)
|
|
||||||
await client.delete_car(updated.id)
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
import pytest, asyncio
|
|
||||||
from TaxisLibrary.taxis_client import TaxisClient, ClientIn, ClientOut
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def client():
|
|
||||||
c = TaxisClient("http://127.0.0.1:7000")
|
|
||||||
asyncio.run(c.login("root", "12345"))
|
|
||||||
return c
|
|
||||||
|
|
||||||
class TestClients:
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_create_and_get_client(self, client):
|
|
||||||
c_in = ClientIn(name="Petya", phone="79281234569")
|
|
||||||
created = await client.create_client(c_in)
|
|
||||||
assert isinstance(created, ClientOut)
|
|
||||||
got = await client.get_client(created.id)
|
|
||||||
assert isinstance(got, ClientOut)
|
|
||||||
await client.delete_client(created.id)
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_list_clients(self, client):
|
|
||||||
result = await client.list_clients()
|
|
||||||
assert isinstance(result, list)
|
|
||||||
if result:
|
|
||||||
assert all(isinstance(c, ClientOut) for c in result)
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
import pytest, asyncio
|
|
||||||
from TaxisLibrary.taxis_client import TaxisClient, DriverIn, DriverOut, DriverAddressUpdate, DriverStatus
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def client():
|
|
||||||
c = TaxisClient("http://127.0.0.1:7000")
|
|
||||||
asyncio.run(c.login("root", "12345"))
|
|
||||||
return c
|
|
||||||
|
|
||||||
class TestDrivers:
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_create_driver(self, client):
|
|
||||||
driver = DriverIn(name="Ivan", phone="+79281234567")
|
|
||||||
result = await client.create_driver(driver)
|
|
||||||
assert isinstance(result, DriverOut)
|
|
||||||
await client.delete_driver(result.id)
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_get_and_update_driver(self, client):
|
|
||||||
d = await client.create_driver(DriverIn(name="Test", phone="+79281234568"))
|
|
||||||
got = await client.get_driver(d.id)
|
|
||||||
assert isinstance(got, DriverOut)
|
|
||||||
updated = await client.update_driver(d.id, DriverIn(name="Updated", phone="79281234568"))
|
|
||||||
assert isinstance(updated, DriverOut)
|
|
||||||
await client.delete_driver(d.id)
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_update_driver_status_and_address(self, client):
|
|
||||||
d = await client.create_driver(DriverIn(name="Status", phone="79281234569"))
|
|
||||||
await client.update_driver_status(d.id, DriverStatus.FREE)
|
|
||||||
await client.update_driver_address(d.id, DriverAddressUpdate(address="город Ставрополь улица Мира 10"))
|
|
||||||
await client.delete_driver(d.id)
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
import pytest, asyncio
|
|
||||||
from TaxisLibrary.taxis_client import (
|
|
||||||
TaxisClient, OrderNotificationsIn, OrderNotificationsOut,
|
|
||||||
OrderNotifySide, OrderNotifyType,
|
|
||||||
ClientIn, ClientOut, OrderIn, OrderOut
|
|
||||||
)
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def client():
|
|
||||||
c = TaxisClient("http://127.0.0.1:7000")
|
|
||||||
asyncio.run(c.login("root", "12345"))
|
|
||||||
return c
|
|
||||||
|
|
||||||
class TestOrderNotifications:
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_create_and_process_notification(self, client):
|
|
||||||
# создаём клиента
|
|
||||||
created_client = await client.get_client_by_phone("79281230010")
|
|
||||||
if not created_client:
|
|
||||||
c_in = ClientIn(phone="79281230010")
|
|
||||||
created_client = await client.create_client(c_in)
|
|
||||||
|
|
||||||
# создаём заказ
|
|
||||||
order_in = OrderIn(
|
|
||||||
client_id=created_client.id,
|
|
||||||
from_address="Город Ставрополь улица Ленина 1",
|
|
||||||
to_address="Город Ставрополь улица Мира 10"
|
|
||||||
)
|
|
||||||
created_order = await client.create_order(order_in)
|
|
||||||
|
|
||||||
# создаём уведомление по заказу
|
|
||||||
n_in = OrderNotificationsIn(
|
|
||||||
order_id=created_order.id,
|
|
||||||
notify_side=OrderNotifySide.CLIENT.value,
|
|
||||||
notify_type=OrderNotifyType.CANCELED_BY_CLIENT.value
|
|
||||||
)
|
|
||||||
created_notification = await client.create_order_notification(n_in)
|
|
||||||
assert isinstance(created_notification, OrderNotificationsOut)
|
|
||||||
|
|
||||||
# помечаем как обработанное
|
|
||||||
processed = await client.mark_order_notification_processed(created_notification.id, True)
|
|
||||||
assert processed.processed is True
|
|
||||||
|
|
||||||
# чистим
|
|
||||||
await client.delete_order_notification(created_notification.id)
|
|
||||||
await client.delete_order(created_order.id)
|
|
||||||
await client.delete_client(created_client.id)
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
import pytest, asyncio
|
|
||||||
from TaxisLibrary.taxis_client import (
|
|
||||||
TaxisClient, OrderIn, OrderOut, OrderStatus,
|
|
||||||
ClientIn, ClientOut, DriverIn, DriverOut
|
|
||||||
)
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def client():
|
|
||||||
c = TaxisClient("http://127.0.0.1:7000")
|
|
||||||
asyncio.run(c.login("root", "12345"))
|
|
||||||
return c
|
|
||||||
|
|
||||||
class TestOrders:
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_create_and_update_order(self, client):
|
|
||||||
# создаём клиента
|
|
||||||
c_in = ClientIn(name="Пётр", phone="+79281230001")
|
|
||||||
created_client = await client.create_client(c_in)
|
|
||||||
|
|
||||||
# создаём заказ с корректными адресами
|
|
||||||
order = OrderIn(
|
|
||||||
client_id=created_client.id,
|
|
||||||
from_address="Город Ставрополь улица Ленина 1",
|
|
||||||
to_address="Город Ставрополь улица Мира 10"
|
|
||||||
)
|
|
||||||
created_order = await client.create_order(order)
|
|
||||||
assert isinstance(created_order, OrderOut)
|
|
||||||
|
|
||||||
# обновляем статус
|
|
||||||
updated = await client.update_order_status(created_order.id, OrderStatus.SEARCHING_TAXI)
|
|
||||||
assert isinstance(updated, OrderOut)
|
|
||||||
|
|
||||||
# чистим
|
|
||||||
await client.delete_order(created_order.id)
|
|
||||||
await client.delete_client(created_client.id)
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_list_orders(self, client):
|
|
||||||
result = await client.list_orders()
|
|
||||||
assert isinstance(result, list)
|
|
||||||
if result:
|
|
||||||
assert all(isinstance(o, OrderOut) for o in result)
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
import pytest, asyncio
|
|
||||||
from TaxisLibrary.taxis_client import TaxisClient, AddressRequest, DistanceRequest, Geocode
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def client():
|
|
||||||
c = TaxisClient("http://127.0.0.1:7000")
|
|
||||||
asyncio.run(c.login("root", "12345"))
|
|
||||||
return c
|
|
||||||
|
|
||||||
class TestUnion:
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_geocode_address(self, client):
|
|
||||||
result = await client.geocode_address("Город Ставрополь улица Мира 10")
|
|
||||||
assert isinstance(result, Geocode)
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_distance(self, client):
|
|
||||||
req = DistanceRequest(
|
|
||||||
coord_from=Geocode(latitude=45.0428, longitude=41.9734), # координаты центра Ставрополя
|
|
||||||
coord_to=Geocode(latitude=45.0450, longitude=41.9800) # точка рядом
|
|
||||||
)
|
|
||||||
result = await client.get_distance(req)
|
|
||||||
assert isinstance(result, float)
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_distance_by_address(self, client):
|
|
||||||
req = AddressRequest(
|
|
||||||
address_from="Город Ставрополь улица Доваторцев 10",
|
|
||||||
address_to="Город Ставрополь улица Мира 10"
|
|
||||||
)
|
|
||||||
result = await client.get_distance_by_address(req)
|
|
||||||
assert isinstance(result, float)
|
|
||||||
Loading…
Add table
Reference in a new issue