Skip to content

Commit

Permalink
Ensure that test doesn't autocreate users before
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 committed Nov 10, 2024
1 parent 749f76a commit 10769db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 14 additions & 3 deletions tin/apps/users/tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
from __future__ import annotations

import pytest
from django.contrib.auth import get_user_model
from django.core.management import call_command


@pytest.mark.no_autocreate_users
def test_create_debug_users():
admin = get_user_model().objects.filter(username="admin", is_superuser=True)
student = get_user_model().objects.filter(username="student", is_student=True)
teacher = get_user_model().objects.filter(username="teacher", is_teacher=True)

assert not admin.exists()
assert not teacher.exists()
assert not student.exists()

call_command("create_debug_users", noinput=True, verbosity=0)
assert get_user_model().objects.filter(username="admin", is_superuser=True)
assert get_user_model().objects.filter(username="student", is_student=True)
assert get_user_model().objects.filter(username="teacher", is_teacher=True)

assert admin.exists()
assert teacher.exists()
assert student.exists()
6 changes: 4 additions & 2 deletions tin/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ def tin_setup(settings, worker_id: str, testrun_uid: str):


@pytest.fixture(autouse=True)
def create_users():
users.add_users_to_database(password=PASSWORD, verbose=False)
def create_users(request):
marker = request.node.get_closest_marker("no_autocreate_users")
if marker is None:
users.add_users_to_database(password=PASSWORD, verbose=False)


@pytest.fixture
Expand Down

0 comments on commit 10769db

Please sign in to comment.