Skip to content

Commit

Permalink
Merge pull request #110 from paulocheque/bugfix-datafixture
Browse files Browse the repository at this point in the history
[bugfix] Fixture factory to interpret the name of the native fixtures
  • Loading branch information
paulocheque committed Jan 4, 2020
2 parents 837731e + 81543c0 commit d6e393f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
5 changes: 3 additions & 2 deletions django_dynamic_fixture/ddf.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,10 @@ def __init__(self, data_fixture, fill_nullable_fields=True, ignore_fields=[], nu
:model_path: internal variable used to control the cycles of dependencies.
"""
from django_dynamic_fixture.global_settings import DDF_IGNORE_FIELDS

from django_dynamic_fixture.fixture_algorithms import FixtureFactory
# custom config of fixtures
self.data_fixture = data_fixture
self.data_fixture = FixtureFactory.get(data_fixture)

self.fill_nullable_fields = fill_nullable_fields
self.ignore_fields = ignore_fields
# extend ignore_fields with globally declared ignore_fields
Expand Down
13 changes: 13 additions & 0 deletions django_dynamic_fixture/fixture_algorithms/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
from django_dynamic_fixture.fixture_algorithms.sequential_fixture import SequentialDataFixture, StaticSequentialDataFixture
from django_dynamic_fixture.fixture_algorithms.random_fixture import RandomDataFixture


class FixtureFactory:
@staticmethod
def get(data_fixture):
if data_fixture == 'static_sequential':
return SequentialDataFixture()
elif data_fixture == 'sequential':
return SequentialDataFixture()
elif data_fixture == 'random':
return RandomDataFixture()
return data_fixture
28 changes: 28 additions & 0 deletions django_dynamic_fixture/tests/test_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,31 @@ def test_compatibility_for_teach(self):
teach('django_dynamic_fixture.ModelWithDefaultValues', integer_with_default=5)
instance = G('django_dynamic_fixture.ModelWithDefaultValues')
assert instance.integer_with_default == 5


class OverrideDataFixture(TestCase):
def test_random(self):
instance = N('django_dynamic_fixture.ModelWithNumbers', data_fixture='random')
assert instance is not None
instance = G('django_dynamic_fixture.ModelWithNumbers', data_fixture='random')
assert instance is not None

def test_sequential(self):
instance = N('django_dynamic_fixture.ModelWithNumbers', data_fixture='sequential')
assert instance is not None
instance = G('django_dynamic_fixture.ModelWithNumbers', data_fixture='sequential')
assert instance is not None

def test_static_sequential(self):
instance = N('django_dynamic_fixture.ModelWithNumbers', data_fixture='static_sequential')
assert instance is not None
instance = G('django_dynamic_fixture.ModelWithNumbers', data_fixture='static_sequential')
assert instance is not None

def test_custom_one(self):
from django_dynamic_fixture.fixture_algorithms.sequential_fixture import SequentialDataFixture
instance = N('django_dynamic_fixture.ModelWithNumbers', data_fixture=SequentialDataFixture())
assert instance is not None
instance = G('django_dynamic_fixture.ModelWithNumbers', data_fixture=SequentialDataFixture())
assert instance is not None

0 comments on commit d6e393f

Please sign in to comment.