def pytest_configure(): from django.contrib.auth.models import Group from django.conf import settings settings.SILENCED_SYSTEM_CHECKS = ['concurrency.W001'] if django.VERSION[:2] == (1.6): from concurrency.api import apply_concurrency_check from concurrency.fields import IntegerVersionField apply_concurrency_check(Group, 'version', IntegerVersionField)
def test_apply_concurrency_check(): apply_concurrency_check(Group, 'version', IntegerVersionField) instance, __ = Group.objects.get_or_create(name=next(nextgroup)) instance.save() copy = refetch(instance) copy.save() with pytest.raises(RecordModifiedError): instance.save()
class ConcurrencyTestExistingModelUser(ConcurrencyTest0): concurrency_model = User concurrency_kwargs = {'username': '******'} apply_concurrency_check(User, 'version', IntegerVersionField) def setUp(self): super(ConcurrencyTestExistingModelUser, self).setUp() self._unique_field_name = 'username' def _get_target(self): self.TARGET = User(username="******") def _get_form_data(self, **kwargs): data = { 'username': '******', 'password': "******", 'last_login': '******', 'date_joined': '2000-01-01' } data.update(**kwargs) return data
class ConcurrencyTestExistingModel(ConcurrencyTest0): """ """ apply_concurrency_check(TestModelGroup, 'version', IntegerVersionField) def setUp(self): super(ConcurrencyTestExistingModel, self).setUp() self._unique_field_name = 'name' def _get_target(self): self.TARGET = TestModelGroup(name="aaa") def _get_form_data(self, **kwargs): data = { 'last_login': datetime.datetime.today(), 'date_joined': datetime.datetime.today(), 'password': '******', 'name': 'aaa', 'username': '******' } data.update(**kwargs) return data
import django import pytest from django.test import TransactionTestCase from django.contrib.auth.models import User from django_webtest import WebTestMixin from tests.admin import admin_register_models SENTINEL = '**concurrent_update**' from concurrency.api import apply_concurrency_check from django.contrib.auth.models import Permission from concurrency.fields import IntegerVersionField apply_concurrency_check(Permission, 'version', IntegerVersionField) DJANGO_TRUNK = django.VERSION[:2] == (1, 7) skipIfDjangoTrunk = pytest.mark.skipif(DJANGO_TRUNK, reason="Skip if django == 1.7") onlyDjangoTrunk = pytest.mark.skipif(DJANGO_TRUNK, reason="Skip if django != 1.7") failIfTrunk = pytest.mark.xfail(DJANGO_TRUNK, reason="python trunk api changes") skipIfDjango14 = pytest.mark.skipif(django.VERSION[:2] == (1, 4), reason="Skip if django == 1.4") class AdminTestCase(WebTestMixin, TransactionTestCase): urls = 'tests.urls'
import django from django.contrib.auth.models import Group, User from django.test import TransactionTestCase from django.utils import timezone from demo.admin import admin_register_models from django_webtest import WebTestMixin from concurrency.api import apply_concurrency_check from concurrency.fields import IntegerVersionField SENTINEL = '**concurrent_update**' apply_concurrency_check(Group, 'version', IntegerVersionField) DJANGO_TRUNK = django.VERSION[:2] >= (1, 8) class AdminTestCase(WebTestMixin, TransactionTestCase): urls = 'demo.urls' def setUp(self): super(AdminTestCase, self).setUp() self.user, __ = User.objects.get_or_create(is_superuser=True, is_staff=True, is_active=True, last_login=timezone.now(), email='*****@*****.**',
from __future__ import unicode_literals import django from django.contrib.auth.models import Group, User from django.test import TransactionTestCase from django.utils import timezone from demo.admin import admin_register_models from django_webtest import WebTestMixin from concurrency.api import apply_concurrency_check from concurrency.fields import IntegerVersionField SENTINEL = '**concurrent_update**' apply_concurrency_check(Group, 'version', IntegerVersionField) DJANGO_TRUNK = django.VERSION[:2] >= (1, 8) class AdminTestCase(WebTestMixin, TransactionTestCase): urls = 'demo.urls' def setUp(self): super(AdminTestCase, self).setUp() self.user, __ = User.objects.get_or_create(is_superuser=True, is_staff=True, is_active=True, last_login=timezone.now(), email='*****@*****.**',
from django.contrib.auth.signals import user_logged_in from django.dispatch import receiver from mezzanine.forms.models import Form from mezzanine.pages.models import RichTextPage from concurrency.api import apply_concurrency_check from concurrency.fields import IntegerVersionField apply_concurrency_check(Form, 'version', IntegerVersionField) apply_concurrency_check(RichTextPage, 'version', IntegerVersionField) @receiver(user_logged_in) def add_just_logged_in_cookie(**kwargs): """Mark the request that a user logged in with.""" kwargs['request'].just_logged_in = True
def test_apply_concurrency_check_ignore_multiple_call(): apply_concurrency_check(Group, 'version', IntegerVersionField) apply_concurrency_check(Group, 'version', IntegerVersionField)
def test_apply_concurrency_check(model_class=SimpleConcurrentModel): try: apply_concurrency_check(Permission, 'version', IntegerVersionField) except ImproperlyConfigured: pass