Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added test with wrong params #33

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions tests/tours/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

from src.core.tours import models

from .utils import _check_page_with_item_result, _check_page_with_list_result
from .utils import (
_check_response_with_item_result,
_check_response_with_list_result,
_check_response_with_wrong_param,
)


@pytest.mark.asyncio
Expand All @@ -12,21 +16,21 @@ class TestActivities:

async def test_list_activities(self, client, list_activities):
url = self.base_url
await _check_page_with_list_result(client, url, "locations")
await _check_response_with_list_result(client, url, "locations")

async def test_retrieve_activity(
self, client, activity_with_locations, activity_data_with_locations
):
activity_id = activity_with_locations.id
url = f"{self.base_url}/{activity_id}"
await _check_page_with_item_result(
await _check_response_with_item_result(
client, url, activity_id, activity_data_with_locations
)

async def test_list_activities_with_param_location(
self, activities_locations, client, list_activities, session, location
):
assert location is not None, "Локация не добавлена"
assert location.id is not None, "Локация не добавлена"
url = f"{self.base_url}?loc={location.id}"
response = await client.get(url)

Expand All @@ -50,28 +54,32 @@ async def test_list_activities_with_param_location(
f"к локации {location.name}"
)

async def test_list_activity_with_wrong_param(self, client, session):
url = f"{self.base_url}?loc=9999"
await _check_response_with_wrong_param(client, url)


@pytest.mark.asyncio
class TestLocation:
base_url = "/v1/locations"

async def test_list_locations(self, client, list_locations):
url = self.base_url
await _check_page_with_list_result(client, url, "activities")
await _check_response_with_list_result(client, url, "activities")

async def test_retrieve_location(
self, client, location_with_activity, location_data_with_activity
):
location_id = location_with_activity.id
url = f"{self.base_url}/{location_id}"
await _check_page_with_item_result(
await _check_response_with_item_result(
client, url, location_id, location_data_with_activity
)

async def test_list_location_with_param_activity(
self, activities_locations, client, list_activities, session, activity
):
assert activity is not None, "Активность не добавлена"
assert activity.id is not None, "Активность не добавлена"
url = f"{self.base_url}?act={activity.id}"
response = await client.get(url)

Expand All @@ -90,3 +98,7 @@ async def test_list_location_with_param_activity(
f'В "result" есть Локация не относящаяся к '
f"активности {activity.name}"
)

async def test_list_location_with_wrong_param(self, client, session):
url = f"{self.base_url}?act=9999"
await _check_response_with_wrong_param(client, url)
12 changes: 10 additions & 2 deletions tests/tours/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _validate_result(result: list[dict], related: str):
return True


async def _check_page_with_list_result(client, url: str, related: str):
async def _check_response_with_list_result(client, url: str, related: str):
response = await client.get(url)
assert response.status_code == 200, f"Страница {url} не возвращает код 200"
assert (
Expand All @@ -30,7 +30,7 @@ async def _check_page_with_list_result(client, url: str, related: str):
assert _validate_result(result, related)


async def _check_page_with_item_result(client, url, item_id, data):
async def _check_response_with_item_result(client, url, item_id, data):
response = await client.get(url)
assert response.status_code == 200, f"Страница {url} не возвращает код 200"
assert (
Expand All @@ -44,3 +44,11 @@ async def _check_page_with_item_result(client, url, item_id, data):
"id": item_id,
**data,
}, f'Данные в "result" не соответствую объекту {url}'


async def _check_response_with_wrong_param(client, url):
response = await client.get(url)
assert response.json().get("status") == "access"
assert (
response.json().get("result") == []
), 'В "result" должен быть пустой список'