Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

62 Zeilen
2.2 KiB

  1. from django.core.urlresolvers import reverse
  2. from django.test import TestCase
  3. from django.test.utils import override_settings
  4. import mock
  5. from .auth.backends import CombinedAuthBackend
  6. from .models import User
  7. def mock_requests_get(url, headers=None):
  8. response = mock.Mock(content=open('logo.png', 'rb').read())
  9. return response
  10. class CombinedAuthBackendTest(TestCase):
  11. def setUp(self):
  12. self.backend = CombinedAuthBackend()
  13. self.username = 'jdoe'
  14. self.email = 'jdoe@example.com'
  15. self.password = 'password'
  16. User.objects.create_user(username=self.username, email=self.email, password=self.password)
  17. def test_authenticate_username(self):
  18. self.assertTrue(self.backend.authenticate(username=self.username, password=self.password))
  19. def test_authenticate_email(self):
  20. self.assertTrue(self.backend.authenticate(username=self.email, password=self.password))
  21. def test_authenticate_wrong_password(self):
  22. self.assertIsNone(self.backend.authenticate(username=self.username, password='wrong-password'))
  23. def test_authenticate_unknown_user(self):
  24. self.assertIsNone(self.backend.authenticate(username='wrong-username', password='wrong-password'))
  25. class CreateUserTest(TestCase):
  26. def test_create_post(self):
  27. data = {
  28. 'username': 'jdoe',
  29. 'email': 'jdoe@example.com',
  30. 'password': 'password'
  31. }
  32. response = self.client.post(reverse('users:register'), data=data)
  33. self.assertRedirects(response, reverse('core:recent-pins'))
  34. self.assertIn('_auth_user_id', self.client.session)
  35. @override_settings(ALLOW_NEW_REGISTRATIONS=False)
  36. def test_create_post_not_allowed(self):
  37. response = self.client.get(reverse('users:register'))
  38. self.assertRedirects(response, reverse('core:recent-pins'))
  39. class LogoutViewTest(TestCase):
  40. def setUp(self):
  41. User.objects.create_user(username='jdoe', password='password')
  42. self.client.login(username='jdoe', password='password')
  43. def test_logout_view(self):
  44. response = self.client.get(reverse('users:logout'))
  45. self.assertRedirects(response, reverse('core:recent-pins'))