aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources/factories.py
blob: af818a18e856ac4cbe196ce02588b097f4b8b31d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import factory

from .models import PDFResource


class ResourceTypeModelFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = "resources.ResourceType"
        django_get_or_create = ("name",)

    name = factory.Sequence(lambda n: f"Default Resource Type {n}")


class ResourceCategoryModelFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = "resources.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"

    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(
        "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,
    # )