我有一个Participant
模型,它包含一个django.contrib.auth.model.User
,它的is_active
属性是False
。阻止这些用户自己登录。管理员用户必须使用我编写的一些使用^{
我需要在测试中验证这些用户的身份
class ParticipantFactory(factory.django.DjangoModelFactory):
class Meta:
model = Participant
user = factory.SubFactory(InactiveUserFactory)
first_location = factory.SubFactory(LocationFactory)
location = factory.SubFactory(LocationFactory)
study_id = FuzzyText(prefix='7')
class BasicTest(TestCase):
def setUp(self):
self.u = User.objects.create_user(
'test_user', 'test@example.com', 'test_pass')
self.u.is_active = False
self.u.save()
self.participant = ParticipantFactory(user=self.u)
# This works but has no effect on the tests
auth = authenticate(username=self.u.username, password='test_pass')
assert(auth is not None)
# This fails because the user is inactive
# login = self.client.login(username=self.u.username,
# password='test_pass')
# assert(login is True)
有人知道如何认证这个不活跃的用户吗?在
我可以在登录之前将用户设置为活动状态来解决此问题:
相关问题 更多 >
编程相关推荐