github stars project celery-rabbit

This commit is contained in:
2021-07-06 16:36:19 +03:00
commit 70bff65fc0
85 changed files with 6716 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
"""
This module is used to provide configuration, fixtures, and plugins for pytest.
It may be also used for extending doctest's context:
1. https://docs.python.org/3/library/doctest.html
2. https://docs.pytest.org/en/latest/doctest.html
"""
import pytest
@pytest.fixture(autouse=True)
def _media_root(settings, tmpdir_factory) -> None:
"""Forces django to save media files into temp folder."""
settings.MEDIA_ROOT = tmpdir_factory.mktemp('media', numbered=True)
@pytest.fixture(autouse=True)
def _password_hashers(settings) -> None:
"""Forces django to use fast password hashers for tests."""
settings.PASSWORD_HASHERS = [
'django.contrib.auth.hashers.MD5PasswordHasher',
]
@pytest.fixture(autouse=True)
def _auth_backends(settings) -> None:
"""Deactivates security backend from Axes app."""
settings.AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
@pytest.fixture(autouse=True)
def _debug(settings) -> None:
"""Sets proper DEBUG and TEMPLATE debug mode for coverage."""
settings.DEBUG = False
for template in settings.TEMPLATES:
template['OPTIONS']['debug'] = True
@pytest.fixture()
def main_heading() -> str:
"""An example fixture containing some html fragment."""
return '<h1>wemake-django-template</h1>'

View File

@@ -0,0 +1,16 @@
from hypothesis import given
from hypothesis.extra import django
from server.apps.main.models import BlogPost
class TestBlogPost(django.TestCase):
"""This is a property-based test that ensures model correctness."""
@given(django.from_model(BlogPost))
def test_model_properties(self, instance: BlogPost) -> None:
"""Tests that instance can be saved and has correct representation."""
instance.save()
assert instance.id > 0
assert len(str(instance)) <= 20

View File

@@ -0,0 +1,17 @@
import pytest
from django_test_migrations.migrator import Migrator
from server.apps.main.urls import app_name
def test_initial0001(migrator: Migrator) -> None:
"""Tests the initial migration forward application."""
old_state = migrator.apply_initial_migration((app_name, None))
with pytest.raises(LookupError):
# This model does not exist before this migration:
old_state.apps.get_model(app_name, 'BlogPost')
new_state = migrator.apply_tested_migration((app_name, '0001_initial'))
model = new_state.apps.get_model(app_name, 'BlogPost')
assert model.objects.create(title='test', body='some body')

View File

@@ -0,0 +1,18 @@
from django.test import Client
from django.urls import reverse
def test_main_page(client: Client, main_heading: str) -> None:
"""This test ensures that main page works."""
response = client.get('/')
assert response.status_code == 200
assert main_heading in str(response.content)
def test_hello_page(client: Client, main_heading: str) -> None:
"""This test ensures that hello page works."""
response = client.get(reverse('main:hello'))
assert response.status_code == 200
assert main_heading in str(response.content)

View File

@@ -0,0 +1,55 @@
import pytest
from django.test import Client
@pytest.mark.django_db()
def test_health_check(client: Client) -> None:
"""This test ensures that health check is accessible."""
response = client.get('/health/')
assert response.status_code == 200
def test_admin_unauthorized(client: Client) -> None:
"""This test ensures that admin panel requires auth."""
response = client.get('/admin/')
assert response.status_code == 302
def test_admin_authorized(admin_client: Client) -> None:
"""This test ensures that admin panel is accessible."""
response = admin_client.get('/admin/')
assert response.status_code == 200
def test_admin_docs_unauthorized(client: Client) -> None:
"""This test ensures that admin panel docs requires auth."""
response = client.get('/admin/doc/')
assert response.status_code == 302
def test_admin_docs_authorized(admin_client: Client) -> None:
"""This test ensures that admin panel docs are accessible."""
response = admin_client.get('/admin/doc/')
assert response.status_code == 200
assert b'docutils' not in response.content
def test_robots_txt(client: Client) -> None:
"""This test ensures that `robots.txt` is accessible."""
response = client.get('/robots.txt')
assert response.status_code == 200
assert response.get('Content-Type') == 'text/plain'
def test_humans_txt(client: Client) -> None:
"""This test ensures that `humans.txt` is accessible."""
response = client.get('/humans.txt')
assert response.status_code == 200
assert response.get('Content-Type') == 'text/plain'