Skip to content

Commit

Permalink
Add ProductFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
brylie committed Jul 7, 2023
1 parent 136c2bd commit 4e39b8d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions store/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import factory
from factory.django import DjangoModelFactory
from wagtail.rich_text import RichText
from .models import Product


class ProductFactory(DjangoModelFactory):
class Meta:
model = Product

title = factory.Sequence(lambda n: f"Product {n}")
description = RichText("Product description")
price = factory.Faker( # type: ignore
"pydecimal",
left_digits=2,
right_digits=2,
positive=True,
)
available = factory.Iterator([True, False])

# TODO: add a MockWagtailImage class
# and use it here
# image = factory.LazyAttribute(lambda _: get_test_image_file())

0 comments on commit 4e39b8d

Please sign in to comment.