def test_ok(self):
     signer = RegisterEmailSigner({
         'user_id': self.user.pk,
         'email': self.new_email,
     })
     data = signer.get_signed_data()
     request = self.factory.post('', data)
     response = verify_email(request)
     self.assert_valid_response(response, status.HTTP_200_OK)
     self.user.refresh_from_db()
     self.assertEqual(self.user.email, self.new_email)
 def test_noverify_not_found(self):
     signer = RegisterEmailSigner({
         'user_id': self.user.pk,
         'email': self.new_email,
     }, strict=False)
     data = signer.get_signed_data()
     request = self.factory.post('', data)
     response = verify_email(request)
     self.assert_invalid_response(response, status.HTTP_404_NOT_FOUND)
     self.user.refresh_from_db()
     self.assertEqual(self.user.email, self.email)
 def test_tampered_timestamp(self):
     signer = RegisterEmailSigner({
         'user_id': self.user.pk,
         'email': self.new_email,
     })
     data = signer.get_signed_data()
     data['timestamp'] += 1
     request = self.factory.post('', data)
     response = verify_email(request)
     self.assert_invalid_response(response, status.HTTP_400_BAD_REQUEST)
     self.user.refresh_from_db()
     self.assertEqual(self.user.email, self.email)
 def test_expired(self):
     timestamp = time.time()
     with patch('time.time', side_effect=lambda: timestamp):
         signer = RegisterEmailSigner({
             'user_id': self.user.pk,
             'email': self.new_email,
         })
         data = signer.get_signed_data()
     request = self.factory.post('', data)
     with patch('time.time', side_effect=lambda: timestamp + 3600 * 24 * 8):
         response = verify_email(request)
     self.assert_invalid_response(response, status.HTTP_400_BAD_REQUEST)
     self.user.refresh_from_db()
     self.assertEqual(self.user.email, self.email)