diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2014-05-18 15:10:56 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2014-05-18 15:10:56 +0200 |
commit | 3a5709527d362a960a1a35769375412e4536839e (patch) | |
tree | 0d16ff742914585556ccc55ef75cbec162f4a271 /docs | |
parent | b245a83019a8735d0c80c07275cd426bc60dd9f8 (diff) | |
download | factory-boy-3a5709527d362a960a1a35769375412e4536839e.tar factory-boy-3a5709527d362a960a1a35769375412e4536839e.tar.gz |
Rename 'target' to 'model'.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/examples.rst | 4 | ||||
-rw-r--r-- | docs/introduction.rst | 24 | ||||
-rw-r--r-- | docs/orms.rst | 18 | ||||
-rw-r--r-- | docs/recipes.rst | 30 | ||||
-rw-r--r-- | docs/reference.rst | 106 |
5 files changed, 91 insertions, 91 deletions
diff --git a/docs/examples.rst b/docs/examples.rst index 52a5ef6..a57080e 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -57,7 +57,7 @@ And now, we'll define the related factories: class AccountFactory(factory.Factory): class Meta: - target = objects.Account + model = objects.Account username = factory.Sequence(lambda n: 'john%s' % n) email = factory.LazyAttribute(lambda o: '%s@example.org' % o.username) @@ -65,7 +65,7 @@ And now, we'll define the related factories: class ProfileFactory(factory.Factory): class Meta: - target = objects.Profile + model = objects.Profile account = factory.SubFactory(AccountFactory) gender = factory.Iterator([objects.Profile.GENDER_MALE, objects.Profile.GENDER_FEMALE]) diff --git a/docs/introduction.rst b/docs/introduction.rst index 6ea6b5e..5e3b4d8 100644 --- a/docs/introduction.rst +++ b/docs/introduction.rst @@ -18,11 +18,11 @@ Basic usage ----------- -Factories declare a set of attributes used to instantiate an object, whose class is defined in the ``class Meta``'s ``target`` attribute: +Factories declare a set of attributes used to instantiate an object, whose class is defined in the ``class Meta``'s ``model`` attribute: - Subclass ``factory.Factory`` (or a more suitable subclass) - Add a ``class Meta:`` block -- Set its ``target`` attribute to the target class +- Set its ``model`` attribute to the target class - Add defaults for keyword args to pass to the associated class' ``__init__`` method @@ -33,7 +33,7 @@ Factories declare a set of attributes used to instantiate an object, whose class class UserFactory(factory.Factory): class Meta: - target = base.User + model = base.User firstname = "John" lastname = "Doe" @@ -59,7 +59,7 @@ A given class may be associated to many :class:`~factory.Factory` subclasses: class EnglishUserFactory(factory.Factory): class Meta: - target = base.User + model = base.User firstname = "John" lastname = "Doe" @@ -68,7 +68,7 @@ A given class may be associated to many :class:`~factory.Factory` subclasses: class FrenchUserFactory(factory.Factory): class Meta: - target = base.User + model = base.User firstname = "Jean" lastname = "Dupont" @@ -93,7 +93,7 @@ This is achieved with the :class:`~factory.Sequence` declaration: class UserFactory(factory.Factory): class Meta: - target = models.User + model = models.User username = factory.Sequence(lambda n: 'user%d' % n) @@ -110,7 +110,7 @@ This is achieved with the :class:`~factory.Sequence` declaration: class UserFactory(factory.Factory): class Meta: - target = models.User + model = models.User @factory.sequence def username(n): @@ -128,7 +128,7 @@ taking the object being built and returning the value for the field: class UserFactory(factory.Factory): class Meta: - target = models.User + model = models.User username = factory.Sequence(lambda n: 'user%d' % n) email = factory.LazyAttribute(lambda obj: '%s@example.com' % obj.username) @@ -154,7 +154,7 @@ taking the object being built and returning the value for the field: class UserFactory(factory.Factory): class Meta: - target = models.User + model = models.User username = factory.Sequence(lambda n: 'user%d' % n) @@ -177,7 +177,7 @@ and update them with its own declarations: class UserFactory(factory.Factory): class Meta: - target = base.User + model = base.User firstname = "John" lastname = "Doe" @@ -224,7 +224,7 @@ This is handled by the :data:`~factory.FactoryOptions.arg_parameters` attribute: class MyFactory(factory.Factory): class Meta: - target = MyClass + model = MyClass arg_parameters = ('x', 'y') x = 1 @@ -262,7 +262,7 @@ Calling a :class:`~factory.Factory` subclass will provide an object through the class MyFactory(factory.Factory): class Meta: - target = MyClass + model = MyClass .. code-block:: pycon diff --git a/docs/orms.rst b/docs/orms.rst index 5ef8568..d3d98c9 100644 --- a/docs/orms.rst +++ b/docs/orms.rst @@ -32,7 +32,7 @@ All factories for a Django :class:`~django.db.models.Model` should use the This class provides the following features: - * The :attr:`~factory.FactoryOption.target` attribute also supports the ``'app.Model'`` + * The :attr:`~factory.FactoryOptions.model` attribute also supports the ``'app.Model'`` syntax * :func:`~factory.Factory.create()` uses :meth:`Model.objects.create() <django.db.models.query.QuerySet.create>` * :func:`~factory.Factory._setup_next_sequence()` selects the next unused primary key value @@ -55,7 +55,7 @@ All factories for a Django :class:`~django.db.models.Model` should use the class UserFactory(factory.django.DjangoModelFactory): class Meta: - target = 'myapp.User' # Equivalent to ``target = myapp.models.User`` + model = 'myapp.User' # Equivalent to ``model = myapp.models.User`` django_get_or_create = ('username',) username = 'john' @@ -87,12 +87,12 @@ All factories for a Django :class:`~django.db.models.Model` should use the class MyAbstractModelFactory(factory.django.DjangoModelFactory): class Meta: - target = models.MyAbstractModel + model = models.MyAbstractModel abstract = True class MyConcreteModelFactory(MyAbstractModelFactory): class Meta: - target = models.MyConcreteModel + model = models.MyConcreteModel Otherwise, factory_boy will try to get the 'next PK' counter from the abstract model. @@ -121,7 +121,7 @@ Extra fields class MyFactory(factory.django.DjangoModelFactory): class Meta: - target = models.MyModel + model = models.MyModel the_file = factory.django.FileField(filename='the_file.dat') @@ -159,7 +159,7 @@ Extra fields class MyFactory(factory.django.DjangoModelFactory): class Meta: - target = models.MyModel + model = models.MyModel the_image = factory.django.ImageField(color='blue') @@ -199,7 +199,7 @@ To work around this problem, use the :meth:`mute_signals()` decorator/context ma @factory.django.mute_signals(signals.pre_save, signals.post_save) class FooFactory(factory.django.DjangoModelFactory): class Meta: - target = models.Foo + model = models.Foo # ... @@ -252,7 +252,7 @@ factory_boy supports `MongoEngine`_-style models, through the :class:`MongoEngin * :func:`~factory.Factory.create()` builds an instance through ``__init__`` then saves it. - .. note:: If the :attr:`associated class <factory.FactoryOptions.target>` is a :class:`mongoengine.EmbeddedDocument`, + .. note:: If the :attr:`associated class <factory.FactoryOptions.model` is a :class:`mongoengine.EmbeddedDocument`, the :meth:`~MongoEngineFactory.create` function won't "save" it, since this wouldn't make sense. This feature makes it possible to use :class:`~factory.SubFactory` to create embedded document. @@ -314,7 +314,7 @@ A (very) simple exemple: class UserFactory(SQLAlchemyModelFactory): class Meta: - target = User + model = User sqlalchemy_session = session # the SQLAlchemy session object id = factory.Sequence(lambda n: n) diff --git a/docs/recipes.rst b/docs/recipes.rst index 917bc3c..72dacef 100644 --- a/docs/recipes.rst +++ b/docs/recipes.rst @@ -27,7 +27,7 @@ use the :class:`~factory.SubFactory` declaration: class UserFactory(factory.django.DjangoModelFactory): class Meta: - target = models.User + model = models.User first_name = factory.Sequence(lambda n: "Agent %03d" % n) group = factory.SubFactory(GroupFactory) @@ -55,7 +55,7 @@ use a :class:`~factory.RelatedFactory` declaration: # factories.py class UserFactory(factory.django.DjangoModelFactory): class Meta: - target = models.User + model = models.User log = factory.RelatedFactory(UserLogFactory, 'user', action=models.UserLog.ACTION_CREATE) @@ -78,7 +78,7 @@ factory_boy allows to define attributes of such profiles dynamically when creati class ProfileFactory(factory.django.DjangoModelFactory): class Meta: - target = my_models.Profile + model = my_models.Profile title = 'Dr' # We pass in profile=None to prevent UserFactory from creating another profile @@ -87,7 +87,7 @@ factory_boy allows to define attributes of such profiles dynamically when creati class UserFactory(factory.django.DjangoModelFactory): class Meta: - target = auth_models.User + model = auth_models.User username = factory.Sequence(lambda n: "user_%d" % n) @@ -150,13 +150,13 @@ hook: # factories.py class GroupFactory(factory.django.DjangoModelFactory): class Meta: - target = models.Group + model = models.Group name = factory.Sequence(lambda n: "Group #%s" % n) class UserFactory(factory.django.DjangoModelFactory): class Meta: - target = models.User + model = models.User name = "John Doe" @@ -207,19 +207,19 @@ If more links are needed, simply add more :class:`RelatedFactory` declarations: # factories.py class UserFactory(factory.django.DjangoModelFactory): class Meta: - target = models.User + model = models.User name = "John Doe" class GroupFactory(factory.django.DjangoModelFactory): class Meta: - target = models.Group + model = models.Group name = "Admins" class GroupLevelFactory(factory.django.DjangoModelFactory): class Meta: - target = models.GroupLevel + model = models.GroupLevel user = factory.SubFactory(UserFactory) group = factory.SubFactory(GroupFactory) @@ -283,14 +283,14 @@ Here, we want: # factories.py class CountryFactory(factory.django.DjangoModelFactory): class Meta: - target = models.Country + model = models.Country name = factory.Iterator(["France", "Italy", "Spain"]) lang = factory.Iterator(['fr', 'it', 'es']) class UserFactory(factory.django.DjangoModelFactory): class Meta: - target = models.User + model = models.User name = "John" lang = factory.SelfAttribute('country.lang') @@ -298,7 +298,7 @@ Here, we want: class CompanyFactory(factory.django.DjangoModelFactory): class Meta: - target = models.Company + model = models.Company name = "ACME, Inc." country = factory.SubFactory(CountryFactory) @@ -315,15 +315,15 @@ default :meth:`Model.objects.create() <django.db.models.query.QuerySet.create>` class UserFactory(factory.DjangoModelFactory): class Meta: - target = UserenaSignup + model = UserenaSignup username = "l7d8s" email = "my_name@example.com" password = "my_password" @classmethod - def _create(cls, target_class, *args, **kwargs): + def _create(cls, model_class, *args, **kwargs): """Override the default ``_create`` with our custom call.""" - manager = cls._get_manager(target_class) + manager = cls._get_manager(model_class) # The default would use ``manager.create(*args, **kwargs)`` return manager.create_user(*args, **kwargs) diff --git a/docs/reference.rst b/docs/reference.rst index f19b44e..d616d1c 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -23,10 +23,10 @@ The :class:`Factory` class class MyFactory(factory.Factory): class Meta: - target = MyObject + model = MyObject abstract = False - .. attribute:: target + .. attribute:: model This optional attribute describes the class of objects to generate. @@ -40,10 +40,10 @@ The :class:`Factory` class be used to generate objects, but instead provides some extra defaults. It will be automatically set to ``True`` if neither the :class:`Factory` - subclass nor its parents define the :attr:`~FactoryOptions.target` attribute. + subclass nor its parents define the :attr:`~FactoryOptions.model` attribute. .. warning:: This flag is reset to ``False`` When a :class:`Factory` subclasses - another one if a :attr:`~FactoryOptions.target` is set. + another one if a :attr:`~FactoryOptions.model` is set. .. versionadded:: 2.4.0 @@ -57,7 +57,7 @@ The :class:`Factory` class class UserFactory(factory.Factory): class Meta: - target = User + model = User arg_parameters = ('login', 'email') login = 'john' @@ -76,7 +76,7 @@ The :class:`Factory` class While writing a :class:`Factory` for some object, it may be useful to have general fields helping defining others, but that should not be - passed to the target class; for instance, a field named 'now' that would + passed to the model class; for instance, a field named 'now' that would hold a reference time used by other objects. Factory fields whose name are listed in :attr:`hidden_args` will @@ -87,7 +87,7 @@ The :class:`Factory` class class OrderFactory(factory.Factory): class Meta: - target = Order + model = Order hidden_args = ('now',) now = factory.LazyAttribute(lambda o: datetime.datetime.utcnow()) @@ -115,7 +115,7 @@ The :class:`Factory` class .. attribute:: FACTORY_FOR .. deprecated:: 2.4.0 - See :attr:`FactoryOptions.target`. + See :attr:`FactoryOptions.model`. .. attribute:: ABSTRACT_FACTORY @@ -258,19 +258,19 @@ The :class:`Factory` class Subclasses may fetch the next free ID from the database, for instance. - .. classmethod:: _build(cls, target_class, *args, **kwargs) + .. classmethod:: _build(cls, model_class, *args, **kwargs) .. OHAI_VIM* This class method is called whenever a new instance needs to be built. - It receives the target class (provided to :attr:`~FactoryOptions.target`), and + It receives the model class (provided to :attr:`~FactoryOptions.model`), and the positional and keyword arguments to use for the class once all has been computed. Subclasses may override this for custom APIs. - .. classmethod:: _create(cls, target_class, *args, **kwargs) + .. classmethod:: _create(cls, model_class, *args, **kwargs) .. OHAI_VIM* @@ -286,8 +286,8 @@ The :class:`Factory` class class Meta: abstract = True # Optional - def _create(cls, target_class, *args, **kwargs): - obj = target_class(*args, **kwargs) + def _create(cls, model_class, *args, **kwargs): + obj = model_class(*args, **kwargs) obj.save() return obj @@ -363,7 +363,7 @@ factory_boy supports two main strategies for generating instances, plus stubs. but not persisted to any datastore. It is usually a simple call to the :meth:`~object.__init__` method of the - :attr:`~FactoryOptions.target` class. + :attr:`~FactoryOptions.model` class. .. data:: CREATE_STRATEGY @@ -386,7 +386,7 @@ factory_boy supports two main strategies for generating instances, plus stubs. when using the ``create`` strategy. That policy will be used if the - :attr:`associated class <FactoryOptions.target>` has an ``objects`` + :attr:`associated class <FactoryOptions.model` has an ``objects`` attribute *and* the :meth:`~Factory._create` classmethod of the :class:`Factory` wasn't overridden. @@ -407,7 +407,7 @@ factory_boy supports two main strategies for generating instances, plus stubs. .. data:: STUB_STRATEGY The 'stub' strategy is an exception in the factory_boy world: it doesn't return - an instance of the :attr:`~FactoryOptions.target` class, and actually doesn't + an instance of the :attr:`~FactoryOptions.model` class, and actually doesn't require one to be present. Instead, it returns an instance of :class:`StubObject` whose attributes have been @@ -485,7 +485,7 @@ accept the object being built as sole argument, and return a value. class UserFactory(factory.Factory): class Meta: - target = User + model = User username = 'john' email = factory.LazyAttribute(lambda o: '%s@example.com' % o.username) @@ -521,7 +521,7 @@ return value of the method: class UserFactory(factory.Factory) class Meta: - target = User + model = User name = u"Jean" @@ -560,7 +560,7 @@ This declaration takes a single argument, a function accepting a single paramete class UserFactory(factory.Factory) class Meta: - target = User + model = User phone = factory.Sequence(lambda n: '123-555-%04d' % n) @@ -586,7 +586,7 @@ be the sequence counter - this might be confusing: class UserFactory(factory.Factory) class Meta: - target = User + model = User @factory.sequence def phone(n): @@ -612,7 +612,7 @@ The sequence counter is shared across all :class:`Sequence` attributes of the class UserFactory(factory.Factory): class Meta: - target = User + model = User phone = factory.Sequence(lambda n: '%04d' % n) office = factory.Sequence(lambda n: 'A23-B%03d' % n) @@ -637,7 +637,7 @@ sequence counter is shared: class UserFactory(factory.Factory): class Meta: - target = User + model = User phone = factory.Sequence(lambda n: '123-555-%04d' % n) @@ -673,7 +673,7 @@ class-level value. class UserFactory(factory.Factory): class Meta: - target = User + model = User uid = factory.Sequence(int) @@ -709,7 +709,7 @@ It takes a single argument, a function whose two parameters are, in order: class UserFactory(factory.Factory): class Meta: - target = User + model = User login = 'john' email = factory.LazyAttributeSequence(lambda o, n: '%s@s%d.example.com' % (o.login, n)) @@ -734,7 +734,7 @@ handles more complex cases: class UserFactory(factory.Factory): class Meta: - target = User + model = User login = 'john' @@ -772,7 +772,7 @@ The :class:`SubFactory` attribute should be called with: class FooFactory(factory.Factory): class Meta: - target = Foo + model = Foo bar = factory.SubFactory(BarFactory) # Not BarFactory() @@ -786,7 +786,7 @@ Definition # A standard factory class UserFactory(factory.Factory): class Meta: - target = User + model = User # Various fields first_name = 'John' @@ -796,7 +796,7 @@ Definition # A factory for an object with a 'User' field class CompanyFactory(factory.Factory): class Meta: - target = Company + model = Company name = factory.Sequence(lambda n: 'FactoryBoyz' + 'z' * n) @@ -877,14 +877,14 @@ This issue can be handled by passing the absolute import path to the target class UserFactory(factory.Factory): class Meta: - target = User + model = User username = 'john' main_group = factory.SubFactory('users.factories.GroupFactory') class GroupFactory(factory.Factory): class Meta: - target = Group + model = Group name = "MyGroup" owner = factory.SubFactory(UserFactory) @@ -913,7 +913,7 @@ That declaration takes a single argument, a dot-delimited path to the attribute class UserFactory(factory.Factory) class Meta: - target = User + model = User birthdate = factory.Sequence(lambda n: datetime.date(2000, 1, 1) + datetime.timedelta(days=n)) birthmonth = factory.SelfAttribute('birthdate.month') @@ -940,14 +940,14 @@ gains an "upward" semantic through the double-dot notation, as used in Python im class UserFactory(factory.Factory): class Meta: - target = User + model = User language = 'en' class CompanyFactory(factory.Factory): class Meta: - target = Company + model = Company country = factory.SubFactory(CountryFactory) owner = factory.SubFactory(UserFactory, language=factory.SelfAttribute('..country.language')) @@ -976,7 +976,7 @@ through the :attr:`~containers.LazyStub.factory_parent` attribute of the passed- class CompanyFactory(factory.Factory): class Meta: - target = Company + model = Company country = factory.SubFactory(CountryFactory) owner = factory.SubFactory(UserFactory, language=factory.LazyAttribute(lambda user: user.factory_parent.country.language), @@ -1055,7 +1055,7 @@ adequate value. class UserFactory(factory.Factory): class Meta: - target = User + model = User # CATEGORY_CHOICES is a list of (key, title) tuples category = factory.Iterator(User.CATEGORY_CHOICES, getter=lambda c: c[0]) @@ -1077,7 +1077,7 @@ use the :func:`iterator` decorator: class UserFactory(factory.Factory): class Meta: - target = User + model = User @factory.iterator def name(): @@ -1121,7 +1121,7 @@ with the :class:`Dict` and :class:`List` attributes: class UserFactory(factory.Factory): class Meta: - target = User + model = User is_superuser = False roles = factory.Dict({ @@ -1158,7 +1158,7 @@ with the :class:`Dict` and :class:`List` attributes: class UserFactory(factory.Factory): class Meta: - target = User + model = User flags = factory.List([ 'user', @@ -1206,7 +1206,7 @@ For instance, a :class:`PostGeneration` hook is declared as ``post``: class SomeFactory(factory.Factory): class Meta: - target = SomeObject + model = SomeObject @post_generation def post(self, create, extracted, **kwargs): @@ -1221,7 +1221,7 @@ When calling the factory, some arguments will be extracted for this method: - Any argument starting with ``post__XYZ`` will be extracted, its ``post__`` prefix removed, and added to the kwargs passed to the post-generation hook. -Extracted arguments won't be passed to the :attr:`~FactoryOptions.target` class. +Extracted arguments won't be passed to the :attr:`~FactoryOptions.model` class. Thus, in the following call: @@ -1235,7 +1235,7 @@ Thus, in the following call: ) The ``post`` hook will receive ``1`` as ``extracted`` and ``{'y': 3, 'z__t': 42}`` -as keyword arguments; ``{'post_x': 2}`` will be passed to ``SomeFactory._meta.target``. +as keyword arguments; ``{'post_x': 2}`` will be passed to ``SomeFactory._meta.model``. RelatedFactory @@ -1278,7 +1278,7 @@ RelatedFactory class FooFactory(factory.Factory): class Meta: - target = Foo + model = Foo bar = factory.RelatedFactory(BarFactory) # Not BarFactory() @@ -1287,14 +1287,14 @@ RelatedFactory class CityFactory(factory.Factory): class Meta: - target = City + model = City capital_of = None name = "Toronto" class CountryFactory(factory.Factory): class Meta: - target = Country + model = Country lang = 'fr' capital_city = factory.RelatedFactory(CityFactory, 'capital_of', name="Paris") @@ -1336,7 +1336,7 @@ PostGeneration .. class:: PostGeneration(callable) -The :class:`PostGeneration` declaration performs actions once the target object +The :class:`PostGeneration` declaration performs actions once the model object has been generated. Its sole argument is a callable, that will be called once the base object has @@ -1357,7 +1357,7 @@ as ``callable(obj, create, extracted, **kwargs)``, where: class UserFactory(factory.Factory): class Meta: - target = User + model = User login = 'john' make_mbox = factory.PostGeneration( @@ -1378,7 +1378,7 @@ A decorator is also provided, decorating a single method accepting the same class UserFactory(factory.Factory): class Meta: - target = User + model = User login = 'john' @@ -1414,7 +1414,7 @@ PostGenerationMethodCall .. attribute:: method_name - The name of the method to call on the :attr:`~FactoryOptions.target` object + The name of the method to call on the :attr:`~FactoryOptions.model` object .. attribute:: args @@ -1439,7 +1439,7 @@ attribute like below: class UserFactory(factory.Factory): class Meta: - target = User + model = User username = 'user' password = factory.PostGenerationMethodCall('set_password', @@ -1490,7 +1490,7 @@ factory during instantiation. class UserFactory(factory.django.DjangoModelFactory): class Meta: - target = User + model = User username = 'user' password = factory.PostGenerationMethodCall('set_password', @@ -1505,7 +1505,7 @@ example, if we declared the ``password`` attribute like the following, class UserFactory(factory.Factory): class Meta: - target = User + model = User username = 'user' password = factory.PostGenerationMethodCall('set_password', '', 'sha1') @@ -1569,7 +1569,7 @@ Lightweight factory declaration class UserFactory(factory.Factory): class Meta: - target = User + model = User login = 'john' email = factory.LazyAttribute(lambda u: '%s@example.com' % u.login) @@ -1589,7 +1589,7 @@ Lightweight factory declaration class UserFactory(factory.django.DjangoModelFactory): class Meta: - target = models.User + model = models.User login = 'john' email = factory.LazyAttribute(lambda u: '%s@example.com' % u.login) |