You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.9 KiB

  1. from django.test import RequestFactory, TestCase, override_settings
  2. from django.utils.http import urlsafe_base64_encode
  3. from django.utils.encoding import force_bytes
  4. from django.urls import reverse
  5. from rest_framework import status
  6. from ..forms import SignupForm
  7. from ..tokens import account_activation_token
  8. import re
  9. @override_settings(STATICFILES_STORAGE='django.contrib.staticfiles.storage.StaticFilesStorage')
  10. class TestActivate(TestCase):
  11. def setUp(self):
  12. # Every test needs access to the request factory.
  13. self.factory = RequestFactory()
  14. request_POST = {'username': 'username5648',
  15. 'email': 'email@example.com',
  16. 'password1': 'pwd0000Y00$$',
  17. 'password2': 'pwd0000Y00$$'}
  18. user = SignupForm(request_POST).save(commit=False)
  19. user.save()
  20. self.token = account_activation_token.make_token(user)
  21. self.uid = urlsafe_base64_encode(force_bytes(user.pk)).decode()
  22. def test_activate_invalid(self):
  23. response = self.client.get(reverse('activate', args=['wrong_uid', 'wrong_token']))
  24. self.assertEqual(response.status_code, 200)
  25. needle = '<p>Activation link is invalid!</p>'
  26. m = re.search(needle, str(response.content))
  27. self.assertTrue(m is None)
  28. def test_activate_valid(self):
  29. """we make sure code is for the /projects redirection"""
  30. response = self.client.get(reverse('activate', args=[self.uid, self.token]))
  31. # For some reason this get rejected by Travis CI
  32. # File "/usr/local/lib/python3.6/site-packages/webpack_loader/loader.py", line 26, in _load_assets with open(self.config['STATS_FILE'], encoding="utf-8") as f:
  33. # FileNotFoundError: [Errno 2] No such file or directory: '/doccano/app/server/static/webpack-stats.json'
  34. # self.assertRedirects(response, '/projects/')
  35. self.assertEqual(response.status_code, status.HTTP_302_FOUND)