Beispiel #1
0
    def test_lazyness(self):
        f = declarations.SubFactory('factory.declarations.Sequence', x=3)
        self.assertEqual(None, f.factory)

        self.assertEqual({'x': 3}, f.defaults)

        factory_class = f.get_factory()
        self.assertEqual(declarations.Sequence, factory_class)
Beispiel #2
0
    def test_subfields(self):
        class FakeInnerFactory(object):
            pass

        sf = declarations.SubFactory(FakeInnerFactory)
        FakeFactory = self.make_fake_factory({'one': sf, 'two': 2})

        ab = containers.AttributeBuilder(FakeFactory, {'one__blah': 1, 'two__bar': 2})
        self.assertTrue(ab.has_subfields(sf))
        self.assertEqual(['one'], list(ab._subfields.keys()))
        self.assertEqual(2, ab._declarations['two__bar'])
Beispiel #3
0
    def test_subfields(self):
        class FakeInnerFactory(object):
            pass

        sf = declarations.SubFactory(FakeInnerFactory)

        class FakeFactory(object):
            @classmethod
            def declarations(cls, extra):
                d = {'one': sf, 'two': 2}
                d.update(extra)
                return d

        ab = containers.AttributeBuilder(FakeFactory, {'one__blah': 1, 'two__bar': 2})
        self.assertTrue(ab.has_subfields(sf))
        self.assertEqual(['one'], ab._subfields.keys())
        self.assertEqual(2, ab._attrs['two__bar'])
Beispiel #4
0
    def test_cache(self):
        orig_date = datetime.date
        f = declarations.SubFactory('datetime.date')
        self.assertEqual(None, f.factory)

        factory_class = f.get_factory()
        self.assertEqual(orig_date, factory_class)

        try:
            # Modify original value
            datetime.date = None
            # Repeat import
            factory_class = f.get_factory()
            self.assertEqual(orig_date, factory_class)

        finally:
            # IMPORTANT: restore attribute.
            datetime.date = orig_date
Beispiel #5
0
        class StubB(base.StubFactory):
            class Meta:
                model = TestObject

            stubbed = declarations.SubFactory(StubA, two='two')
Beispiel #6
0
        class OuterWrappingTestObjectFactory(Factory):
            FACTORY_FOR = TestObject

            wrap = declarations.SubFactory(WrappingTestObjectFactory,
                    wrapped__two=declarations.SubFactory(TestObjectFactory, four=4))
Beispiel #7
0
        class WrappingTestObjectFactory(Factory):
            FACTORY_FOR = TestObject

            wrapped = declarations.SubFactory(TestObjectFactory)
            friend = declarations.LazyAttribute(lambda o: o.wrapped.two.four + 1)
Beispiel #8
0
        class WrappingTestObjectFactory(Factory):
            FACTORY_FOR = TestObject

            wrapped = declarations.SubFactory(TestObjectFactory)
            wrapped_bis = declarations.SubFactory(TestObjectFactory, one=1)
Beispiel #9
0
 class TestModel2Factory(Factory):
     FACTORY_FOR = TestModel2
     two = declarations.SubFactory(TestModelFactory,
                                   one=declarations.Sequence(lambda n: 'x%sx' % n),
                                   two=declarations.LazyAttribute(
                                       lambda o: '%s%s' % (o.one, o.one)))
Beispiel #10
0
 class TestModel2Factory(Factory):
     FACTORY_FOR = TestModel2
     two = declarations.SubFactory(TestModelFactory, one=1)
Beispiel #11
0
        class OuterWrappingTestObjectFactory(base.Factory):
            FACTORY_FOR = TestObject

            wrap = declarations.SubFactory(WrappingTestObjectFactory, wrapped__two=2)
Beispiel #12
0
        class WrappingTestObjectFactory(base.Factory):
            FACTORY_FOR = TestObject

            wrapped = declarations.SubFactory(TestObjectFactory, two=2, four=4)
            wrapped__two = 4
            wrapped__three = 3