|
1 | 1 | import dataclasses as dc
|
2 |
| -import unittest |
3 | 2 |
|
4 | 3 | import fastapi
|
5 | 4 | import httpx
|
6 | 5 | import pydantic
|
| 6 | +import pytest |
7 | 7 | import typing_extensions as typing
|
8 | 8 | from starlette.responses import JSONResponse
|
9 | 9 |
|
@@ -144,24 +144,28 @@ async def login(
|
144 | 144 | client = CatClient(transport=httpx.ASGITransport(app=cats_app))
|
145 | 145 |
|
146 | 146 |
|
147 |
| -class TestClient(unittest.IsolatedAsyncioTestCase): |
148 |
| - async def test_request(self): |
149 |
| - response = await client.cat_list() |
150 |
| - self.assertIsInstance(response, list) |
151 |
| - self.assertEqual([Cat(id=1, name='Tom')], response) |
| 147 | +@pytest.mark.asyncio |
| 148 | +async def test_request(): |
| 149 | + response = await client.cat_list() |
| 150 | + assert isinstance(response, list) |
| 151 | + assert response == [Cat(id=1, name='Tom')] |
152 | 152 |
|
153 |
| - cat = await client.cat_get(id=1) |
154 |
| - self.assertIsInstance(cat, Cat) |
155 |
| - self.assertEqual(Cat(id=1, name='Tom'), cat) |
| 153 | + cat = await client.cat_get(id=1) |
| 154 | + assert isinstance(cat, Cat) |
| 155 | + assert cat == Cat(id=1, name='Tom') |
156 | 156 |
|
157 |
| - async def test_response_auth(self): |
158 |
| - response = await client.login(body=AuthRequest(login='login', password='passwd')) |
159 | 157 |
|
160 |
| - self.assertEqual("you're in", response.api_key) |
| 158 | +@pytest.mark.asyncio |
| 159 | +async def test_response_auth(): |
| 160 | + response = await client.login(body=AuthRequest(login='login', password='passwd')) |
161 | 161 |
|
162 |
| - async def test_error(self): |
163 |
| - try: |
164 |
| - await client.cat_get(id=7) |
165 |
| - assert False, 'Expected ServerError' |
166 |
| - except ServerError as e: |
167 |
| - self.assertEqual(e.msg, 'Cat not found') |
| 162 | + assert response.api_key == "you're in" |
| 163 | + |
| 164 | + |
| 165 | +@pytest.mark.asyncio |
| 166 | +async def test_error(): |
| 167 | + try: |
| 168 | + await client.cat_get(id=7) |
| 169 | + assert False, 'Expected ServerError' |
| 170 | + except ServerError as e: |
| 171 | + assert e.msg == 'Cat not found' |
0 commit comments