Permalink
Browse files

use default if generator no explicitly defined

  • Loading branch information...
Mikko Hellsing
Mikko Hellsing committed Oct 15, 2010
1 parent f195f06 commit 1d7522152aafcd11882a8670f33f10ef6a1e4a8c
View
@@ -93,7 +93,6 @@ class AutoFixture(object):
class IGNORE_FIELD(object):
pass
- overwrite_defaults = False
follow_fk = True
generate_fk = False
follow_m2m = {'ALL': (1,5)}
@@ -121,10 +120,9 @@ class IGNORE_FIELD(object):
constraints.unique_constraint,
constraints.unique_together_constraint]
- def __init__(self, model,
- field_generators=None, overwrite_defaults=None,
- constraints=None, follow_fk=None, generate_fk=None,
- follow_m2m=None, generate_m2m=None):
+ def __init__(self, model, field_generators=None, constraints=None,
+ follow_fk=None, generate_fk=None, follow_m2m=None,
+ generate_m2m=None):
'''
Parameters:
``model``: A model class which is used to create the test data.
@@ -134,10 +132,6 @@ def __init__(self, model,
a ``Generator`` instance that generates a value on the fly or a
callable which takes no arguments and returns the wanted value.
- ``overwrite_defaults``: All default values of fields are preserved
- by default. If set to ``True``, default values will be treated
- like any other field.
-
``constraints``: A list of callables. The constraints are used to
verify if the created model instance may be used. The callable
gets the actual model as first and the instance as second
@@ -166,8 +160,6 @@ def __init__(self, model,
self.model = model
self.field_generators.update(field_generators or {})
self.constraints = constraints or []
- if overwrite_defaults is not None:
- self.overwrite_defaults = overwrite_defaults
if follow_fk is not None:
self.follow_fk = follow_fk
@@ -239,9 +231,8 @@ def get_generator(self, field):
if isinstance(field, fields.AutoField):
return None
- if field.default is not fields.NOT_PROVIDED and \
- not self.overwrite_defaults:
- return None
+ if field.default is not fields.NOT_PROVIDED:
+ return None
if field.choices:
return generators.ChoicesGenerator(choices=field.choices)
@@ -41,10 +41,6 @@ class Command(BaseCommand):
args = 'app.Model:# [app.Model:# ...]'
option_list = BaseCommand.option_list + (
- make_option('-d', '--overwrite-defaults', action='store_true',
- dest='overwrite_defaults', default=None, help=
- u'Generate values for fields with default values. Default is '
- u'to use default values.'),
make_option('--no-follow-fk', action='store_true', dest='no_follow_fk',
default=None, help=
u'Ignore foreignkeys while creating model instances.'),
@@ -180,7 +176,6 @@ def handle(self, *attrs, **options):
use = use.split('.')
use = getattr(import_module('.'.join(use[:-1])), use[-1])
- overwrite_defaults = options['overwrite_defaults']
self.verbosity = int(options['verbosity'])
models = []
@@ -209,7 +204,6 @@ def handle(self, *attrs, **options):
autofixture.autodiscover()
kwargs = {
- 'overwrite_defaults': overwrite_defaults,
'follow_fk': follow_fk,
'generate_fk': generate_fk,
'follow_m2m': follow_m2m,
@@ -27,9 +27,7 @@ def test_create(self):
self.assertEqual(BasicModel.objects.count(), 10)
def test_constraints(self):
- filler = AutoFixture(
- BasicModel,
- overwrite_defaults=False)
+ filler = AutoFixture(BasicModel)
for obj in filler.create(100):
self.assertTrue(len(obj.chars) > 0)
self.assertEqual(type(obj.chars), unicode)
@@ -377,7 +375,6 @@ def setUp(self):
from autofixture.management.commands.loadtestdata import Command
self.command = Command()
self.options = {
- 'overwrite_defaults': None,
'no_follow_fk': None,
'no_follow_m2m': None,
'generate_fk': None,

0 comments on commit 1d75221

Please sign in to comment.