Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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'
Exemplo n.º 8
0
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='*****@*****.**',
Exemplo n.º 9
0
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
Exemplo n.º 11
0
def test_apply_concurrency_check_ignore_multiple_call():
    apply_concurrency_check(Group, 'version', IntegerVersionField)
    apply_concurrency_check(Group, 'version', IntegerVersionField)
Exemplo n.º 12
0
def test_apply_concurrency_check(model_class=SimpleConcurrentModel):
    try:
        apply_concurrency_check(Permission, 'version', IntegerVersionField)
    except ImproperlyConfigured:
        pass