diff --git a/tests/test_cars.py b/tests/test_cars.py new file mode 100644 index 0000000..279e445 --- /dev/null +++ b/tests/test_cars.py @@ -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) diff --git a/tests/test_clients.py b/tests/test_clients.py new file mode 100644 index 0000000..1bc8cef --- /dev/null +++ b/tests/test_clients.py @@ -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) diff --git a/tests/test_drivers.py b/tests/test_drivers.py new file mode 100644 index 0000000..e480fae --- /dev/null +++ b/tests/test_drivers.py @@ -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) diff --git a/tests/test_order_notifications.py b/tests/test_order_notifications.py new file mode 100644 index 0000000..a5397ff --- /dev/null +++ b/tests/test_order_notifications.py @@ -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) diff --git a/tests/test_orders.py b/tests/test_orders.py new file mode 100644 index 0000000..5e70294 --- /dev/null +++ b/tests/test_orders.py @@ -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) diff --git a/tests/test_union.py b/tests/test_union.py new file mode 100644 index 0000000..f93c1a5 --- /dev/null +++ b/tests/test_union.py @@ -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)