-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:Funtech-3/backend into dev
- Loading branch information
Showing
10 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
DJANGO_SETTINGS_MODULE = funtech.settings | ||
testpaths = tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pytest_plugins = [ | ||
'tests.fixtures.fixture_user', | ||
'tests.fixtures.fixture_data', | ||
'tests.fixtures.fixture_urls', | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from datetime import date, time, timedelta | ||
from tempfile import NamedTemporaryFile | ||
|
||
import pytest | ||
from events.models import Event, EventStep, Speaker | ||
from users.models import City, Tag | ||
|
||
LEN_OBJ_IN_LIST = 5 | ||
|
||
|
||
@pytest.fixture | ||
def cities_list(db): | ||
return City.objects.bulk_create( | ||
City(name=f'Город {index}') | ||
for index in range(LEN_OBJ_IN_LIST) | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def city(db): | ||
return City.objects.create(name='Тестовый город') | ||
|
||
|
||
@pytest.fixture | ||
def tags_list(db): | ||
return Tag.objects.bulk_create( | ||
Tag(title=f'Тег {index}') | ||
for index in range(LEN_OBJ_IN_LIST) | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def tag(db): | ||
return Tag.objects.create(title='Тестовый тег') | ||
|
||
|
||
@pytest.fixture | ||
def speaker(db): | ||
return Speaker.objects.create( | ||
first_name='Иван', | ||
last_name='Иванов', | ||
work_place='ACME', | ||
position='Работник' | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def image(): | ||
return NamedTemporaryFile(suffix='.jpg').name | ||
|
||
|
||
@pytest.fixture | ||
def event(db, city, image, tag): | ||
event = Event.objects.create( | ||
title='Тестовое событие', | ||
description='Тестовое', | ||
slug='test-event', | ||
city=city, | ||
address='Зимний дворец', | ||
date=date.today() + timedelta(days=7), | ||
image=image, | ||
) | ||
event.tags.add(tag) | ||
return event | ||
|
||
|
||
@pytest.fixture | ||
def event_steps(db, events, speaker): | ||
steps = EventStep.objects.bulk_create( | ||
EventStep( | ||
title=f'Этап события {index}', | ||
start_time=time(hour=index), | ||
description=f'Событие {index}', | ||
event=event | ||
) | ||
for index, event in enumerate(events) | ||
) | ||
for step in steps: | ||
step.speakers.add(speaker) | ||
return steps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
from django.urls import reverse | ||
|
||
|
||
@pytest.fixture | ||
def url_event_list(): | ||
return reverse('event-list') | ||
|
||
|
||
@pytest.fixture | ||
def url_event_detail(event): | ||
return reverse('event-detail', args=(event.slug,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def user(django_user_model): | ||
return django_user_model.objects.create( | ||
yandex_id=11111 | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def another_user(django_user_model): | ||
return django_user_model.objects.create( | ||
yandex_id=22222 | ||
) | ||
|
||
|
||
# @pytest.fixture | ||
# def token(user): | ||
# from rest_framework_simplejwt.tokens import RefreshToken | ||
|
||
# refresh = RefreshToken.for_user(user) | ||
# return { | ||
# 'refresh': str(refresh), | ||
# 'access': str(refresh.access_token) | ||
# } | ||
|
||
|
||
@pytest.fixture | ||
def user_client(user): | ||
from rest_framework.test import APIClient | ||
|
||
client = APIClient() | ||
# client.credentials(HTTP_AUTHORIZATION=f'Bearer {token["access"]}') | ||
client.force_authenticate(user=user) | ||
return client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from http import HTTPStatus | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.django_db(transaction=True) | ||
class TestEventAPI: | ||
"""Тесты эндпоинтов для списка событий и конкретного события.""" | ||
|
||
def check_event_response_data(self, | ||
response_data, | ||
expected_fields): | ||
for field in expected_fields: | ||
assert field in response_data, ( | ||
|
||
) | ||
|
||
def test_events_not_found(self, client, url_event_list): | ||
response = client.get(url_event_list) | ||
assert response.status_code != HTTPStatus.NOT_FOUND, ( | ||
f'Эндпоинт {url_event_list} не найден.' | ||
) | ||
|
||
def test_event_list_not_auth(self, client, url_event_list): | ||
response = client.get(url_event_list) | ||
assert response.status_code == HTTPStatus.OK, ( | ||
f'Эндпоинт {url_event_list} должен быть доступен' | ||
f'неавторизованным пользователям.' | ||
) | ||
|
||
def test_event_detail_not_auth(self, client, url_event_detail): | ||
response = client.get(url_event_detail) | ||
assert response.status_code == HTTPStatus.OK, ( | ||
f'Эндпоинт {url_event_detail} должен быть доступен' | ||
f'неавторизованным пользователям.' | ||
) |