DJANGO: Как написать и запустить модульные тесты?
Когда я запускаю свои модульные тесты, я использую эту команду python manage.py test
, но мои тесты не запускаются, я получаю следующее сообщение:
System check identified 1 issue (0 silenced).
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
NOTE: Я использую MySQL Database вместо стандартного SQLite. Имеет ли это какое-либо отношение к модульным тестам?
У меня следующая иерархия файлов и папок проекта:
--[PROJECT-NAME]
------apps
----------[APP-NAME]
--------------migrations
--------------templates
--------------models.py
--------------test.py
--------------urls.py
--------------views.py
------[PROJECT-NAME]
----------settings.py
----------urls.py
------manage.py
А это мой tests.py
файл
from django.test import TestCase
from apps.accounts.models import User, Invitation
class TestModels(TestCase):
def test_sending_password_reset_email(self):
user = User.objects.create(
login = "testuser@test.com",
email = "testuser@test.com",
password = "TestPassword1!"
)
email_sent = user.send_password_reset_email()
self.assertTrue(email_sent)
def test_accepting_invitation(self):
user = User.objects.create(
login = "testuser@test.com",
email = "testuser@test.com",
password = "TestPassword1!"
)
invitation = Invitation.objects.create(created_by = user)
accepted = invitation.accept(user, "testinguser@test.com", "TestingPassword1!")
self.assertTrue(accepted)
def test_cancelling_invitation(self):
user = User.objects.create(
login = "testuser@test.com",
email = "testuser@test.com",
password = "TestPassword1!"
)
invitation = Invitation.objects.create(created_by = user)
invitation.cancel()
self.assertTrue(invitation.is_canceled)
def test_sending_invite_user_email(self):
user = User.objects.create(
login = "testuser@test.com",
email = "testuser@test.com",
password = "TestPassword1!"
)
invitation = Invitation.objects.create(created_by = user)
message = invitation.send_invite_user_email()
self.assertEqual(message, "Success")
и вот сигнатуры функций в моем models.py
:
def send_password_reset_email(self) -> bool:
.
.
.
def accept(
self,
user: User,
login: str,
password: str
) -> bool:
.
.
.
def cancel(self):
.
.
.
def send_invite_user_email(self) -> str:
.
.
.
Кто-нибудь знает, что я делаю не так? Почему мои модульные тесты не выполняются?