class TestObjectFactory(Factory): @classmethod def _setup_next_sequence(cls): return 42 one = declarations.Sequence(lambda n: 'one' + n) two = declarations.Sequence(lambda n: 'two' + n)
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)))
def test_replaced_sequence(self): seq = declarations.Sequence(lambda n: 'xx' + n) seq2 = declarations.Sequence(lambda n: 'yy' + n) class FakeFactory(object): @classmethod def declarations(cls, extra): d = {'one': seq} d.update(extra) return d @classmethod def _generate_next_sequence(cls): return 1 ab = containers.AttributeBuilder(FakeFactory, extra={'one': seq2}) self.assertEqual({'one': 'yy1'}, ab.build(create=False))
class TestObjectFactory(Factory): one = declarations.Sequence(lambda n: 'one' + n) two = declarations.Sequence(lambda n: 'two' + n)
class TestObjectFactory(Factory): one = declarations.Sequence(lambda a: a)