mirror of
https://github.com/lemeow125/DRF_Template.git
synced 2025-09-18 13:39:56 +08:00
Implement tests
This commit is contained in:
parent
7b1d9d2b4c
commit
0baf619ace
19 changed files with 432 additions and 48 deletions
38
src/tests/users/test_user_creation_deletion.py
Normal file
38
src/tests/users/test_user_creation_deletion.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
import pytest
|
||||
import users
|
||||
|
||||
from accounts.models import CustomUser
|
||||
|
||||
|
||||
def assert_users_created():
|
||||
data = users.get_users_json()
|
||||
|
||||
for user in data["users"]:
|
||||
USER = CustomUser.objects.filter(username=user["username"]).first()
|
||||
|
||||
# Assert user exists
|
||||
assert USER
|
||||
|
||||
if user["is_superuser"]:
|
||||
# Assert is superuser
|
||||
assert USER.is_superuser
|
||||
|
||||
|
||||
def assert_users_removed():
|
||||
data = users.get_users_json()
|
||||
for user in data["users"]:
|
||||
USER = CustomUser.objects.filter(username=user["username"]).first()
|
||||
|
||||
# Assert user does not exist
|
||||
assert not USER
|
||||
|
||||
|
||||
@pytest.mark.django_db(transaction=True)
|
||||
def test_user_creation_deletion():
|
||||
"""
|
||||
Test user creation and deletion
|
||||
"""
|
||||
users.generate_test_users()
|
||||
assert_users_created()
|
||||
users.remove_test_users()
|
||||
assert_users_removed()
|
Loading…
Add table
Add a link
Reference in a new issue