diff options
author | Matthew Lemon <y@yulqen.org> | 2024-05-16 21:00:47 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-05-16 21:00:47 +0100 |
commit | 9f9b3d588dfabe8c57306d9adf371968a60364d3 (patch) | |
tree | e395af5bde21474e5e9a020952fb23f299a676a2 /pyblackbird_cc/resources/factories.py | |
parent | 557b2f0d01d6177f14c96fda8bf39cfd3f22f6ac (diff) |
wip: improving the test setup
Diffstat (limited to '')
-rw-r--r-- | pyblackbird_cc/resources/factories.py | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/pyblackbird_cc/resources/factories.py b/pyblackbird_cc/resources/factories.py index af818a1..4bca89f 100644 --- a/pyblackbird_cc/resources/factories.py +++ b/pyblackbird_cc/resources/factories.py @@ -1,11 +1,11 @@ import factory -from .models import PDFResource +from .models import PDFResource, PDFPageSnapshot, Resource, ResourceCategory, ResourceType class ResourceTypeModelFactory(factory.django.DjangoModelFactory): class Meta: - model = "resources.ResourceType" + model = ResourceType django_get_or_create = ("name",) name = factory.Sequence(lambda n: f"Default Resource Type {n}") @@ -13,24 +13,15 @@ class ResourceTypeModelFactory(factory.django.DjangoModelFactory): class ResourceCategoryModelFactory(factory.django.DjangoModelFactory): class Meta: - model = "resources.ResourceCategory" + model = ResourceCategory django_get_or_create = ("name",) 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" + model = PDFPageSnapshot name = factory.Sequence(lambda n: f"pdf_page_snapshot_{n}") file_name = factory.Sequence(lambda n: f"pdf_page_snapshot_{n}.jpg") @@ -39,19 +30,13 @@ class PDFPageSnapshotModelFactory(factory.django.DjangoModelFactory): class ResourceModelFactory(factory.django.DjangoModelFactory): class Meta: - model = "resources.Resource" + model = Resource name = factory.Sequence(lambda n: f"Default Resource {n}") thumbnail_filenames = factory.Sequence(lambda n: [f"thumbnail_{n}.jpg"]) - 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" - ) + resource_type = factory.SubFactory(ResourceTypeModelFactory) + main_resource_category = factory.SubFactory(ResourceCategoryModelFactory) + additional_resource_category = factory.SubFactory(ResourceCategoryModelFactory) description = factory.Sequence(lambda n: f"Default description {n}") age_range = factory.Iterator(["5-7", "7-10", "10+"]) curriculum = factory.Iterator(["English", "Scottish"]) @@ -68,3 +53,12 @@ class ResourceModelFactory(factory.django.DjangoModelFactory): # factory_related_name="pdfs", # size=20, # ) + + +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) |