Commit 485af427 authored by Volkov Gherman's avatar Volkov Gherman

Add tests on api app, with pytest lib

parent 6b0324d0
from django.test import TestCase from django.urls import reverse
# Create your tests here. import pytest
from rest_framework.test import APIClient
from rest_framework import status
@pytest.fixture
def client():
return APIClient()
@pytest.fixture
def valid_data():
return {'signer_name': 'Гвидыч', 'signer_surname': 'Ванросыч', 'signer_email': 'robogop2510@gmail.com'}
@pytest.fixture
def invalid_data():
return {'signer_name': 'Чебурашка', 'signer_surname': 'Генадьева'}
@pytest.fixture
def expected_data():
return {'id': 1, 'signer_name': 'Гвидыч', 'signer_surname': 'Ванросыч', 'signer_email': 'robogop2510@gmail.com',
'status': 'Документ отправлен на подпись, проверьте Вашу почту'}
def test_index_view_redirects_to_send_email(client):
response = client.get(reverse('index'))
assert response.status_code == status.HTTP_302_FOUND
assert response.url == reverse('send_email')
def test_get_send_document_view(client):
response = client.get(reverse('send_email'))
assert response.status_code == status.HTTP_200_OK
assert 'index.html' in response.template_name
@pytest.mark.django_db
def test_post_valid_data(client, valid_data, expected_data):
response = client.post(reverse('send_email'), valid_data)
assert response.status_code == status.HTTP_200_OK
assert response.data == expected_data
@pytest.mark.django_db
def test_post_invalid_data(client, invalid_data):
response = client.post(reverse('send_email'), invalid_data)
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.data == {'error': 'Bad Request', 'description': 'Введенные Вами данные не валидны'}
...@@ -13,6 +13,7 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ ...@@ -13,6 +13,7 @@ https://docs.djangoproject.com/en/4.2/ref/settings/
import os import os
from pathlib import Path from pathlib import Path
import pytest
from dotenv import load_dotenv from dotenv import load_dotenv
...@@ -118,7 +119,6 @@ AUTH_PASSWORD_VALIDATORS = [ ...@@ -118,7 +119,6 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
CORS_ALLOWED_ORIGINS = [ CORS_ALLOWED_ORIGINS = [
'http://localhost:8000', 'http://localhost:8000',
'http://0.0.0.0:8000', 'http://0.0.0.0:8000',
......
...@@ -11,6 +11,7 @@ then ...@@ -11,6 +11,7 @@ then
echo "PostgreSQL started" echo "PostgreSQL started"
fi fi
pytest .
python manage.py migrate --noinput python manage.py migrate --noinput
python manage.py collectstatic --no-input --clear python manage.py collectstatic --no-input --clear
......
[pytest]
DJANGO_SETTINGS_MODULE = core.settings
python_files = tests.py test_*.py *_tests.py
...@@ -5,3 +5,6 @@ python-dotenv==1.0.* ...@@ -5,3 +5,6 @@ python-dotenv==1.0.*
docusign-esign==3.22.* docusign-esign==3.22.*
django-cors-headers==4.0.* django-cors-headers==4.0.*
gunicorn==20.1.* gunicorn==20.1.*
pytest==7.3.*
pytest-django==4.5.*
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment