diff --git a/edgy/testing/factory/base.py b/edgy/testing/factory/base.py index f8cb6544..3a636bdb 100644 --- a/edgy/testing/factory/base.py +++ b/edgy/testing/factory/base.py @@ -76,7 +76,6 @@ def build( values[name] = field(faker=faker, parameters=current_parameters_or_callback) values.update(self.__kwargs__) values.update(overwrites) - result = self.meta.model(**values) if getattr(self, "database", None) is not None: result.database = self.database diff --git a/tests/factory/test_factory.py b/tests/factory/test_factory.py index 0e4da3c8..d522839b 100644 --- a/tests/factory/test_factory.py +++ b/tests/factory/test_factory.py @@ -45,28 +45,35 @@ class Meta: assert UserFactory.meta.registry == models -def test_can_generate_and_overwrite(): +def test_can_generate_overwrite_and_exclude(): class UserFactory(ModelFactory): class Meta: model = User + id = FactoryField(exclude=True) + class ProductFactory(ModelFactory): class Meta: model = Product + id = FactoryField(exclude=True) name = FactoryField() user = UserFactory().build() + assert not hasattr(user, "id") assert user.database == database product = ProductFactory().build() + assert not hasattr(product, "id") assert product.user is not user + assert product.database == database - product = ProductFactory().build(overwrites={"user": user}) + product = ProductFactory().build(overwrites={"user": user, "id": 999}) - assert product.database == database + assert product.id == 999 assert product.user is user + assert product.database == database def test_can_generate_and_parametrize():