|
3 | 3 | import pytest
|
4 | 4 | from app.models.features import Feature
|
5 | 5 | from async_asgi_testclient import TestClient
|
6 |
| -from tests._utils.features import create_random_feature, create_random_feature_title |
| 6 | +from tests._utils.features import ( |
| 7 | + create_random_feature, |
| 8 | + create_random_feature_slug, |
| 9 | + create_random_feature_title, |
| 10 | +) |
7 | 11 | from tests._utils.guests import create_random_guest
|
8 | 12 |
|
9 | 13 |
|
10 | 14 | @pytest.mark.asyncio
|
11 |
| -async def test_feature_http_post(app): |
| 15 | +async def test_features_http_post_with_custom_slug(app): |
12 | 16 | path = "/api/features"
|
13 | 17 | async with TestClient(app) as client:
|
14 | 18 | data = {
|
15 | 19 | "title": create_random_feature_title(),
|
| 20 | + "slug": create_random_feature_slug(), |
16 | 21 | "turn_duration": randint(0, 99),
|
17 | 22 | }
|
18 | 23 | response = await client.post(path, json=data)
|
19 | 24 | assert response.status_code == 200
|
20 | 25 | content = response.json()
|
21 | 26 | assert content["title"] == data["title"]
|
| 27 | + assert content["slug"] == data["slug"] |
22 | 28 | assert content["turn_duration"] == data["turn_duration"]
|
23 | 29 | assert "id" in content
|
24 | 30 | feature = await Feature.get_or_none(pk=content["id"])
|
25 | 31 | assert feature
|
26 | 32 | assert feature.title == data["title"]
|
| 33 | + assert feature.slug == data["slug"] |
27 | 34 | assert feature.turn_duration == data["turn_duration"]
|
28 | 35 |
|
29 | 36 |
|
30 | 37 | @pytest.mark.asyncio
|
31 |
| -async def test_feature_http_get(app): |
32 |
| - path = "/api/features/{feature_id}" |
| 38 | +async def test_features_http_post_without_custom_slug(app): |
| 39 | + path = "/api/features" |
| 40 | + async with TestClient(app) as client: |
| 41 | + data = {"title": create_random_feature_title(), "turn_duration": randint(0, 99)} |
| 42 | + response = await client.post(path, json=data) |
| 43 | + assert response.status_code == 200 |
| 44 | + content = response.json() |
| 45 | + assert content["slug"].strip() |
| 46 | + assert content["title"] == data["title"] |
| 47 | + assert content["turn_duration"] == data["turn_duration"] |
| 48 | + assert "id" in content |
| 49 | + feature = await Feature.get_or_none(pk=content["id"]) |
| 50 | + assert feature |
| 51 | + assert feature.title == data["title"] |
| 52 | + assert feature.turn_duration == data["turn_duration"] |
| 53 | + |
| 54 | + |
| 55 | +@pytest.mark.asyncio |
| 56 | +async def test_features_http_get_by_id(app): |
| 57 | + path = "/api/features/{id}" |
| 58 | + async with TestClient(app) as client: |
| 59 | + random_feature = await create_random_feature() |
| 60 | + await create_random_guest(random_feature) |
| 61 | + await create_random_guest(random_feature) |
| 62 | + await create_random_guest(random_feature) |
| 63 | + response = await client.get(path.format(id=random_feature.id)) |
| 64 | + assert response.status_code == 200 |
| 65 | + content = response.json() |
| 66 | + assert content["title"] == random_feature.title |
| 67 | + assert content["turn_duration"] == random_feature.turn_duration |
| 68 | + |
| 69 | + |
| 70 | +@pytest.mark.asyncio |
| 71 | +async def test_features_http_get_by_slug(app): |
| 72 | + path = "/api/features/{slug}" |
33 | 73 | async with TestClient(app) as client:
|
34 | 74 | random_feature = await create_random_feature()
|
35 | 75 | await create_random_guest(random_feature)
|
36 | 76 | await create_random_guest(random_feature)
|
37 | 77 | await create_random_guest(random_feature)
|
38 |
| - response = await client.get(path.format(feature_id=random_feature.id)) |
| 78 | + response = await client.get(path.format(slug=random_feature.slug)) |
39 | 79 | assert response.status_code == 200
|
40 | 80 | content = response.json()
|
41 | 81 | assert content["title"] == random_feature.title
|
|
0 commit comments