Simplify database access in tests (#3807)

This commit is contained in:
Dani Hodovic 2022-07-27 00:44:34 +02:00 committed by GitHub
parent 1f92d572a8
commit 122ebfc3a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 2 additions and 22 deletions

View File

@ -10,5 +10,5 @@ def media_storage(settings, tmpdir):
@pytest.fixture
def user() -> User:
def user(db) -> User:
return UserFactory()

View File

@ -1,10 +1,7 @@
import pytest
from django.urls import reverse
from {{ cookiecutter.project_slug }}.users.models import User
pytestmark = pytest.mark.django_db
class TestUserAdmin:
def test_changelist(self, admin_client):

View File

@ -1,10 +1,7 @@
import pytest
from django.urls import resolve, reverse
from {{ cookiecutter.project_slug }}.users.models import User
pytestmark = pytest.mark.django_db
def test_user_detail(user: User):
assert (

View File

@ -1,11 +1,8 @@
import pytest
from django.test import RequestFactory
from {{ cookiecutter.project_slug }}.users.api.views import UserViewSet
from {{ cookiecutter.project_slug }}.users.models import User
pytestmark = pytest.mark.django_db
class TestUserViewSet:
def test_get_queryset(self, user: User, rf: RequestFactory):

View File

@ -1,14 +1,11 @@
"""
Module for all Form Tests.
"""
import pytest
from django.utils.translation import gettext_lazy as _
from {{ cookiecutter.project_slug }}.users.forms import UserAdminCreationForm
from {{ cookiecutter.project_slug }}.users.models import User
pytestmark = pytest.mark.django_db
class TestUserAdminCreationForm:
"""

View File

@ -1,9 +1,5 @@
import pytest
from {{ cookiecutter.project_slug }}.users.models import User
pytestmark = pytest.mark.django_db
def test_user_get_absolute_url(user: User):
assert user.get_absolute_url() == f"/users/{user.username}/"

View File

@ -1,8 +1,6 @@
import pytest
from django.urls import reverse
pytestmark = pytest.mark.django_db
def test_swagger_accessible_by_admin(admin_client):
url = reverse("api-docs")
@ -10,6 +8,7 @@ def test_swagger_accessible_by_admin(admin_client):
assert response.status_code == 200
@pytest.mark.django_db
def test_swagger_ui_not_accessible_by_normal_user(client):
url = reverse("api-docs")
response = client.get(url)

View File

@ -1,10 +1,7 @@
import pytest
from django.urls import resolve, reverse
from {{ cookiecutter.project_slug }}.users.models import User
pytestmark = pytest.mark.django_db
def test_detail(user: User):
assert (