42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
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)
|