2015-01-22 18:29:12 +01:00
|
|
|
from unittest import TestCase
|
2016-10-01 14:26:28 +02:00
|
|
|
from unittest.mock import patch
|
2015-01-22 18:29:12 +01:00
|
|
|
|
|
|
|
from openslides.utils import views
|
|
|
|
|
|
|
|
|
2015-02-12 22:42:54 +01:00
|
|
|
class TestAPIView(TestCase):
|
|
|
|
def test_class_creation(self):
|
|
|
|
"""
|
|
|
|
Tests that the APIView has all relevant methods
|
|
|
|
"""
|
|
|
|
http_methods = set(('get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'))
|
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
http_methods.issubset(views.APIView.__dict__),
|
|
|
|
"All http methods should be defined in the APIView")
|
|
|
|
self.assertFalse(
|
|
|
|
hasattr(views.APIView, 'method_call'),
|
|
|
|
"The APIView should not have the method 'method_call'")
|
2015-02-17 20:07:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestCSRFMixin(TestCase):
|
|
|
|
@patch('builtins.super')
|
|
|
|
def test_as_view(self, mock_super):
|
|
|
|
"""
|
|
|
|
Tests, that ensure_csrf_cookie is called.
|
|
|
|
"""
|
|
|
|
mock_super().as_view.return_value = 'super_view'
|
|
|
|
with patch('openslides.utils.views.ensure_csrf_cookie') as ensure_csrf_cookie:
|
|
|
|
views.CSRFMixin.as_view()
|
|
|
|
|
|
|
|
ensure_csrf_cookie.assert_called_once_with('super_view')
|