aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources/factories.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-05-16 17:46:21 +0100
committerMatthew Lemon <y@yulqen.org>2024-05-16 17:46:21 +0100
commit557b2f0d01d6177f14c96fda8bf39cfd3f22f6ac (patch)
treec6472ade648b8e80140f06409a7ac96cdc388b9f /pyblackbird_cc/resources/factories.py
parent55e5dfbd51924f1f23e5a651d830206be01e376c (diff)
wip: working on setting up the tests
Diffstat (limited to 'pyblackbird_cc/resources/factories.py')
-rw-r--r--pyblackbird_cc/resources/factories.py45
1 files changed, 42 insertions, 3 deletions
diff --git a/pyblackbird_cc/resources/factories.py b/pyblackbird_cc/resources/factories.py
index b78822d..af818a1 100644
--- a/pyblackbird_cc/resources/factories.py
+++ b/pyblackbird_cc/resources/factories.py
@@ -1,5 +1,7 @@
import factory
+from .models import PDFResource
+
class ResourceTypeModelFactory(factory.django.DjangoModelFactory):
class Meta:
@@ -17,15 +19,52 @@ class ResourceCategoryModelFactory(factory.django.DjangoModelFactory):
name = factory.Sequence(lambda n: f"Default Resource Category {n}")
+class PDFResourceModelFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = "resources.PDFResource"
+
+ resource = factory.SubFactory("resources.tests.factories.ResourceModelFactory")
+ file_name = factory.Sequence(lambda n: f"test_{n}.pdf")
+ file_size = factory.Faker("random_int", min=0, max=1000)
+
+
+class PDFPageSnapshotModelFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = "resources.PDFPageSnapshot"
+
+ name = factory.Sequence(lambda n: f"pdf_page_snapshot_{n}")
+ file_name = factory.Sequence(lambda n: f"pdf_page_snapshot_{n}.jpg")
+ pdf_file = factory.SubFactory("pyblackbird_cc.resources.factories.PDFResourceModelFactory")
+
+
class ResourceModelFactory(factory.django.DjangoModelFactory):
class Meta:
model = "resources.Resource"
name = factory.Sequence(lambda n: f"Default Resource {n}")
thumbnail_filenames = factory.Sequence(lambda n: [f"thumbnail_{n}.jpg"])
- resource_type = factory.SubFactory(ResourceTypeModelFactory)
- main_resource_category = factory.SubFactory(ResourceCategoryModelFactory)
- additional_resource_category = factory.SubFactory(ResourceCategoryModelFactory)
+ resource_type = factory.SubFactory(
+ "pyblackbird_cc.resources.factories.ResourceTypeModelFactory"
+ )
+ main_resource_category = factory.SubFactory(
+ "pyblackbird_cc.resources.factories.ResourceCategoryModelFactory"
+ )
+ additional_resource_category = factory.SubFactory(
+ "pyblackbird_cc.resources.factories.ResourceCategoryModelFactory"
+ )
description = factory.Sequence(lambda n: f"Default description {n}")
age_range = factory.Iterator(["5-7", "7-10", "10+"])
curriculum = factory.Iterator(["English", "Scottish"])
+
+ pdfs = factory.RelatedFactoryList(
+ "pyblackbird_cc.resources.factories.PDFResourceModelFactory",
+ factory_related_name="resource",
+ size=3,
+ )
+
+ # TODO: Don't think we can include this this way - we are getting import issues
+ # pdf_snapshots = factory.RelatedFactoryList(
+ # "pyblackbird_cc.resources.factories.PDFPageSnapshotModelFactory",
+ # factory_related_name="pdfs",
+ # size=20,
+ # )