summaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2014-05-18 15:10:56 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2014-05-18 15:10:56 +0200
commit3a5709527d362a960a1a35769375412e4536839e (patch)
tree0d16ff742914585556ccc55ef75cbec162f4a271 /factory
parentb245a83019a8735d0c80c07275cd426bc60dd9f8 (diff)
downloadfactory-boy-3a5709527d362a960a1a35769375412e4536839e.tar
factory-boy-3a5709527d362a960a1a35769375412e4536839e.tar.gz
Rename 'target' to 'model'.
Diffstat (limited to 'factory')
-rw-r--r--factory/alchemy.py6
-rw-r--r--factory/base.py76
-rw-r--r--factory/containers.py14
-rw-r--r--factory/declarations.py4
-rw-r--r--factory/django.py28
-rw-r--r--factory/helpers.py2
-rw-r--r--factory/mogo.py8
-rw-r--r--factory/mongoengine.py8
8 files changed, 73 insertions, 73 deletions
diff --git a/factory/alchemy.py b/factory/alchemy.py
index b956d7e..3c91411 100644
--- a/factory/alchemy.py
+++ b/factory/alchemy.py
@@ -47,7 +47,7 @@ class SQLAlchemyModelFactory(base.Factory):
def _setup_next_sequence(cls, *args, **kwargs):
"""Compute the next available PK, based on the 'pk' database field."""
session = cls._meta.sqlalchemy_session
- model = cls._meta.target
+ model = cls._meta.model
pk = getattr(model, model.__mapper__.primary_key[0].name)
max_pk = session.query(max(pk)).one()[0]
if isinstance(max_pk, int):
@@ -56,9 +56,9 @@ class SQLAlchemyModelFactory(base.Factory):
return 1
@classmethod
- def _create(cls, target_class, *args, **kwargs):
+ def _create(cls, model_class, *args, **kwargs):
"""Create an instance of the model, and save it to the database."""
session = cls._meta.sqlalchemy_session
- obj = target_class(*args, **kwargs)
+ obj = model_class(*args, **kwargs)
session.add(obj)
return obj
diff --git a/factory/base.py b/factory/base.py
index 862556e..e5c31f7 100644
--- a/factory/base.py
+++ b/factory/base.py
@@ -41,7 +41,7 @@ class FactoryError(Exception):
class AssociatedClassError(FactoryError):
- """Exception for Factory subclasses lacking Meta.target."""
+ """Exception for Factory subclasses lacking Meta.model."""
class UnknownStrategy(FactoryError):
@@ -147,7 +147,7 @@ class FactoryMetaClass(type):
if cls._meta.abstract:
return '<%s (abstract)>' % cls.__name__
else:
- return '<%s for %s>' % (cls.__name__, cls._meta.target)
+ return '<%s for %s>' % (cls.__name__, cls._meta.model)
class BaseMeta:
@@ -189,7 +189,7 @@ class FactoryOptions(object):
to update() its return value.
"""
return [
- OptionDefault('target', None, inherit=True),
+ OptionDefault('model', None, inherit=True),
OptionDefault('abstract', False, inherit=False),
OptionDefault('strategy', CREATE_STRATEGY, inherit=True),
OptionDefault('arg_parameters', (), inherit=True),
@@ -225,8 +225,8 @@ class FactoryOptions(object):
self._fill_from_meta(meta=meta, base_meta=base_meta)
- self.target = self.factory._load_target_class(self.target)
- if self.target is None:
+ self.model = self.factory._load_model_class(self.model)
+ if self.model is None:
self.abstract = True
self.counter_reference = self._get_counter_reference()
@@ -246,10 +246,10 @@ class FactoryOptions(object):
def _get_counter_reference(self):
"""Identify which factory should be used for a shared counter."""
- if (self.target is not None
+ if (self.model is not None
and self.base_factory is not None
- and self.base_factory._meta.target is not None
- and issubclass(self.target, self.base_factory._meta.target)):
+ and self.base_factory._meta.model is not None
+ and issubclass(self.model, self.base_factory._meta.model)):
return self.base_factory
else:
return self.factory
@@ -323,7 +323,7 @@ class BaseFactory(object):
_meta = FactoryOptions()
_OLDSTYLE_ATTRIBUTES = {
- 'FACTORY_FOR': 'target',
+ 'FACTORY_FOR': 'model',
'ABSTRACT_FACTORY': 'abstract',
'FACTORY_STRATEGY': 'strategy',
'FACTORY_ARG_PARAMETERS': 'arg_parameters',
@@ -444,8 +444,8 @@ class BaseFactory(object):
return kwargs
@classmethod
- def _load_target_class(cls, class_definition):
- """Extension point for loading target classes.
+ def _load_model_class(cls, class_definition):
+ """Extension point for loading model classes.
This can be overridden in framework-specific subclasses to hook into
existing model repositories, for instance.
@@ -453,10 +453,10 @@ class BaseFactory(object):
return class_definition
@classmethod
- def _get_target_class(cls):
- """Retrieve the actual, associated target class."""
- definition = cls._meta.target
- return cls._load_target_class(definition)
+ def _get_model_class(cls):
+ """Retrieve the actual, associated model class."""
+ definition = cls._meta.model
+ return cls._load_model_class(definition)
@classmethod
def _prepare(cls, create, **kwargs):
@@ -466,7 +466,7 @@ class BaseFactory(object):
create: bool, whether to create or to build the object
**kwargs: arguments to pass to the creation function
"""
- target_class = cls._get_target_class()
+ model_class = cls._get_model_class()
kwargs = cls._adjust_kwargs(**kwargs)
# Remove 'hidden' arguments.
@@ -482,9 +482,9 @@ class BaseFactory(object):
utils.log_pprint(args, kwargs),
)
if create:
- return cls._create(target_class, *args, **kwargs)
+ return cls._create(model_class, *args, **kwargs)
else:
- return cls._build(target_class, *args, **kwargs)
+ return cls._build(model_class, *args, **kwargs)
@classmethod
def _generate(cls, create, attrs):
@@ -497,7 +497,7 @@ class BaseFactory(object):
if cls._meta.abstract:
raise FactoryError(
"Cannot generate instances of abstract factory %(f)s; "
- "Ensure %(f)s.Meta.target is set and %(f)s.Meta.abstract "
+ "Ensure %(f)s.Meta.model is set and %(f)s.Meta.abstract "
"is either not set or False." % dict(f=cls.__name__))
# Extract declarations used for post-generation
@@ -531,34 +531,34 @@ class BaseFactory(object):
pass
@classmethod
- def _build(cls, target_class, *args, **kwargs):
- """Actually build an instance of the target_class.
+ def _build(cls, model_class, *args, **kwargs):
+ """Actually build an instance of the model_class.
Customization point, will be called once the full set of args and kwargs
has been computed.
Args:
- target_class (type): the class for which an instance should be
+ model_class (type): the class for which an instance should be
built
args (tuple): arguments to use when building the class
kwargs (dict): keyword arguments to use when building the class
"""
- return target_class(*args, **kwargs)
+ return model_class(*args, **kwargs)
@classmethod
- def _create(cls, target_class, *args, **kwargs):
- """Actually create an instance of the target_class.
+ def _create(cls, model_class, *args, **kwargs):
+ """Actually create an instance of the model_class.
Customization point, will be called once the full set of args and kwargs
has been computed.
Args:
- target_class (type): the class for which an instance should be
+ model_class (type): the class for which an instance should be
created
args (tuple): arguments to use when creating the class
kwargs (dict): keyword arguments to use when creating the class
"""
- return target_class(*args, **kwargs)
+ return model_class(*args, **kwargs)
@classmethod
def build(cls, **kwargs):
@@ -705,7 +705,7 @@ class StubFactory(Factory):
class Meta:
strategy = STUB_STRATEGY
- target = containers.StubObject
+ model = containers.StubObject
@classmethod
def build(cls, **kwargs):
@@ -722,20 +722,20 @@ class BaseDictFactory(Factory):
abstract = True
@classmethod
- def _build(cls, target_class, *args, **kwargs):
+ def _build(cls, model_class, *args, **kwargs):
if args:
raise ValueError(
"DictFactory %r does not support Meta.arg_parameters.", cls)
- return target_class(**kwargs)
+ return model_class(**kwargs)
@classmethod
- def _create(cls, target_class, *args, **kwargs):
- return cls._build(target_class, *args, **kwargs)
+ def _create(cls, model_class, *args, **kwargs):
+ return cls._build(model_class, *args, **kwargs)
class DictFactory(BaseDictFactory):
class Meta:
- target = dict
+ model = dict
class BaseListFactory(Factory):
@@ -744,22 +744,22 @@ class BaseListFactory(Factory):
abstract = True
@classmethod
- def _build(cls, target_class, *args, **kwargs):
+ def _build(cls, model_class, *args, **kwargs):
if args:
raise ValueError(
"ListFactory %r does not support Meta.arg_parameters.", cls)
values = [v for k, v in sorted(kwargs.items())]
- return target_class(values)
+ return model_class(values)
@classmethod
- def _create(cls, target_class, *args, **kwargs):
- return cls._build(target_class, *args, **kwargs)
+ def _create(cls, model_class, *args, **kwargs):
+ return cls._build(model_class, *args, **kwargs)
class ListFactory(BaseListFactory):
class Meta:
- target = list
+ model = list
def use_strategy(new_strategy):
diff --git a/factory/containers.py b/factory/containers.py
index c0c5e24..5116320 100644
--- a/factory/containers.py
+++ b/factory/containers.py
@@ -47,27 +47,27 @@ class LazyStub(object):
__containers (LazyStub list): "parents" of the LazyStub being built.
This allows to have the field of a field depend on the value of
another field
- __target_class (type): the target class to build.
+ __model_class (type): the model class to build.
"""
__initialized = False
- def __init__(self, attrs, containers=(), target_class=object, log_ctx=None):
+ def __init__(self, attrs, containers=(), model_class=object, log_ctx=None):
self.__attrs = attrs
self.__values = {}
self.__pending = []
self.__containers = containers
- self.__target_class = target_class
- self.__log_ctx = log_ctx or '%s.%s' % (target_class.__module__, target_class.__name__)
+ self.__model_class = model_class
+ self.__log_ctx = log_ctx or '%s.%s' % (model_class.__module__, model_class.__name__)
self.factory_parent = containers[0] if containers else None
self.__initialized = True
def __repr__(self):
- return '<LazyStub for %s.%s>' % (self.__target_class.__module__, self.__target_class.__name__)
+ return '<LazyStub for %s.%s>' % (self.__model_class.__module__, self.__model_class.__name__)
def __str__(self):
return '<LazyStub for %s with %s>' % (
- self.__target_class.__name__, list(self.__attrs.keys()))
+ self.__model_class.__name__, list(self.__attrs.keys()))
def __fill__(self):
"""Fill this LazyStub, computing values of all defined attributes.
@@ -224,7 +224,7 @@ class AttributeBuilder(object):
wrapped_attrs[k] = v
stub = LazyStub(wrapped_attrs, containers=self._containers,
- target_class=self.factory, log_ctx=self._log_ctx)
+ model_class=self.factory, log_ctx=self._log_ctx)
return stub.__fill__()
diff --git a/factory/declarations.py b/factory/declarations.py
index 037a679..5e7e734 100644
--- a/factory/declarations.py
+++ b/factory/declarations.py
@@ -50,7 +50,7 @@ class OrderedDeclaration(object):
attributes
containers (list of containers.LazyStub): The chain of SubFactory
which led to building this object.
- create (bool): whether the target class should be 'built' or
+ create (bool): whether the model class should be 'built' or
'created'
extra (DeclarationDict or None): extracted key/value extracted from
the attribute prefix
@@ -434,7 +434,7 @@ class ExtractionContext(object):
class PostGenerationDeclaration(object):
- """Declarations to be called once the target object has been generated."""
+ """Declarations to be called once the model object has been generated."""
def extract(self, name, attrs):
"""Extract relevant attributes from a dict.
diff --git a/factory/django.py b/factory/django.py
index 77afd8c..6090145 100644
--- a/factory/django.py
+++ b/factory/django.py
@@ -61,10 +61,10 @@ class DjangoOptions(base.FactoryOptions):
def _get_counter_reference(self):
counter_reference = super(DjangoOptions, self)._get_counter_reference()
if (counter_reference == self.base_factory
- and self.base_factory._meta.target is not None
- and self.base_factory._meta.target._meta.abstract
- and self.target is not None
- and not self.target._meta.abstract):
+ and self.base_factory._meta.model is not None
+ and self.base_factory._meta.model._meta.abstract
+ and self.model is not None
+ and not self.model._meta.abstract):
# Target factory is for an abstract model, yet we're for another,
# concrete subclass => don't reuse the counter.
return self.factory
@@ -90,7 +90,7 @@ class DjangoModelFactory(base.Factory):
})
@classmethod
- def _load_target_class(cls, definition):
+ def _load_model_class(cls, definition):
if is_string(definition) and '.' in definition:
app, model = definition.split('.', 1)
@@ -100,17 +100,17 @@ class DjangoModelFactory(base.Factory):
return definition
@classmethod
- def _get_manager(cls, target_class):
+ def _get_manager(cls, model_class):
try:
- return target_class._default_manager # pylint: disable=W0212
+ return model_class._default_manager # pylint: disable=W0212
except AttributeError:
- return target_class.objects
+ return model_class.objects
@classmethod
def _setup_next_sequence(cls):
"""Compute the next available PK, based on the 'pk' database field."""
- model = cls._get_target_class() # pylint: disable=E1101
+ model = cls._get_model_class() # pylint: disable=E1101
manager = cls._get_manager(model)
try:
@@ -122,9 +122,9 @@ class DjangoModelFactory(base.Factory):
return 1
@classmethod
- def _get_or_create(cls, target_class, *args, **kwargs):
+ def _get_or_create(cls, model_class, *args, **kwargs):
"""Create an instance of the model through objects.get_or_create."""
- manager = cls._get_manager(target_class)
+ manager = cls._get_manager(model_class)
assert 'defaults' not in cls._meta.django_get_or_create, (
"'defaults' is a reserved keyword for get_or_create "
@@ -140,12 +140,12 @@ class DjangoModelFactory(base.Factory):
return obj
@classmethod
- def _create(cls, target_class, *args, **kwargs):
+ def _create(cls, model_class, *args, **kwargs):
"""Create an instance of the model, and save it to the database."""
- manager = cls._get_manager(target_class)
+ manager = cls._get_manager(model_class)
if cls._meta.django_get_or_create:
- return cls._get_or_create(target_class, *args, **kwargs)
+ return cls._get_or_create(model_class, *args, **kwargs)
return manager.create(*args, **kwargs)
diff --git a/factory/helpers.py b/factory/helpers.py
index 0c387d0..19431df 100644
--- a/factory/helpers.py
+++ b/factory/helpers.py
@@ -51,7 +51,7 @@ def make_factory(klass, **kwargs):
"""Create a new, simple factory for the given class."""
factory_name = '%sFactory' % klass.__name__
class Meta:
- target = klass
+ model = klass
kwargs['Meta'] = Meta
base_class = kwargs.pop('FACTORY_CLASS', base.Factory)
diff --git a/factory/mogo.py b/factory/mogo.py
index 0214119..5541043 100644
--- a/factory/mogo.py
+++ b/factory/mogo.py
@@ -36,11 +36,11 @@ class MogoFactory(base.Factory):
abstract = True
@classmethod
- def _build(cls, target_class, *args, **kwargs):
- return target_class.new(*args, **kwargs)
+ def _build(cls, model_class, *args, **kwargs):
+ return model_class.new(*args, **kwargs)
@classmethod
- def _create(cls, target_class, *args, **kwargs):
- instance = target_class.new(*args, **kwargs)
+ def _create(cls, model_class, *args, **kwargs):
+ instance = model_class.new(*args, **kwargs)
instance.save()
return instance
diff --git a/factory/mongoengine.py b/factory/mongoengine.py
index 729ebb1..e3ab99c 100644
--- a/factory/mongoengine.py
+++ b/factory/mongoengine.py
@@ -37,12 +37,12 @@ class MongoEngineFactory(base.Factory):
abstract = True
@classmethod
- def _build(cls, target_class, *args, **kwargs):
- return target_class(*args, **kwargs)
+ def _build(cls, model_class, *args, **kwargs):
+ return model_class(*args, **kwargs)
@classmethod
- def _create(cls, target_class, *args, **kwargs):
- instance = target_class(*args, **kwargs)
+ def _create(cls, model_class, *args, **kwargs):
+ instance = model_class(*args, **kwargs)
if instance._is_document:
instance.save()
return instance