diff options
-rw-r--r-- | factory/base.py | 4 | ||||
-rw-r--r-- | factory/mogo.py | 3 | ||||
-rw-r--r-- | factory/mongoengine.py | 4 | ||||
-rw-r--r-- | tests/cyclic/bar.py | 3 | ||||
-rw-r--r-- | tests/cyclic/foo.py | 3 | ||||
-rw-r--r-- | tests/test_alchemy.py | 13 | ||||
-rw-r--r-- | tests/test_base.py | 64 | ||||
-rw-r--r-- | tests/test_django.py | 58 | ||||
-rw-r--r-- | tests/test_mongoengine.py | 6 | ||||
-rw-r--r-- | tests/test_using.py | 380 |
10 files changed, 353 insertions, 185 deletions
diff --git a/factory/base.py b/factory/base.py index d255dbf..7db0c76 100644 --- a/factory/base.py +++ b/factory/base.py @@ -40,7 +40,7 @@ class FactoryError(Exception): class AssociatedClassError(FactoryError): - """Exception for Factory subclasses lacking FACTORY_FOR.""" + """Exception for Factory subclasses lacking Meta.target.""" class UnknownStrategy(FactoryError): @@ -82,7 +82,7 @@ class FactoryMetaClass(type): elif cls._meta.strategy == STUB_STRATEGY: return cls.stub(**kwargs) else: - raise UnknownStrategy('Unknown FACTORY_STRATEGY: {0}'.format( + raise UnknownStrategy('Unknown Meta.strategy: {0}'.format( cls._meta.strategy)) def __new__(mcs, class_name, bases, attrs): diff --git a/factory/mogo.py b/factory/mogo.py index 48d9677..0214119 100644 --- a/factory/mogo.py +++ b/factory/mogo.py @@ -32,7 +32,8 @@ from . import base class MogoFactory(base.Factory): """Factory for mogo objects.""" - ABSTRACT_FACTORY = True + class Meta: + abstract = True @classmethod def _build(cls, target_class, *args, **kwargs): diff --git a/factory/mongoengine.py b/factory/mongoengine.py index 462f5f2..729ebb1 100644 --- a/factory/mongoengine.py +++ b/factory/mongoengine.py @@ -32,7 +32,9 @@ from . import base class MongoEngineFactory(base.Factory): """Factory for mongoengine objects.""" - ABSTRACT_FACTORY = True + + class Meta: + abstract = True @classmethod def _build(cls, target_class, *args, **kwargs): diff --git a/tests/cyclic/bar.py b/tests/cyclic/bar.py index fed0602..8674c4d 100644 --- a/tests/cyclic/bar.py +++ b/tests/cyclic/bar.py @@ -30,7 +30,8 @@ class Bar(object): class BarFactory(factory.Factory): - FACTORY_FOR = Bar + class Meta: + target = Bar y = 13 foo = factory.SubFactory('cyclic.foo.FooFactory') diff --git a/tests/cyclic/foo.py b/tests/cyclic/foo.py index e584ed1..5310b1e 100644 --- a/tests/cyclic/foo.py +++ b/tests/cyclic/foo.py @@ -32,7 +32,8 @@ class Foo(object): class FooFactory(factory.Factory): - FACTORY_FOR = Foo + class Meta: + target = Foo x = 42 bar = factory.SubFactory(bar_mod.BarFactory) diff --git a/tests/test_alchemy.py b/tests/test_alchemy.py index c94e425..4526ad1 100644 --- a/tests/test_alchemy.py +++ b/tests/test_alchemy.py @@ -36,7 +36,8 @@ if sqlalchemy: else: class Fake(object): - FACTORY_SESSION = None + class Meta: + sqlalchemy_session = None models = Fake() models.StandardModel = Fake() @@ -46,16 +47,18 @@ else: class StandardFactory(SQLAlchemyModelFactory): - FACTORY_FOR = models.StandardModel - FACTORY_SESSION = models.session + class Meta: + target = models.StandardModel + sqlalchemy_session = models.session id = factory.Sequence(lambda n: n) foo = factory.Sequence(lambda n: 'foo%d' % n) class NonIntegerPkFactory(SQLAlchemyModelFactory): - FACTORY_FOR = models.NonIntegerPk - FACTORY_SESSION = models.session + class Meta: + target = models.NonIntegerPk + sqlalchemy_session = models.session id = factory.Sequence(lambda n: 'foo%d' % n) diff --git a/tests/test_base.py b/tests/test_base.py index be36363..c44ebd5 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -49,7 +49,8 @@ class FakeDjangoModel(object): class FakeModelFactory(base.Factory): - ABSTRACT_FACTORY = True + class Meta: + abstract = True @classmethod def _create(cls, target_class, *args, **kwargs): @@ -204,7 +205,8 @@ class OptionsTests(unittest.TestCase): class DeclarationParsingTests(unittest.TestCase): def test_classmethod(self): class TestObjectFactory(base.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject @classmethod def some_classmethod(cls): @@ -216,24 +218,28 @@ class DeclarationParsingTests(unittest.TestCase): class FactoryTestCase(unittest.TestCase): - def test_factory_for(self): + def test_magic_happens(self): + """Calling a FooFactory doesn't yield a FooFactory instance.""" class TestObjectFactory(base.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject self.assertEqual(TestObject, TestObjectFactory._meta.target) obj = TestObjectFactory.build() - self.assertFalse(hasattr(obj, 'FACTORY_FOR')) + self.assertFalse(hasattr(obj, '_meta')) def test_display(self): class TestObjectFactory(base.Factory): - FACTORY_FOR = FakeDjangoModel + class Meta: + target = FakeDjangoModel self.assertIn('TestObjectFactory', str(TestObjectFactory)) self.assertIn('FakeDjangoModel', str(TestObjectFactory)) def test_lazy_attribute_non_existent_param(self): class TestObjectFactory(base.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = declarations.LazyAttribute(lambda a: a.does_not_exist ) @@ -242,12 +248,14 @@ class FactoryTestCase(unittest.TestCase): def test_inheritance_with_sequence(self): """Tests that sequence IDs are shared between parent and son.""" class TestObjectFactory(base.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = declarations.Sequence(lambda a: a) class TestSubFactory(TestObjectFactory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject pass @@ -264,7 +272,8 @@ class FactorySequenceTestCase(unittest.TestCase): super(FactorySequenceTestCase, self).setUp() class TestObjectFactory(base.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = declarations.Sequence(lambda n: n) self.TestObjectFactory = TestObjectFactory @@ -348,7 +357,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): base.Factory._meta.strategy = base.BUILD_STRATEGY class TestModelFactory(base.Factory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -357,10 +367,11 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): self.assertFalse(test_model.id) def test_create_strategy(self): - # Default FACTORY_STRATEGY + # Default Meta.strategy class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -372,7 +383,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): base.Factory._meta.strategy = base.STUB_STRATEGY class TestModelFactory(base.Factory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -384,7 +396,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): base.Factory._meta.strategy = 'unknown' class TestModelFactory(base.Factory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -392,7 +405,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): def test_stub_with_non_stub_strategy(self): class TestModelFactory(base.StubFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -406,7 +420,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): def test_change_strategy(self): @base.use_strategy(base.CREATE_STRATEGY) class TestModelFactory(base.StubFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -416,7 +431,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase): class FactoryCreationTestCase(unittest.TestCase): def test_factory_for(self): class TestFactory(base.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject self.assertTrue(isinstance(TestFactory.build(), TestObject)) @@ -428,7 +444,8 @@ class FactoryCreationTestCase(unittest.TestCase): def test_inheritance_with_stub(self): class TestObjectFactory(base.StubFactory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject pass @@ -439,7 +456,8 @@ class FactoryCreationTestCase(unittest.TestCase): def test_custom_creation(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel @classmethod def _prepare(cls, create, **kwargs): @@ -469,7 +487,8 @@ class PostGenerationParsingTestCase(unittest.TestCase): def test_extraction(self): class TestObjectFactory(base.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject foo = declarations.PostGenerationDeclaration() @@ -477,7 +496,8 @@ class PostGenerationParsingTestCase(unittest.TestCase): def test_classlevel_extraction(self): class TestObjectFactory(base.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject foo = declarations.PostGenerationDeclaration() foo__bar = 42 diff --git a/tests/test_django.py b/tests/test_django.py index 37bf7a5..2bc5fe2 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -99,61 +99,71 @@ def tearDownModule(): class StandardFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = models.StandardModel + class Meta: + target = models.StandardModel foo = factory.Sequence(lambda n: "foo%d" % n) class StandardFactoryWithPKField(factory.django.DjangoModelFactory): - FACTORY_FOR = models.StandardModel - FACTORY_DJANGO_GET_OR_CREATE = ('pk',) + class Meta: + target = models.StandardModel + django_get_or_create = ('pk',) foo = factory.Sequence(lambda n: "foo%d" % n) pk = None class NonIntegerPkFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = models.NonIntegerPk + class Meta: + target = models.NonIntegerPk foo = factory.Sequence(lambda n: "foo%d" % n) bar = '' class AbstractBaseFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = models.AbstractBase - ABSTRACT_FACTORY = True + class Meta: + target = models.AbstractBase + abstract = True foo = factory.Sequence(lambda n: "foo%d" % n) class ConcreteSonFactory(AbstractBaseFactory): - FACTORY_FOR = models.ConcreteSon + class Meta: + target = models.ConcreteSon class AbstractSonFactory(AbstractBaseFactory): - FACTORY_FOR = models.AbstractSon + class Meta: + target = models.AbstractSon class ConcreteGrandSonFactory(AbstractBaseFactory): - FACTORY_FOR = models.ConcreteGrandSon + class Meta: + target = models.ConcreteGrandSon class WithFileFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = models.WithFile + class Meta: + target = models.WithFile if django is not None: afile = factory.django.FileField() class WithImageFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = models.WithImage + class Meta: + target = models.WithImage if django is not None: animage = factory.django.ImageField() class WithSignalsFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = models.WithSignals + class Meta: + target = models.WithSignals @unittest.skipIf(django is None, "Django not installed.") @@ -220,17 +230,20 @@ class DjangoPkForceTestCase(django_test.TestCase): @unittest.skipIf(django is None, "Django not installed.") class DjangoModelLoadingTestCase(django_test.TestCase): - """Tests FACTORY_FOR = 'app.Model' pattern.""" + """Tests class Meta: + target = 'app.Model' pattern.""" def test_loading(self): class ExampleFactory(factory.DjangoModelFactory): - FACTORY_FOR = 'djapp.StandardModel' + class Meta: + target = 'djapp.StandardModel' self.assertEqual(models.StandardModel, ExampleFactory._get_target_class()) def test_building(self): class ExampleFactory(factory.DjangoModelFactory): - FACTORY_FOR = 'djapp.StandardModel' + class Meta: + target = 'djapp.StandardModel' e = ExampleFactory.build() self.assertEqual(models.StandardModel, e.__class__) @@ -241,7 +254,8 @@ class DjangoModelLoadingTestCase(django_test.TestCase): See https://github.com/rbarrois/factory_boy/issues/109. """ class ExampleFactory(factory.DjangoModelFactory): - FACTORY_FOR = 'djapp.StandardModel' + class Meta: + target = 'djapp.StandardModel' class Example2Factory(ExampleFactory): pass @@ -255,12 +269,14 @@ class DjangoModelLoadingTestCase(django_test.TestCase): See https://github.com/rbarrois/factory_boy/issues/109. """ class ExampleFactory(factory.DjangoModelFactory): - FACTORY_FOR = 'djapp.StandardModel' + class Meta: + target = 'djapp.StandardModel' foo = factory.Sequence(lambda n: n) class Example2Factory(ExampleFactory): - FACTORY_FOR = 'djapp.StandardSon' + class Meta: + target = 'djapp.StandardSon' self.assertEqual(models.StandardSon, Example2Factory._get_target_class()) @@ -563,7 +579,8 @@ class PreventSignalsTestCase(unittest.TestCase): def test_class_decorator(self): @factory.django.mute_signals(signals.pre_save, signals.post_save) class WithSignalsDecoratedFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = models.WithSignals + class Meta: + target = models.WithSignals WithSignalsDecoratedFactory() @@ -576,7 +593,8 @@ class PreventSignalsTestCase(unittest.TestCase): def test_class_decorator_build(self): @factory.django.mute_signals(signals.pre_save, signals.post_save) class WithSignalsDecoratedFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = models.WithSignals + class Meta: + target = models.WithSignals WithSignalsDecoratedFactory.build() diff --git a/tests/test_mongoengine.py b/tests/test_mongoengine.py index 803607a..39594c0 100644 --- a/tests/test_mongoengine.py +++ b/tests/test_mongoengine.py @@ -42,12 +42,14 @@ if mongoengine: address = mongoengine.EmbeddedDocumentField(Address) class AddressFactory(MongoEngineFactory): - FACTORY_FOR = Address + class Meta: + target = Address street = factory.Sequence(lambda n: 'street%d' % n) class PersonFactory(MongoEngineFactory): - FACTORY_FOR = Person + class Meta: + target = Person name = factory.Sequence(lambda n: 'name%d' % n) address = factory.SubFactory(AddressFactory) diff --git a/tests/test_using.py b/tests/test_using.py index 3979cd0..6e7ed64 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -78,7 +78,8 @@ class FakeModel(object): class FakeModelFactory(factory.Factory): - ABSTRACT_FACTORY = True + class Meta: + abstract = True @classmethod def _create(cls, target_class, *args, **kwargs): @@ -292,7 +293,8 @@ class SimpleBuildTestCase(unittest.TestCase): class UsingFactoryTestCase(unittest.TestCase): def test_attribute(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 'one' @@ -302,7 +304,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_inheriting_target_class(self): @factory.use_strategy(factory.BUILD_STRATEGY) class TestObjectFactory(factory.Factory, TestObject): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 'one' @@ -311,18 +314,22 @@ class UsingFactoryTestCase(unittest.TestCase): def test_abstract(self): class SomeAbstractFactory(factory.Factory): - ABSTRACT_FACTORY = True + class Meta: + abstract = True + one = 'one' class InheritedFactory(SomeAbstractFactory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject test_object = InheritedFactory.build() self.assertEqual(test_object.one, 'one') def test_sequence(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Sequence(lambda n: 'one%d' % n) two = factory.Sequence(lambda n: 'two%d' % n) @@ -337,7 +344,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_sequence_custom_begin(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject @classmethod def _setup_next_sequence(cls): @@ -356,7 +364,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_sequence_override(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Sequence(lambda n: 'one%d' % n) @@ -372,7 +381,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_custom_create(self): class TestModelFactory(factory.Factory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel two = 2 @@ -395,7 +405,8 @@ class UsingFactoryTestCase(unittest.TestCase): self.y = y class NonDjangoFactory(factory.Factory): - FACTORY_FOR = NonDjango + class Meta: + target = NonDjango x = 3 @@ -405,7 +416,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_sequence_batch(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Sequence(lambda n: 'one%d' % n) two = factory.Sequence(lambda n: 'two%d' % n) @@ -420,7 +432,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_lazy_attribute(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.LazyAttribute(lambda a: 'abc' ) two = factory.LazyAttribute(lambda a: a.one + ' xyz') @@ -431,7 +444,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_lazy_attribute_sequence(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.LazyAttributeSequence(lambda a, n: 'abc%d' % n) two = factory.LazyAttributeSequence(lambda a, n: a.one + ' xyz%d' % n) @@ -446,7 +460,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_lazy_attribute_decorator(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject @factory.lazy_attribute def one(a): @@ -460,7 +475,8 @@ class UsingFactoryTestCase(unittest.TestCase): n = 3 class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 'xx' two = factory.SelfAttribute('one') @@ -479,12 +495,14 @@ class UsingFactoryTestCase(unittest.TestCase): pass class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 3 three = factory.SelfAttribute('..bar') class TestModel2Factory(FakeModelFactory): - FACTORY_FOR = TestModel2 + class Meta: + target = TestModel2 bar = 4 two = factory.SubFactory(TestModelFactory, one=1) @@ -493,7 +511,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_sequence_decorator(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject @factory.sequence def one(n): @@ -504,7 +523,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_lazy_attribute_sequence_decorator(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject @factory.lazy_attribute_sequence def one(a, n): @@ -519,7 +539,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_build_with_parameters(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Sequence(lambda n: 'one%d' % n) two = factory.Sequence(lambda n: 'two%d' % n) @@ -535,7 +556,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_create(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -545,7 +567,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_create_batch(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -561,7 +584,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_generate_build(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -571,7 +595,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_generate_create(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -581,7 +606,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_generate_stub(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -591,7 +617,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_generate_batch_build(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -607,7 +634,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_generate_batch_create(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -623,7 +651,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_generate_batch_stub(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -639,7 +668,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_simple_generate_build(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -649,7 +679,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_simple_generate_create(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -659,7 +690,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_simple_generate_batch_build(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -675,7 +707,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_simple_generate_batch_create(self): class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 'one' @@ -691,7 +724,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_stub_batch(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 'one' two = factory.LazyAttribute(lambda a: a.one + ' two') @@ -710,13 +744,15 @@ class UsingFactoryTestCase(unittest.TestCase): def test_inheritance(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 'one' two = factory.LazyAttribute(lambda a: a.one + ' two') class TestObjectFactory2(TestObjectFactory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject three = 'three' four = factory.LazyAttribute(lambda a: a.three + ' four') @@ -733,12 +769,14 @@ class UsingFactoryTestCase(unittest.TestCase): def test_inheritance_and_sequences(self): """Sequence counters should be kept within an inheritance chain.""" class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Sequence(lambda n: n) class TestObjectFactory2(TestObjectFactory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject to1a = TestObjectFactory() self.assertEqual(0, to1a.one) @@ -755,12 +793,14 @@ class UsingFactoryTestCase(unittest.TestCase): pass class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Sequence(lambda n: n) class TestObjectFactory2(TestObjectFactory): - FACTORY_FOR = TestObject2 + class Meta: + target = TestObject2 to1a = TestObjectFactory() self.assertEqual(0, to1a.one) @@ -785,12 +825,14 @@ class UsingFactoryTestCase(unittest.TestCase): self.one = one class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Sequence(lambda n: n) class TestObjectFactory2(TestObjectFactory): - FACTORY_FOR = TestObject2 + class Meta: + target = TestObject2 to1a = TestObjectFactory() self.assertEqual(0, to1a.one) @@ -804,7 +846,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_inheritance_with_inherited_class(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 'one' two = factory.LazyAttribute(lambda a: a.one + ' two') @@ -821,12 +864,14 @@ class UsingFactoryTestCase(unittest.TestCase): def test_dual_inheritance(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 'one' class TestOtherFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject two = 'two' four = 'four' @@ -841,7 +886,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_class_method_accessible(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject @classmethod def alt_create(cls, **kwargs): @@ -851,7 +897,8 @@ class UsingFactoryTestCase(unittest.TestCase): def test_static_method_accessible(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject @staticmethod def alt_create(**kwargs): @@ -866,8 +913,9 @@ class UsingFactoryTestCase(unittest.TestCase): self.kwargs = kwargs class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject - FACTORY_ARG_PARAMETERS = ('x', 'y') + class Meta: + target = TestObject + arg_parameters = ('x', 'y') x = 1 y = 2 @@ -885,8 +933,9 @@ class UsingFactoryTestCase(unittest.TestCase): self.kwargs = kwargs class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject - FACTORY_HIDDEN_ARGS = ('x', 'z') + class Meta: + target = TestObject + hidden_args = ('x', 'z') x = 1 y = 2 @@ -904,9 +953,10 @@ class UsingFactoryTestCase(unittest.TestCase): self.kwargs = kwargs class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject - FACTORY_HIDDEN_ARGS = ('x', 'z') - FACTORY_ARG_PARAMETERS = ('y',) + class Meta: + target = TestObject + hidden_args = ('x', 'z') + arg_parameters = ('y',) x = 1 y = 2 @@ -927,8 +977,9 @@ class NonKwargParametersTestCase(unittest.TestCase): self.kwargs = kwargs class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject - FACTORY_ARG_PARAMETERS = ('one', 'two',) + class Meta: + target = TestObject + arg_parameters = ('one', 'two',) one = 1 two = 2 @@ -952,8 +1003,9 @@ class NonKwargParametersTestCase(unittest.TestCase): return inst class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject - FACTORY_ARG_PARAMETERS = ('one', 'two') + class Meta: + target = TestObject + arg_parameters = ('one', 'two') one = 1 two = 2 @@ -978,7 +1030,8 @@ class KwargAdjustTestCase(unittest.TestCase): self.kwargs = kwargs class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject @classmethod def _adjust_kwargs(cls, **kwargs): @@ -996,11 +1049,13 @@ class SubFactoryTestCase(unittest.TestCase): pass class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 3 class TestModel2Factory(FakeModelFactory): - FACTORY_FOR = TestModel2 + class Meta: + target = TestModel2 two = factory.SubFactory(TestModelFactory, one=1) test_model = TestModel2Factory(two__one=4) @@ -1013,10 +1068,12 @@ class SubFactoryTestCase(unittest.TestCase): pass class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel class TestModel2Factory(FakeModelFactory): - FACTORY_FOR = TestModel2 + class Meta: + target = TestModel2 two = factory.SubFactory(TestModelFactory, one=factory.Sequence(lambda n: 'x%dx' % n), two=factory.LazyAttribute(lambda o: '%s%s' % (o.one, o.one)), @@ -1033,12 +1090,14 @@ class SubFactoryTestCase(unittest.TestCase): setattr(self, k, v) class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Sequence(lambda n: int(n)) class WrappingTestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject wrapped = factory.SubFactory(TestObjectFactory) @@ -1054,7 +1113,8 @@ class SubFactoryTestCase(unittest.TestCase): setattr(self, k, v) class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject class OtherTestObject(object): @@ -1063,7 +1123,8 @@ class SubFactoryTestCase(unittest.TestCase): setattr(self, k, v) class WrappingTestObjectFactory(factory.Factory): - FACTORY_FOR = OtherTestObject + class Meta: + target = OtherTestObject wrapped = factory.SubFactory(TestObjectFactory, two=2, four=4) wrapped__two = 4 @@ -1083,16 +1144,19 @@ class SubFactoryTestCase(unittest.TestCase): setattr(self, k, v) class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject class WrappingTestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject wrapped = factory.SubFactory(TestObjectFactory) wrapped_bis = factory.SubFactory(TestObjectFactory, one=1) class OuterWrappingTestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject wrap = factory.SubFactory(WrappingTestObjectFactory, wrapped__two=2) @@ -1109,17 +1173,20 @@ class SubFactoryTestCase(unittest.TestCase): setattr(self, k, v) class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject two = 'two' class WrappingTestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject wrapped = factory.SubFactory(TestObjectFactory) friend = factory.LazyAttribute(lambda o: o.wrapped.two.four + 1) class OuterWrappingTestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject wrap = factory.SubFactory(WrappingTestObjectFactory, wrapped__two=factory.SubFactory(TestObjectFactory, four=4)) @@ -1139,12 +1206,14 @@ class SubFactoryTestCase(unittest.TestCase): # Innermost factory class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject two = 'two' # Intermediary factory class WrappingTestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject wrapped = factory.SubFactory(TestObjectFactory) wrapped__two = 'three' @@ -1162,11 +1231,13 @@ class SubFactoryTestCase(unittest.TestCase): setattr(self, k, v) class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject two = 'two' class WrappingTestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject wrapped = factory.SubFactory(TestObjectFactory) friend = factory.LazyAttribute(lambda o: o.wrapped.two + 1) @@ -1200,20 +1271,24 @@ class SubFactoryTestCase(unittest.TestCase): self.side_b = side_b class InnerMostFactory(factory.Factory): - FACTORY_FOR = InnerMost + class Meta: + target = InnerMost a = 15 b = 20 class SideAFactory(factory.Factory): - FACTORY_FOR = SideA + class Meta: + target = SideA inner_from_a = factory.SubFactory(InnerMostFactory, a=20) class SideBFactory(factory.Factory): - FACTORY_FOR = SideB + class Meta: + target = SideB inner_from_b = factory.SubFactory(InnerMostFactory, b=15) class OuterMostFactory(factory.Factory): - FACTORY_FOR = OuterMost + class Meta: + target = OuterMost foo = 30 side_a = factory.SubFactory(SideAFactory, @@ -1238,12 +1313,14 @@ class SubFactoryTestCase(unittest.TestCase): pass class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 3 two = factory.ContainerAttribute(lambda obj, containers: len(containers or []), strict=False) class TestModel2Factory(FakeModelFactory): - FACTORY_FOR = TestModel2 + class Meta: + target = TestModel2 one = 1 two = factory.SubFactory(TestModelFactory, one=1) @@ -1261,12 +1338,14 @@ class SubFactoryTestCase(unittest.TestCase): pass class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 3 two = factory.ContainerAttribute(lambda obj, containers: len(containers or []), strict=True) class TestModel2Factory(FakeModelFactory): - FACTORY_FOR = TestModel2 + class Meta: + target = TestModel2 one = 1 two = factory.SubFactory(TestModelFactory, one=1) @@ -1282,7 +1361,8 @@ class SubFactoryTestCase(unittest.TestCase): pass class TestModelFactory(FakeModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel one = 3 @factory.container_attribute @@ -1292,7 +1372,8 @@ class SubFactoryTestCase(unittest.TestCase): return 42 class TestModel2Factory(FakeModelFactory): - FACTORY_FOR = TestModel2 + class Meta: + target = TestModel2 one = 1 two = factory.SubFactory(TestModelFactory, one=1) @@ -1310,7 +1391,8 @@ class IteratorTestCase(unittest.TestCase): def test_iterator(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Iterator(range(10, 30)) @@ -1323,7 +1405,8 @@ class IteratorTestCase(unittest.TestCase): @tools.disable_warnings def test_iterator_list_comprehension_scope_bleeding(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Iterator([j * 3 for j in range(5)]) @@ -1334,7 +1417,8 @@ class IteratorTestCase(unittest.TestCase): @tools.disable_warnings def test_iterator_list_comprehension_protected(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Iterator([_j * 3 for _j in range(5)]) @@ -1347,7 +1431,8 @@ class IteratorTestCase(unittest.TestCase): def test_iterator_decorator(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject @factory.iterator def one(): @@ -1397,7 +1482,8 @@ class BetterFakeModel(object): class DjangoModelFactoryTestCase(unittest.TestCase): def test_simple(self): class FakeModelFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = FakeModel + class Meta: + target = FakeModel obj = FakeModelFactory(one=1) self.assertEqual(1, obj.one) @@ -1411,8 +1497,9 @@ class DjangoModelFactoryTestCase(unittest.TestCase): objects = BetterFakeModelManager({'x': 1}, prev) class MyFakeModelFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = MyFakeModel - FACTORY_DJANGO_GET_OR_CREATE = ('x',) + class Meta: + target = MyFakeModel + django_get_or_create = ('x',) x = 1 y = 4 z = 6 @@ -1432,8 +1519,9 @@ class DjangoModelFactoryTestCase(unittest.TestCase): objects = BetterFakeModelManager({'x': 1, 'y': 2, 'z': 3}, prev) class MyFakeModelFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = MyFakeModel - FACTORY_DJANGO_GET_OR_CREATE = ('x', 'y', 'z') + class Meta: + target = MyFakeModel + django_get_or_create = ('x', 'y', 'z') x = 1 y = 4 z = 6 @@ -1453,8 +1541,9 @@ class DjangoModelFactoryTestCase(unittest.TestCase): objects = BetterFakeModelManager({'x': 1}, prev) class MyFakeModelFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = MyFakeModel - FACTORY_DJANGO_GET_OR_CREATE = ('x',) + class Meta: + target = MyFakeModel + django_get_or_create = ('x',) x = 1 y = 4 z = 6 @@ -1474,8 +1563,9 @@ class DjangoModelFactoryTestCase(unittest.TestCase): objects = BetterFakeModelManager({'x': 1, 'y': 2, 'z': 3}, prev) class MyFakeModelFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = MyFakeModel - FACTORY_DJANGO_GET_OR_CREATE = ('x', 'y', 'z') + class Meta: + target = MyFakeModel + django_get_or_create = ('x', 'y', 'z') x = 1 y = 4 z = 6 @@ -1489,7 +1579,8 @@ class DjangoModelFactoryTestCase(unittest.TestCase): def test_sequence(self): class TestModelFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel a = factory.Sequence(lambda n: 'foo_%s' % n) @@ -1507,7 +1598,8 @@ class DjangoModelFactoryTestCase(unittest.TestCase): def test_no_get_or_create(self): class TestModelFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = TestModel + class Meta: + target = TestModel a = factory.Sequence(lambda n: 'foo_%s' % n) @@ -1518,8 +1610,9 @@ class DjangoModelFactoryTestCase(unittest.TestCase): def test_get_or_create(self): class TestModelFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = TestModel - FACTORY_DJANGO_GET_OR_CREATE = ('a', 'b') + class Meta: + target = TestModel + django_get_or_create = ('a', 'b') a = factory.Sequence(lambda n: 'foo_%s' % n) b = 2 @@ -1537,8 +1630,9 @@ class DjangoModelFactoryTestCase(unittest.TestCase): def test_full_get_or_create(self): """Test a DjangoModelFactory with all fields in get_or_create.""" class TestModelFactory(factory.django.DjangoModelFactory): - FACTORY_FOR = TestModel - FACTORY_DJANGO_GET_OR_CREATE = ('a', 'b', 'c', 'd') + class Meta: + target = TestModel + django_get_or_create = ('a', 'b', 'c', 'd') a = factory.Sequence(lambda n: 'foo_%s' % n) b = 2 @@ -1557,7 +1651,8 @@ class DjangoModelFactoryTestCase(unittest.TestCase): class PostGenerationTestCase(unittest.TestCase): def test_post_generation(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 1 @@ -1575,7 +1670,8 @@ class PostGenerationTestCase(unittest.TestCase): def test_post_generation_hook(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 1 @@ -1596,7 +1692,8 @@ class PostGenerationTestCase(unittest.TestCase): def test_post_generation_extraction(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 1 @@ -1621,7 +1718,8 @@ class PostGenerationTestCase(unittest.TestCase): self.assertEqual(kwargs, {'foo': 13}) class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject bar = factory.PostGeneration(my_lambda) @@ -1640,7 +1738,8 @@ class PostGenerationTestCase(unittest.TestCase): self.extra = (args, kwargs) class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 3 two = 2 post_call = factory.PostGenerationMethodCall('call', one=1) @@ -1664,12 +1763,14 @@ class PostGenerationTestCase(unittest.TestCase): self.three = obj class TestRelatedObjectFactory(factory.Factory): - FACTORY_FOR = TestRelatedObject + class Meta: + target = TestRelatedObject one = 1 two = factory.LazyAttribute(lambda o: o.one + 1) class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 3 two = 2 three = factory.RelatedFactory(TestRelatedObjectFactory, name='obj') @@ -1709,12 +1810,14 @@ class PostGenerationTestCase(unittest.TestCase): self.three = obj class TestRelatedObjectFactory(factory.Factory): - FACTORY_FOR = TestRelatedObject + class Meta: + target = TestRelatedObject one = 1 two = factory.LazyAttribute(lambda o: o.one + 1) class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 3 two = 2 three = factory.RelatedFactory(TestRelatedObjectFactory) @@ -1755,10 +1858,12 @@ class RelatedFactoryExtractionTestCase(unittest.TestCase): obj.related = subself class TestRelatedObjectFactory(factory.Factory): - FACTORY_FOR = TestRelatedObject + class Meta: + target = TestRelatedObject class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.RelatedFactory(TestRelatedObjectFactory, 'obj') self.TestRelatedObject = TestRelatedObject @@ -1805,7 +1910,8 @@ class CircularTestCase(unittest.TestCase): class DictTestCase(unittest.TestCase): def test_empty_dict(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Dict({}) o = TestObjectFactory() @@ -1813,7 +1919,8 @@ class DictTestCase(unittest.TestCase): def test_naive_dict(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Dict({'a': 1}) o = TestObjectFactory() @@ -1821,7 +1928,8 @@ class DictTestCase(unittest.TestCase): def test_sequence_dict(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Dict({'a': factory.Sequence(lambda n: n + 2)}) o1 = TestObjectFactory() @@ -1832,7 +1940,8 @@ class DictTestCase(unittest.TestCase): def test_dict_override(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Dict({'a': 1}) o = TestObjectFactory(one__a=2) @@ -1840,7 +1949,8 @@ class DictTestCase(unittest.TestCase): def test_dict_extra_key(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.Dict({'a': 1}) o = TestObjectFactory(one__b=2) @@ -1848,7 +1958,8 @@ class DictTestCase(unittest.TestCase): def test_dict_merged_fields(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject two = 13 one = factory.Dict({ 'one': 1, @@ -1861,7 +1972,8 @@ class DictTestCase(unittest.TestCase): def test_nested_dicts(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = 1 two = factory.Dict({ 'one': 3, @@ -1889,7 +2001,8 @@ class DictTestCase(unittest.TestCase): class ListTestCase(unittest.TestCase): def test_empty_list(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.List([]) o = TestObjectFactory() @@ -1897,7 +2010,8 @@ class ListTestCase(unittest.TestCase): def test_naive_list(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.List([1]) o = TestObjectFactory() @@ -1905,7 +2019,8 @@ class ListTestCase(unittest.TestCase): def test_sequence_list(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.List([factory.Sequence(lambda n: n + 2)]) o1 = TestObjectFactory() @@ -1916,7 +2031,8 @@ class ListTestCase(unittest.TestCase): def test_list_override(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.List([1]) o = TestObjectFactory(one__0=2) @@ -1924,7 +2040,8 @@ class ListTestCase(unittest.TestCase): def test_list_extra_key(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject one = factory.List([1]) o = TestObjectFactory(one__1=2) @@ -1932,7 +2049,8 @@ class ListTestCase(unittest.TestCase): def test_list_merged_fields(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject two = 13 one = factory.List([ 1, @@ -1945,7 +2063,9 @@ class ListTestCase(unittest.TestCase): def test_nested_lists(self): class TestObjectFactory(factory.Factory): - FACTORY_FOR = TestObject + class Meta: + target = TestObject + one = 1 two = factory.List([ 3, |