Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock csrf token in all tests. Fixes #454 #461

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions oioioi/base/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
import urllib.parse
from unittest import mock
from django.contrib.auth.models import AnonymousUser, User
from django.core.cache import cache
from django.core.exceptions import ImproperlyConfigured
Expand Down Expand Up @@ -43,6 +44,15 @@ def __exit__(self, exc_type, exc_value, traceback):

class TestCase(DjangoTestCase):

def setUp(self):
csrf_patch = mock.patch(
'django.middleware.csrf.get_token',
mock.Mock(return_value='deterministicToken')
)

csrf_patch.start()
self.addCleanup(csrf_patch.stop)

# Based on: https://github.com/revsys/django-test-plus/blob/master/test_plus/test.py#L236
def assertNumQueriesLessThan(self, num, *args, **kwargs):
func = kwargs.pop('func', None)
Expand Down
Loading