mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 19:56:48 +00:00
131 test modules sat next to the code they test; instances alone had 51 of them beside views.py and utils.py. They move into a tests/ package per app, and the JavaScript checks into webvirtcloud/tests/js. Each non-empty tests.py becomes tests/test_views.py; the empty generated stubs are removed. Imports of the app's own modules become absolute, paths built from __file__ go one level up, the live helper is instances.tests.livetest, and coverage omits */tests/*. The suite discovers the same 960 tests as before.
32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
from unittest.mock import patch
|
|
|
|
from django.contrib.auth import get_user_model
|
|
from django.test import TestCase
|
|
from django.urls import reverse
|
|
|
|
|
|
class AdminEmailOtpTestCase(TestCase):
|
|
"""Sending the OTP QR code by email must not happen on GET."""
|
|
|
|
def setUp(self):
|
|
User = get_user_model()
|
|
self.superuser = User.objects.create_superuser(
|
|
username="otp_super", email="otp_super@example.com", password="x"
|
|
)
|
|
self.user = User.objects.create_user(
|
|
username="otp_user", email="otp_user@example.com", password="x"
|
|
)
|
|
self.client.force_login(self.superuser)
|
|
self.url = reverse("accounts:admin_email_otp", args=[self.user.id])
|
|
|
|
@patch("accounts.views.send_email_with_otp")
|
|
def test_get_does_not_send_email(self, mock_send):
|
|
response = self.client.get(self.url)
|
|
self.assertEqual(response.status_code, 405)
|
|
mock_send.assert_not_called()
|
|
|
|
@patch("accounts.views.send_email_with_otp")
|
|
def test_post_sends_email(self, mock_send):
|
|
response = self.client.post(self.url)
|
|
self.assertEqual(response.status_code, 302)
|
|
mock_send.assert_called_once()
|