diff options
-rw-r--r-- | README | 4 | ||||
-rw-r--r-- | docs/changelog.rst | 18 | ||||
-rw-r--r-- | docs/introduction.rst | 2 | ||||
-rw-r--r-- | docs/orms.rst | 32 | ||||
-rw-r--r-- | docs/recipes.rst | 24 | ||||
-rw-r--r-- | docs/reference.rst | 14 | ||||
-rw-r--r-- | factory/__init__.py | 5 | ||||
-rw-r--r-- | factory/base.py | 77 | ||||
-rw-r--r-- | factory/django.py | 100 | ||||
-rw-r--r-- | factory/mogo.py | 45 | ||||
-rw-r--r-- | tests/test_using.py | 30 |
11 files changed, 225 insertions, 126 deletions
@@ -189,8 +189,8 @@ ORM Support factory_boy has specific support for a few ORMs, through specific :class:`~factory.Factory` subclasses: -* Django, with :class:`~factory.DjangoModelFactory` -* Mogo, with :class:`~factory.MogoFactory` +* Django, with :class:`~factory.django.DjangoModelFactory` +* Mogo, with :class:`~factory.mogo.MogoFactory` Contributing ------------ diff --git a/docs/changelog.rst b/docs/changelog.rst index 0baa3f7..e820d8c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -11,6 +11,8 @@ ChangeLog - Add a :attr:`~factory.containers.LazyStub.factory_parent` attribute to the :class:`~factory.containers.LazyStub` passed to :class:`~factory.LazyAttribute`, in order to access fields defined in wrapping factories. + - Move :class:`~factory.django.DjangoModelFactory` and :class:`~factory.mogo.MogoFactory` + to their own modules (:mod:`factory.django` and :mod:`factory.mogo`) *Deprecation:* @@ -21,7 +23,7 @@ ChangeLog *New:* - - When :attr:`~factory.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE` is + - When :attr:`~factory.django.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE` is empty, use ``Model.objects.create()`` instead of ``Model.objects.get_or_create``. @@ -31,7 +33,7 @@ ChangeLog *New:* - Don't push ``defaults`` to ``get_or_create`` when - :attr:`~factory.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE` is not set. + :attr:`~factory.django.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE` is not set. 2.0.0 (2013-04-15) @@ -44,8 +46,8 @@ ChangeLog - The default :attr:`~factory.Sequence.type` for :class:`~factory.Sequence` is now :obj:`int` - Fields listed in :attr:`~factory.Factory.FACTORY_HIDDEN_ARGS` won't be passed to the associated class' constructor - - Add support for ``get_or_create`` in :class:`~factory.DjangoModelFactory`, - through :attr:`~factory.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE`. + - Add support for ``get_or_create`` in :class:`~factory.django.DjangoModelFactory`, + through :attr:`~factory.django.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE`. - Add support for :mod:`~factory.fuzzy` attribute definitions. - The :class:`Sequence` counter can be overridden when calling a generating function - Add :class:`~factory.Dict` and :class:`~factory.List` declarations (Closes #18). @@ -75,7 +77,7 @@ New - **Global:** - Rewrite the whole documentation - - Provide a dedicated :class:`~factory.MogoFactory` subclass of :class:`~factory.Factory` + - Provide a dedicated :class:`~factory.mogo.MogoFactory` subclass of :class:`~factory.Factory` - **The Factory class:** - Better creation/building customization hooks at :meth:`factory.Factory._build` and :meth:`factory.Factory.create` @@ -92,7 +94,7 @@ New its :attr:`~factory.Iterator.cycle` argument to ``False`` - Allow overriding default arguments in a :class:`~factory.PostGenerationMethodCall` when generating an instance of the factory - - An object created by a :class:`~factory.DjangoModelFactory` will be saved + - An object created by a :class:`~factory.django.DjangoModelFactory` will be saved again after :class:`~factory.PostGeneration` hooks execution @@ -127,7 +129,7 @@ In order to upgrade client code, apply the following rules: :class:`~factory.Factory`, instead of relying on automagic associated class discovery - When using factory_boy for Django models, have each factory inherit from - :class:`~factory.DjangoModelFactory` + :class:`~factory.django.DjangoModelFactory` - Replace ``factory.CircularSubFactory('some.module', 'Symbol')`` with ``factory.SubFactory('some.module.Symbol')`` - Replace ``factory.InfiniteIterator(iterable)`` with ``factory.Iterator(iterable)`` @@ -216,7 +218,7 @@ In order to upgrade client code, apply the following rules: - Introduce :data:`~factory.MOGO_BUILD` build function - Add support for inheriting from multiple :class:`~factory.Factory` - Base :class:`~factory.Factory` classes can now be declared :attr:`abstract <factory.Factory.ABSTRACT_FACTORY>`. - - Provide :class:`~factory.DjangoModelFactory`, whose :class:`~factory.Sequence` counter starts at the next free database id + - Provide :class:`~factory.django.DjangoModelFactory`, whose :class:`~factory.Sequence` counter starts at the next free database id - Introduce :class:`~factory.SelfAttribute`, a shortcut for ``factory.LazyAttribute(lambda o: o.foo.bar.baz``. *Bugfix:* diff --git a/docs/introduction.rst b/docs/introduction.rst index 8bbb10c..356e11f 100644 --- a/docs/introduction.rst +++ b/docs/introduction.rst @@ -227,7 +227,7 @@ All factories support two built-in strategies: as for a Django model. Starting from 2.0, :meth:`factory.Factory.create` simply calls ``AssociatedClass(**kwargs)``. - You should use :class:`~factory.DjangoModelFactory` for Django models. + You should use :class:`~factory.django.DjangoModelFactory` for Django models. When a :class:`~factory.Factory` includes related fields (:class:`~factory.SubFactory`, :class:`~factory.RelatedFactory`), diff --git a/docs/orms.rst b/docs/orms.rst index 8e5b6f6..9cf7f8e 100644 --- a/docs/orms.rst +++ b/docs/orms.rst @@ -11,6 +11,8 @@ adding dedicated features. Django ------ +.. currentmodule:: factory.django + The first versions of factory_boy were designed specifically for Django, but the library has now evolved to be framework-independant. @@ -24,14 +26,14 @@ All factories for a Django :class:`~django.db.models.Model` should use the :class:`DjangoModelFactory` base class. -.. class:: DjangoModelFactory(Factory) +.. class:: DjangoModelFactory(factory.Factory) Dedicated class for Django :class:`~django.db.models.Model` factories. This class provides the following features: - * :func:`~Factory.create()` uses :meth:`Model.objects.create() <django.db.models.query.QuerySet.create>` - * :func:`~Factory._setup_next_sequence()` selects the next unused primary key value + * :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 * When using :class:`~factory.RelatedFactory` or :class:`~factory.PostGeneration` attributes, the base object will be :meth:`saved <django.db.models.Model.save>` once all post-generation hooks have run. @@ -44,7 +46,7 @@ All factories for a Django :class:`~django.db.models.Model` should use the .. code-block:: python - class UserFactory(factory.DjangoModelFactory): + class UserFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.User FACTORY_DJANGO_GET_OR_CREATE = ('username',) @@ -68,3 +70,25 @@ All factories for a Django :class:`~django.db.models.Model` should use the <User: jack> >>> User.objects.all() [<User: john>, <User: jack>] + + +Mogo +---- + +.. currentmodule:: factory.mogo + +factory_boy supports `Mogo`_-style models, through the :class:`MogoFactory` class. + +`Mogo`_ is a wrapper around the ``pymongo`` library for MongoDB. + +.. _Mogo: https://github.com/joshmarshall/mogo + +.. class:: MogoFactory(factory.Factory) + + Dedicated class for `Mogo`_ models. + + This class provides the following features: + + * :func:`~factory.Factory.build()` calls a model's ``new()`` method + * :func:`~factory.Factory.create()` builds an instance through ``new()`` then + saves it. diff --git a/docs/recipes.rst b/docs/recipes.rst index ecdff96..82f0658 100644 --- a/docs/recipes.rst +++ b/docs/recipes.rst @@ -25,7 +25,7 @@ use the :class:`~factory.SubFactory` declaration: import factory from . import models - class UserFactory(factory.DjangoModelFactory): + class UserFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.User first_name = factory.Sequence(lambda n: "Agent %03d" % n) @@ -52,7 +52,7 @@ use a :class:`~factory.RelatedFactory` declaration: # factories.py - class UserFactory(factory.DjangoModelFactory): + class UserFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.User log = factory.RelatedFactory(UserLogFactory, 'user', action=models.UserLog.ACTION_CREATE) @@ -74,12 +74,12 @@ factory_boy allows to define attributes of such profiles dynamically when creati .. code-block:: python - class ProfileFactory(factory.DjangoModelFactory): + class ProfileFactory(factory.django.DjangoModelFactory): FACTORY_FOR = my_models.Profile title = 'Dr' - class UserFactory(factory.DjangoModelFactory): + class UserFactory(factory.django.DjangoModelFactory): FACTORY_FOR = auth_models.User username = factory.Sequence(lambda n: "user_%d" % n) @@ -129,12 +129,12 @@ hook: # factories.py - class GroupFactory(factory.DjangoModelFactory): + class GroupFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.Group name = factory.Sequence(lambda n: "Group #%s" % n) - class UserFactory(factory.DjangoModelFactory): + class UserFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.User name = "John Doe" @@ -184,17 +184,17 @@ If more links are needed, simply add more :class:`RelatedFactory` declarations: # factories.py - class UserFactory(factory.DjangoModelFactory): + class UserFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.User name = "John Doe" - class GroupFactory(factory.DjangoModelFactory): + class GroupFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.Group name = "Admins" - class GroupLevelFactory(factory.DjangoModelFactory): + class GroupLevelFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.GroupLevel user = factory.SubFactory(UserFactory) @@ -257,20 +257,20 @@ Here, we want: .. code-block:: python # factories.py - class CountryFactory(factory.DjangoModelFactory): + class CountryFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.Country name = factory.Iterator(["France", "Italy", "Spain"]) lang = factory.Iterator(['fr', 'it', 'es']) - class UserFactory(factory.DjangoModelFactory): + class UserFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.User name = "John" lang = factory.SelfAttribute('country.lang') country = factory.SubFactory(CountryFactory) - class CompanyFactory(factory.DjangoModelFactory): + class CompanyFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.Company name = "ACME, Inc." diff --git a/docs/reference.rst b/docs/reference.rst index ad921fa..377feb1 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -606,7 +606,9 @@ The :class:`SubFactory` attribute should be called with: factory -.. note:: When passing an actual :class:`~factory.Factory` for the +.. note:: + + When passing an actual :class:`~factory.Factory` for the :attr:`~factory.SubFactory.factory` argument, make sure to pass the class and not instance (i.e no ``()`` after the class): @@ -1070,7 +1072,9 @@ RelatedFactory keyword: -.. note:: When passing an actual :class:`~factory.Factory` for the +.. note:: + + When passing an actual :class:`~factory.Factory` for the :attr:`~factory.RelatedFactory.factory` argument, make sure to pass the class and not instance (i.e no ``()`` after the class): @@ -1266,7 +1270,7 @@ factory during instantiation. .. code-block:: python - class UserFactory(factory.DjangoModelFactory): + class UserFactory(factory.django.DjangoModelFactory): FACTORY_FOR = User username = 'user' @@ -1357,12 +1361,12 @@ Lightweight factory declaration UserFactory = make_factory(models.User, login='john', email=factory.LazyAttribute(lambda u: '%s@example.com' % u.login), - FACTORY_CLASS=factory.DjangoModelFactory, + FACTORY_CLASS=factory.django.DjangoModelFactory, ) # This is equivalent to: - class UserFactory(factory.DjangoModelFactory): + class UserFactory(factory.django.DjangoModelFactory): FACTORY_FOR = models.User login = 'john' diff --git a/factory/__init__.py b/factory/__init__.py index 2c81705..9eb3b7b 100644 --- a/factory/__init__.py +++ b/factory/__init__.py @@ -29,9 +29,7 @@ from .base import ( DictFactory, BaseListFactory, ListFactory, - MogoFactory, StubFactory, - DjangoModelFactory, BUILD_STRATEGY, CREATE_STRATEGY, @@ -39,6 +37,9 @@ from .base import ( use_strategy, ) +from .mogo import MogoFactory +from .django import DjangoModelFactory + from .declarations import ( LazyAttribute, Iterator, diff --git a/factory/base.py b/factory/base.py index 2ff2944..23fdac7 100644 --- a/factory/base.py +++ b/factory/base.py @@ -554,83 +554,6 @@ class StubFactory(Factory): raise UnsupportedStrategy() -class DjangoModelFactory(Factory): - """Factory for Django models. - - This makes sure that the 'sequence' field of created objects is a new id. - - Possible improvement: define a new 'attribute' type, AutoField, which would - handle those for non-numerical primary keys. - """ - - ABSTRACT_FACTORY = True - FACTORY_DJANGO_GET_OR_CREATE = () - - @classmethod - def _get_manager(cls, target_class): - try: - return target_class._default_manager # pylint: disable=W0212 - except AttributeError: - return target_class.objects - - @classmethod - def _setup_next_sequence(cls): - """Compute the next available PK, based on the 'pk' database field.""" - - model = cls._associated_class # pylint: disable=E1101 - manager = cls._get_manager(model) - - try: - return 1 + manager.values_list('pk', flat=True - ).order_by('-pk')[0] - except IndexError: - return 1 - - @classmethod - def _get_or_create(cls, target_class, *args, **kwargs): - """Create an instance of the model through objects.get_or_create.""" - manager = cls._get_manager(target_class) - - assert 'defaults' not in cls.FACTORY_DJANGO_GET_OR_CREATE, ( - "'defaults' is a reserved keyword for get_or_create " - "(in %s.FACTORY_DJANGO_GET_OR_CREATE=%r)" - % (cls, cls.FACTORY_DJANGO_GET_OR_CREATE)) - - key_fields = {} - for field in cls.FACTORY_DJANGO_GET_OR_CREATE: - key_fields[field] = kwargs.pop(field) - key_fields['defaults'] = kwargs - - obj, _created = manager.get_or_create(*args, **key_fields) - return obj - - @classmethod - def _create(cls, target_class, *args, **kwargs): - """Create an instance of the model, and save it to the database.""" - manager = cls._get_manager(target_class) - - if cls.FACTORY_DJANGO_GET_OR_CREATE: - return cls._get_or_create(target_class, *args, **kwargs) - - return manager.create(*args, **kwargs) - - @classmethod - def _after_postgeneration(cls, obj, create, results=None): - """Save again the instance if creating and at least one hook ran.""" - if create and results: - # Some post-generation hooks ran, and may have modified us. - obj.save() - - -class MogoFactory(Factory): - """Factory for mogo objects.""" - ABSTRACT_FACTORY = True - - @classmethod - def _build(cls, target_class, *args, **kwargs): - return target_class.new(*args, **kwargs) - - class BaseDictFactory(Factory): """Factory for dictionary-like classes.""" ABSTRACT_FACTORY = True diff --git a/factory/django.py b/factory/django.py new file mode 100644 index 0000000..351cb76 --- /dev/null +++ b/factory/django.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2010 Mark Sandstrom +# Copyright (c) 2011-2013 Raphaël Barrois +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + + +from __future__ import unicode_literals + + +"""factory_boy extensions for use with the Django framework.""" + + +from . import base + + +class DjangoModelFactory(base.Factory): + """Factory for Django models. + + This makes sure that the 'sequence' field of created objects is a new id. + + Possible improvement: define a new 'attribute' type, AutoField, which would + handle those for non-numerical primary keys. + """ + + ABSTRACT_FACTORY = True + FACTORY_DJANGO_GET_OR_CREATE = () + + @classmethod + def _get_manager(cls, target_class): + try: + return target_class._default_manager # pylint: disable=W0212 + except AttributeError: + return target_class.objects + + @classmethod + def _setup_next_sequence(cls): + """Compute the next available PK, based on the 'pk' database field.""" + + model = cls._associated_class # pylint: disable=E1101 + manager = cls._get_manager(model) + + try: + return 1 + manager.values_list('pk', flat=True + ).order_by('-pk')[0] + except IndexError: + return 1 + + @classmethod + def _get_or_create(cls, target_class, *args, **kwargs): + """Create an instance of the model through objects.get_or_create.""" + manager = cls._get_manager(target_class) + + assert 'defaults' not in cls.FACTORY_DJANGO_GET_OR_CREATE, ( + "'defaults' is a reserved keyword for get_or_create " + "(in %s.FACTORY_DJANGO_GET_OR_CREATE=%r)" + % (cls, cls.FACTORY_DJANGO_GET_OR_CREATE)) + + key_fields = {} + for field in cls.FACTORY_DJANGO_GET_OR_CREATE: + key_fields[field] = kwargs.pop(field) + key_fields['defaults'] = kwargs + + obj, _created = manager.get_or_create(*args, **key_fields) + return obj + + @classmethod + def _create(cls, target_class, *args, **kwargs): + """Create an instance of the model, and save it to the database.""" + manager = cls._get_manager(target_class) + + if cls.FACTORY_DJANGO_GET_OR_CREATE: + return cls._get_or_create(target_class, *args, **kwargs) + + return manager.create(*args, **kwargs) + + @classmethod + def _after_postgeneration(cls, obj, create, results=None): + """Save again the instance if creating and at least one hook ran.""" + if create and results: + # Some post-generation hooks ran, and may have modified us. + obj.save() + + diff --git a/factory/mogo.py b/factory/mogo.py new file mode 100644 index 0000000..48d9677 --- /dev/null +++ b/factory/mogo.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2010 Mark Sandstrom +# Copyright (c) 2011-2013 Raphaël Barrois +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + + +from __future__ import unicode_literals + + +"""factory_boy extensions for use with the mogo library (pymongo wrapper).""" + + +from . import base + + +class MogoFactory(base.Factory): + """Factory for mogo objects.""" + ABSTRACT_FACTORY = True + + @classmethod + def _build(cls, target_class, *args, **kwargs): + return target_class.new(*args, **kwargs) + + @classmethod + def _create(cls, target_class, *args, **kwargs): + instance = target_class.new(*args, **kwargs) + instance.save() + return instance diff --git a/tests/test_using.py b/tests/test_using.py index 821fad3..a3f5322 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -125,7 +125,7 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.foo, 'bar') def test_create_custom_base(self): - obj = factory.create(FakeModel, foo='bar', FACTORY_CLASS=factory.DjangoModelFactory) + obj = factory.create(FakeModel, foo='bar', FACTORY_CLASS=factory.django.DjangoModelFactory) self.assertEqual(obj.id, 2) self.assertEqual(obj.foo, 'bar') @@ -141,7 +141,7 @@ class SimpleBuildTestCase(unittest.TestCase): def test_create_batch_custom_base(self): objs = factory.create_batch(FakeModel, 4, foo='bar', - FACTORY_CLASS=factory.DjangoModelFactory) + FACTORY_CLASS=factory.django.DjangoModelFactory) self.assertEqual(4, len(objs)) self.assertEqual(4, len(set(objs))) @@ -177,7 +177,7 @@ class SimpleBuildTestCase(unittest.TestCase): def test_generate_create_custom_base(self): obj = factory.generate(FakeModel, factory.CREATE_STRATEGY, foo='bar', - FACTORY_CLASS=factory.DjangoModelFactory) + FACTORY_CLASS=factory.django.DjangoModelFactory) self.assertEqual(obj.id, 2) self.assertEqual(obj.foo, 'bar') @@ -208,7 +208,7 @@ class SimpleBuildTestCase(unittest.TestCase): def test_generate_batch_create_custom_base(self): objs = factory.generate_batch(FakeModel, factory.CREATE_STRATEGY, 20, foo='bar', - FACTORY_CLASS=factory.DjangoModelFactory) + FACTORY_CLASS=factory.django.DjangoModelFactory) self.assertEqual(20, len(objs)) self.assertEqual(20, len(set(objs))) @@ -238,7 +238,7 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.foo, 'bar') def test_simple_generate_create_custom_base(self): - obj = factory.simple_generate(FakeModel, True, foo='bar', FACTORY_CLASS=factory.DjangoModelFactory) + obj = factory.simple_generate(FakeModel, True, foo='bar', FACTORY_CLASS=factory.django.DjangoModelFactory) self.assertEqual(obj.id, 2) self.assertEqual(obj.foo, 'bar') @@ -264,7 +264,7 @@ class SimpleBuildTestCase(unittest.TestCase): def test_simple_generate_batch_create_custom_base(self): objs = factory.simple_generate_batch(FakeModel, True, 20, foo='bar', - FACTORY_CLASS=factory.DjangoModelFactory) + FACTORY_CLASS=factory.django.DjangoModelFactory) self.assertEqual(20, len(objs)) self.assertEqual(20, len(set(objs))) @@ -1298,7 +1298,7 @@ class BetterFakeModel(object): class DjangoModelFactoryTestCase(unittest.TestCase): def test_simple(self): - class FakeModelFactory(factory.DjangoModelFactory): + class FakeModelFactory(factory.django.DjangoModelFactory): FACTORY_FOR = FakeModel obj = FakeModelFactory(one=1) @@ -1312,7 +1312,7 @@ class DjangoModelFactoryTestCase(unittest.TestCase): class MyFakeModel(BetterFakeModel): objects = BetterFakeModelManager({'x': 1}, prev) - class MyFakeModelFactory(factory.DjangoModelFactory): + class MyFakeModelFactory(factory.django.DjangoModelFactory): FACTORY_FOR = MyFakeModel FACTORY_DJANGO_GET_OR_CREATE = ('x',) x = 1 @@ -1333,7 +1333,7 @@ class DjangoModelFactoryTestCase(unittest.TestCase): class MyFakeModel(BetterFakeModel): objects = BetterFakeModelManager({'x': 1, 'y': 2, 'z': 3}, prev) - class MyFakeModelFactory(factory.DjangoModelFactory): + class MyFakeModelFactory(factory.django.DjangoModelFactory): FACTORY_FOR = MyFakeModel FACTORY_DJANGO_GET_OR_CREATE = ('x', 'y', 'z') x = 1 @@ -1354,7 +1354,7 @@ class DjangoModelFactoryTestCase(unittest.TestCase): class MyFakeModel(BetterFakeModel): objects = BetterFakeModelManager({'x': 1}, prev) - class MyFakeModelFactory(factory.DjangoModelFactory): + class MyFakeModelFactory(factory.django.DjangoModelFactory): FACTORY_FOR = MyFakeModel FACTORY_DJANGO_GET_OR_CREATE = ('x',) x = 1 @@ -1375,7 +1375,7 @@ class DjangoModelFactoryTestCase(unittest.TestCase): class MyFakeModel(BetterFakeModel): objects = BetterFakeModelManager({'x': 1, 'y': 2, 'z': 3}, prev) - class MyFakeModelFactory(factory.DjangoModelFactory): + class MyFakeModelFactory(factory.django.DjangoModelFactory): FACTORY_FOR = MyFakeModel FACTORY_DJANGO_GET_OR_CREATE = ('x', 'y', 'z') x = 1 @@ -1769,7 +1769,7 @@ class ListTestCase(unittest.TestCase): class DjangoModelFactoryTestCase(unittest.TestCase): def test_sequence(self): - class TestModelFactory(factory.DjangoModelFactory): + class TestModelFactory(factory.django.DjangoModelFactory): FACTORY_FOR = TestModel a = factory.Sequence(lambda n: 'foo_%s' % n) @@ -1787,7 +1787,7 @@ class DjangoModelFactoryTestCase(unittest.TestCase): self.assertEqual('foo_5', o4.a) def test_no_get_or_create(self): - class TestModelFactory(factory.DjangoModelFactory): + class TestModelFactory(factory.django.DjangoModelFactory): FACTORY_FOR = TestModel a = factory.Sequence(lambda n: 'foo_%s' % n) @@ -1798,7 +1798,7 @@ class DjangoModelFactoryTestCase(unittest.TestCase): self.assertEqual(2, o.id) def test_get_or_create(self): - class TestModelFactory(factory.DjangoModelFactory): + class TestModelFactory(factory.django.DjangoModelFactory): FACTORY_FOR = TestModel FACTORY_DJANGO_GET_OR_CREATE = ('a', 'b') @@ -1817,7 +1817,7 @@ class DjangoModelFactoryTestCase(unittest.TestCase): def test_full_get_or_create(self): """Test a DjangoModelFactory with all fields in get_or_create.""" - class TestModelFactory(factory.DjangoModelFactory): + class TestModelFactory(factory.django.DjangoModelFactory): FACTORY_FOR = TestModel FACTORY_DJANGO_GET_OR_CREATE = ('a', 'b', 'c', 'd') |