aboutsummaryrefslogtreecommitdiffstats
path: root/alphabetlearning/resources/factories.py
diff options
context:
space:
mode:
Diffstat (limited to 'alphabetlearning/resources/factories.py')
-rw-r--r--alphabetlearning/resources/factories.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/alphabetlearning/resources/factories.py b/alphabetlearning/resources/factories.py
new file mode 100644
index 0000000..4075ab1
--- /dev/null
+++ b/alphabetlearning/resources/factories.py
@@ -0,0 +1,83 @@
+import itertools
+
+import factory
+
+from .models import PDFPageSnapshot
+from .models import PDFResource
+from .models import Resource
+from .models import ResourceCategory
+from .models import ResourceType
+
+
+class ResourceTypeModelFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = ResourceType
+ django_get_or_create = ("name",)
+
+ name = factory.Sequence(lambda n: f"Default Resource Type {n}")
+
+
+class ResourceCategoryModelFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = ResourceCategory
+ django_get_or_create = ("name",)
+
+ name = factory.Sequence(lambda n: f"Default Resource Category {n}")
+
+
+class PDFPageSnapshotModelFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = 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("alphabetlearning.resources.factories.PDFResourceModelFactory")
+
+
+class ResourceModelFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = Resource
+
+ name = factory.Sequence(lambda n: f"Default Resource {n}")
+ price = factory.Faker("pydecimal", left_digits=4, right_digits=2, positive=True)
+ thumbnail_filenames = factory.List(
+ [factory.Faker("file_name", extension="jpg") for _ in range(3)]
+ )
+ resource_type = factory.SubFactory(ResourceTypeModelFactory)
+ main_resource_category = factory.SubFactory(ResourceCategoryModelFactory)
+ subcategories = factory.RelatedFactoryList(ResourceCategoryModelFactory, size=2)
+ description = factory.Faker("paragraph")
+ card_description = factory.Faker("text", max_nb_chars=1000)
+ age_range = factory.Iterator(["5-7", "7-9", "9-11"])
+ curriculum = factory.Iterator(["English", "Scottish", "No curriculum"])
+ feature_slot = factory.Iterator(itertools.chain([1, 2, 3], itertools.repeat(None)))
+ created_at = factory.Faker("date_time_this_year")
+ updated_at = factory.Faker("date_time_this_month")
+
+ @factory.post_generation
+ def pdfs(self, create, extracted, **kwargs):
+ if not create:
+ return
+
+ if extracted:
+ for pdf in extracted:
+ self.pdf_resources.add(pdf)
+ else:
+ PDFResourceModelFactory.create_batch(3, resource=self)
+
+
+class ResourceSubcategoryModelFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = ResourceCategory
+ django_get_or_create = ("name",)
+
+ name = factory.Sequence(lambda n: f"Default Resource Subcategory {n}")
+
+
+class PDFResourceModelFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = PDFResource
+
+ resource = factory.SubFactory(ResourceModelFactory)
+ file_name = factory.Sequence(lambda n: f"test_{n}.pdf")
+ file_size = factory.Faker("random_int", min=0, max=1000)