Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devkral committed Jan 15, 2025
1 parent fe8ee3e commit 45d986b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion edgy/testing/factory/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions tests/factory/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 45d986b

Please sign in to comment.