Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
dj-kaos / building_blocks / test_abstracts.py
Size: Mime:
import pytest
from django.core.exceptions import ValidationError

from test_example.test_app.models import HasChildren


class TestHasParentModel:
    @pytest.fixture
    def parent(self, db):
        return HasChildren.objects.create()

    @pytest.fixture
    def child(self, parent):
        return HasChildren.objects.create(parent=parent)

    def test_restriction_on(self, parent, child):
        HasChildren.objects.create(parent=parent)
        with pytest.raises(ValidationError):
            HasChildren.objects.create(parent=child)

    def test_restriction_off(self, parent, child):
        HasChildren.config.extras['allow_infinite_nesting'] = True
        HasChildren.objects.create(parent=parent)
        HasChildren.objects.create(parent=child)