我正在使用django-otp
。这是网络视图
这是我的urls.py
path('user_login/', LoginView.as_view(template_name="user_login.html",
authentication_form=SimpleOTPAuthenticationForm, redirect_authenticated_user=True), name='user_login')
这是我的.html
<form method="POST" class="form">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">Login</button>
{% endbuttons %}
</form>
这是我的表格。py
from django_otp.forms import OTPAuthenticationForm
from django import forms
class SimpleOTPAuthenticationForm(OTPAuthenticationForm):
otp_device = forms.CharField(required=False, widget=forms.HiddenInput)
otp_challenge = forms.CharField(required=False, widget=forms.HiddenInput)
models.py文件为
from django.contrib.auth.models import AbstractUser
class ProjectUser(AbstractUser):
def __str__(self):
return self.username
这是我目前对用户名和密码进行的测试
class FormTest(TestCase):
def setUp(self):
self.credentials = {
'username': 'testuser',
'password': 'secret'}
ProjectUser.objects.create_user(**self.credentials)
def test_user_password_otp_true(self):
response = self.client.post('/user_login/', self.credentials, follow=True)
self.assertTrue(response.context['user'].is_active)
如何更改测试以通过OTP以及用户名和密码?
检查此代码中的第60行-> Here is a link to a test they use