mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-01-24 16:24:14 +03:00
Simplify database access in tests (#3807)
This commit is contained in:
parent
1f92d572a8
commit
122ebfc3a8
|
@ -10,5 +10,5 @@ def media_storage(settings, tmpdir):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def user() -> User:
|
||||
def user(db) -> User:
|
||||
return UserFactory()
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
"""
|
||||
|
|
|
@ -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}/"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 (
|
||||
|
|
Loading…
Reference in New Issue
Block a user