@@ -1,6 +1,8 @@
|
||||
from decimal import Decimal
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import IntegrityError
|
||||
from django.test import TestCase
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
@@ -103,6 +105,21 @@ class SingleDeviceLoginTests(TestCase):
|
||||
self.assertEqual(active.count(), 1)
|
||||
self.assertEqual(active.get().user_agent, "Device B")
|
||||
|
||||
def test_login_succeeds_when_device_audit_write_fails(self):
|
||||
"""设备审计表异常不能回滚已经签发的登录 Token。"""
|
||||
with patch(
|
||||
"apps.accounts.views.LoginSession.objects.create",
|
||||
side_effect=IntegrityError("device audit unavailable"),
|
||||
):
|
||||
response = APIClient().post(
|
||||
"/api/auth/login/",
|
||||
{"username": self.user.username, "password": "strong-password"},
|
||||
format="json",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("token", response.data)
|
||||
|
||||
|
||||
class InvitationFlowTests(TestCase):
|
||||
def _register(self, client, username, **extra):
|
||||
|
||||
Reference in New Issue
Block a user