I'm trying to make a unit test for the user activation process (the test for registration is done).

The function I want to test:

def signup_complete(self, data): try: code = VerificationCode.objects.select_related('user').get(code=data["code"], code_type="registration", expiration_date__gt=timezone.now()) except VerificationCode.DoesNotExist: raise NotFound(_(u"Неверный код восстановленыя"), 1001) user = code.user user.is_active = True user.save() code.delete() 

my test:

 def test_signup_complete(self): user = SiteUser.objects.get(email="test@gmail.com") code = VerificationCode.objects.create(user=user, code_type="registration", code=user.code) #data = serializers.serialize('json', [code]) data = serializers.serialize('json', [code], fields=('user', 'code')) UserService(user).signup_complete(data) self.assertEqual(user.is_active, True) 

I can't pass a parameter for the signup_complete function.

  • Unit tests are tests for individual modules and classes, not for the entire application as a whole - etki
  • Why not? You get an error, in which case add an error message to the question. I’m confused by the string serializers.serialize('json', [code], fields=('user', 'code')) although the function itself (apparently) uses dict - Kirill Ermolov
  • Yes, you're right. I redid it into dictationary and now notFound throws (_ (u "Invalid recovery code"), 1001) - Lyagu Michael

0