Skip to content

Commit

Permalink
Adding inner class for value passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmuellegger committed Aug 24, 2010
1 parent e091f15 commit 6a63793
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion autofixture/base.py
Expand Up @@ -71,6 +71,9 @@ class AutoFixture(object):
class IGNORE_FIELD(object):
pass

class Values(object):
pass

overwrite_defaults = False
follow_fk = True
generate_fk = False
Expand Down Expand Up @@ -146,7 +149,10 @@ def __init__(self, model,
will be ignored if this parameter is set.
'''
self.model = model
self.field_values = self.__class__.field_values.copy()
self.field_values = dict((
(k,v) for k,v in self.Values.__dict__.items()
if k[:2] != '__' and k[-2:] != '__' and not k.startswith('_Values__')))
self.field_values.update(self.__class__.field_values.copy())
self.field_values.update(field_values or {})
self.constraints = constraints or []
if none_chance is not None:
Expand Down
21 changes: 21 additions & 0 deletions autofixture_tests/autofixture_test/tests.py
Expand Up @@ -18,6 +18,12 @@ class SimpleAutoFixture(AutoFixture):
}


class BasicValueFixture(AutoFixture):
class Values:
chars = 'foo'
shortchars = lambda: 'a'


class TestBasicModel(TestCase):
def assertEqualOr(self, first, second, fallback):
if first != second and not fallback:
Expand Down Expand Up @@ -368,6 +374,21 @@ def test_overwrite_attributes(self):
self.assertEqual(obj.name, 'bar')


class TestAutofixtureAPI(TestCase):
def setUp(self):
self.original_registry = autofixture.REGISTRY
autofixture.REGISTRY = {}

def tearDown(self):
autofixture.REGISTRY = self.original_registry

def test_values_class(self):
autofixture.register(BasicModel, BasicValueFixture)
for obj in autofixture.create(BasicModel, 10):
self.assertEqual(obj.chars, 'foo')
self.assertEqual(obj.shortchars, 'a')


class TestManagementCommand(TestCase):
def setUp(self):
from autofixture.management.commands.loadtestdata import Command
Expand Down

0 comments on commit 6a63793

Please sign in to comment.