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.

test_application.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from unittest import mock
  2. from django.conf.urls import url
  3. from django.test import TestCase
  4. from django.views.generic import View
  5. from tests._site.apps.myapp.app import application
  6. class ApplicationTestCase(TestCase):
  7. def test_get_permissions_required_uses_map(self):
  8. perms = application.get_permissions('index')
  9. self.assertEqual(perms, 'is_staff')
  10. def test_permissions_required_falls_back_to_default(self):
  11. perms = application.get_permissions('notinmap')
  12. self.assertEqual(perms, 'is_superuser')
  13. @mock.patch('oscar.core.application.permissions_required')
  14. def test_get_url_decorator_fetches_correct_perms(self, mock_permissions_required):
  15. pattern = url('^$', View.as_view(), name='index')
  16. application.get_url_decorator(pattern)
  17. mock_permissions_required.assert_called_once_with('is_staff', login_url=None)
  18. def test_post_process_urls_adds_decorator(self):
  19. fake_decorator = mock.Mock()
  20. fake_decorator.return_value = 'fake_callback'
  21. application.get_url_decorator = mock.Mock()
  22. application.get_url_decorator.return_value = fake_decorator
  23. pattern = url('^$', View.as_view(), name='index')
  24. processed_patterns = application.post_process_urls([pattern])
  25. application.get_url_decorator.assert_called_once_with(pattern)
  26. self.assertEqual(processed_patterns[0].callback, 'fake_callback')