from django.test import TestCase from rest_framework.test import APIClient class OtpAuthTests(TestCase): def setUp(self): self.client = APIClient() def test_request_and_verify_otp(self): response = self.client.post( "/api/v1/auth/otp/request/", {"phone": "+79991234567"}, format="json", ) self.assertEqual(response.status_code, 200, response.data) code = response.data["debug_code"] response = self.client.post( "/api/v1/auth/otp/verify/", {"phone": "+79991234567", "code": code}, format="json", ) self.assertEqual(response.status_code, 200, response.data) self.assertIn("access", response.data) self.assertIn("refresh", response.data) self.assertEqual(response.data["user"]["phone"], "+79991234567") def test_invalid_phone_is_rejected(self): response = self.client.post( "/api/v1/auth/otp/request/", {"phone": "123"}, format="json", ) self.assertEqual(response.status_code, 400)