[TEST] add basic tests
This commit is contained in:
parent
381f11ccaf
commit
87b754d767
6 changed files with 225 additions and 0 deletions
42
tests/test_cars.py
Normal file
42
tests/test_cars.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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)
|
||||
26
tests/test_clients.py
Normal file
26
tests/test_clients.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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)
|
||||
33
tests/test_drivers.py
Normal file
33
tests/test_drivers.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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)
|
||||
48
tests/test_order_notifications.py
Normal file
48
tests/test_order_notifications.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
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)
|
||||
43
tests/test_orders.py
Normal file
43
tests/test_orders.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
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)
|
||||
33
tests/test_union.py
Normal file
33
tests/test_union.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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