factories.py 3.8 KB
Newer Older
1 2
# Factories are self documenting
# pylint: disable=missing-docstring
muhammad-ammar committed
3
import factory
4
from uuid import uuid4
muhammad-ammar committed
5
from django.core.files.base import ContentFile
6
from factory.django import DjangoModelFactory, ImageField
7

8 9
from student.models import LinkedInAddToProfileConfiguration

10
from certificates.models import (
11
    GeneratedCertificate, CertificateStatuses, CertificateHtmlViewConfiguration, CertificateWhitelist, BadgeAssertion,
12
    BadgeImageConfiguration, CertificateInvalidation,
13
)
14

15

16 17
class GeneratedCertificateFactory(DjangoModelFactory):

muhammad-ammar committed
18 19
    class Meta(object):
        model = GeneratedCertificate
20 21 22

    course_id = None
    status = CertificateStatuses.unavailable
23
    mode = GeneratedCertificate.MODES.honor
24
    name = ''
25
    verify_uuid = uuid4().hex
26 27


28 29
class CertificateWhitelistFactory(DjangoModelFactory):

muhammad-ammar committed
30 31
    class Meta(object):
        model = CertificateWhitelist
32 33 34

    course_id = None
    whitelist = True
35
    notes = 'Test Notes'
36 37


38 39 40 41 42 43 44 45 46
class CertificateInvalidationFactory(DjangoModelFactory):

    class Meta(object):
        model = CertificateInvalidation

    notes = 'Test Notes'
    active = True


47
class BadgeAssertionFactory(DjangoModelFactory):
muhammad-ammar committed
48 49
    class Meta(object):
        model = BadgeAssertion
50 51

    mode = 'honor'
52 53 54 55 56
    data = {
        'image': 'http://www.example.com/image.png',
        'json': {'id': 'http://www.example.com/assertion.json'},
        'issuer': 'http://www.example.com/issuer.json',
    }
57 58 59 60


class BadgeImageConfigurationFactory(DjangoModelFactory):

muhammad-ammar committed
61 62
    class Meta(object):
        model = BadgeImageConfiguration
63 64

    mode = 'honor'
muhammad-ammar committed
65 66 67 68 69 70 71
    icon = factory.LazyAttribute(
        lambda _: ContentFile(
            ImageField()._make_data(  # pylint: disable=protected-access
                {'color': 'blue', 'width': 50, 'height': 50, 'format': 'PNG'}
            ), 'test.png'
        )
    )
72 73


74 75
class CertificateHtmlViewConfigurationFactory(DjangoModelFactory):

muhammad-ammar committed
76 77
    class Meta(object):
        model = CertificateHtmlViewConfiguration
78 79 80 81

    enabled = True
    configuration = """{
            "default": {
82
                "accomplishment_class_append": "accomplishment-certificate",
83
                "platform_name": "edX",
84
                "company_about_url": "http://www.edx.org/about-us",
85 86 87
                "company_privacy_url": "http://www.edx.org/edx-privacy-policy",
                "company_tos_url": "http://www.edx.org/edx-terms-service",
                "company_verified_certificate_url": "http://www.edx.org/verified-certificate",
88
                "document_stylesheet_url_application": "/static/certificates/sass/main-ltr.css",
89
                "logo_src": "/static/certificates/images/logo-edx.png",
90 91 92 93
                "logo_url": "http://www.edx.org"
            },
            "honor": {
                "certificate_type": "Honor Code",
94 95
                "certificate_title": "Certificate of Achievement",
                "logo_url": "http://www.edx.org/honor_logo.png"
96 97 98
            },
            "verified": {
                "certificate_type": "Verified",
99
                "certificate_title": "Verified Certificate of Achievement"
100 101
            },
            "xseries": {
102 103
                "certificate_title": "XSeries Certificate of Achievement",
                "certificate_type": "XSeries"
104 105 106 107 108 109 110
            },
            "microsites": {
                "testmicrosite": {
                    "company_about_url": "http://www.testmicrosite.org/about-us",
                    "company_privacy_url": "http://www.testmicrosite.org/edx-privacy-policy",
                    "company_tos_url": "http://www.testmicrosite.org/edx-terms-service"
                }
111 112
            }
        }"""
113 114 115 116


class LinkedInAddToProfileConfigurationFactory(DjangoModelFactory):

muhammad-ammar committed
117 118
    class Meta(object):
        model = LinkedInAddToProfileConfiguration
119 120 121 122

    enabled = True
    company_identifier = "0_0dPSPyS070e0HsE9HNz_13_d11_"
    trk_partner_name = 'unittest'