Skip to content

Factories

hypha.apply.stream_forms.testing.factories

BLOCK_FACTORY_DEFINITION module-attribute

BLOCK_FACTORY_DEFINITION = {None: NON_FILE_BLOCK_FACTORY_DEFINITION, 'image': SubFactory(ImageFieldBlockFactory), 'file': SubFactory(FileFieldBlockFactory), 'multi_file': SubFactory(MultiFileFieldBlockFactory)}

FormFieldBlockFactory

Bases: StructBlockFactory

default_value class-attribute instance-attribute

default_value = Faker('sentence')

field_label class-attribute instance-attribute

field_label = Faker('sentence')

help_text class-attribute instance-attribute

help_text = LazyAttribute(lambda o: f'Help text for {__name__}')

Meta

model class-attribute instance-attribute

make_answer classmethod

make_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_answer(cls, params=None):
    params = params or {}
    return cls.default_value.evaluate(None, None, dict(params, locale=None))

make_form_answer classmethod

make_form_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_form_answer(cls, params=None):
    if params:
        return params
    return cls.make_answer(params or {})

CharFieldBlockFactory

Bases: FormFieldBlockFactory

field_label class-attribute instance-attribute

field_label = Faker('sentence')

help_text class-attribute instance-attribute

help_text = LazyAttribute(lambda o: f'Help text for {__name__}')

default_value class-attribute instance-attribute

default_value = Faker('sentence')

Meta

model class-attribute instance-attribute

make_answer classmethod

make_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_answer(cls, params=None):
    params = params or {}
    return cls.default_value.evaluate(None, None, dict(params, locale=None))

make_form_answer classmethod

make_form_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_form_answer(cls, params=None):
    if params:
        return params
    return cls.make_answer(params or {})

NumberFieldBlockFactory

Bases: FormFieldBlockFactory

field_label class-attribute instance-attribute

field_label = Faker('sentence')

help_text class-attribute instance-attribute

help_text = LazyAttribute(lambda o: f'Help text for {__name__}')

default_value class-attribute instance-attribute

default_value = 100

Meta

model class-attribute instance-attribute

make_form_answer classmethod

make_form_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_form_answer(cls, params=None):
    if params:
        return params
    return cls.make_answer(params or {})

make_answer classmethod

make_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_answer(cls, params=None):
    return cls.default_value

RadioFieldBlockFactory

Bases: FormFieldBlockFactory

default_value class-attribute instance-attribute

default_value = Faker('sentence')

field_label class-attribute instance-attribute

field_label = Faker('sentence')

help_text class-attribute instance-attribute

help_text = LazyAttribute(lambda o: f'Help text for {__name__}')

choices class-attribute instance-attribute

choices = ['first', 'second']

Meta

model class-attribute instance-attribute

make_form_answer classmethod

make_form_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_form_answer(cls, params=None):
    if params:
        return params
    return cls.make_answer(params or {})

make_answer classmethod

make_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_answer(cls, params=None):
    return cls.choices[0]

UploadableMediaFactory

Bases: FormFieldBlockFactory

field_label class-attribute instance-attribute

field_label = Faker('sentence')

help_text class-attribute instance-attribute

help_text = LazyAttribute(lambda o: f'Help text for {__name__}')

default_value class-attribute instance-attribute

default_value = FileField()

Meta

model class-attribute instance-attribute

make_form_answer classmethod

make_form_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_form_answer(cls, params=None):
    if params:
        return params
    return cls.make_answer(params or {})

make_answer classmethod

make_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_answer(cls, params=None):
    params = params or {}
    params.setdefault("data", b"this is some content")
    if params.get("filename") is None:
        params["filename"] = "test_example.pdf"
    file_name, file = cls.default_value._make_content(params)
    return SimpleUploadedFile(file_name, file.read())

ImageFieldBlockFactory

Bases: UploadableMediaFactory

field_label class-attribute instance-attribute

field_label = Faker('sentence')

help_text class-attribute instance-attribute

help_text = LazyAttribute(lambda o: f'Help text for {__name__}')

default_value class-attribute instance-attribute

default_value = ImageField()

Meta

model class-attribute instance-attribute

make_answer classmethod

make_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_answer(cls, params=None):
    params = params or {}
    params.setdefault("data", b"this is some content")
    if params.get("filename") is None:
        params["filename"] = "test_example.pdf"
    file_name, file = cls.default_value._make_content(params)
    return SimpleUploadedFile(file_name, file.read())

make_form_answer classmethod

make_form_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_form_answer(cls, params=None):
    if params:
        return params
    return cls.make_answer(params or {})

FileFieldBlockFactory

Bases: UploadableMediaFactory

default_value class-attribute instance-attribute

default_value = FileField()

field_label class-attribute instance-attribute

field_label = Faker('sentence')

help_text class-attribute instance-attribute

help_text = LazyAttribute(lambda o: f'Help text for {__name__}')

Meta

model class-attribute instance-attribute

make_answer classmethod

make_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_answer(cls, params=None):
    params = params or {}
    params.setdefault("data", b"this is some content")
    if params.get("filename") is None:
        params["filename"] = "test_example.pdf"
    file_name, file = cls.default_value._make_content(params)
    return SimpleUploadedFile(file_name, file.read())

make_form_answer classmethod

make_form_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_form_answer(cls, params=None):
    if params:
        return params
    return cls.make_answer(params or {})

MultiFileFieldBlockFactory

Bases: UploadableMediaFactory

default_value class-attribute instance-attribute

default_value = FileField()

field_label class-attribute instance-attribute

field_label = Faker('sentence')

help_text class-attribute instance-attribute

help_text = LazyAttribute(lambda o: f'Help text for {__name__}')

Meta

model class-attribute instance-attribute

make_form_answer classmethod

make_form_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_form_answer(cls, params=None):
    if params:
        return params
    return cls.make_answer(params or {})

make_answer classmethod

make_answer(params=None)
Source code in hypha/apply/stream_forms/testing/factories.py
@classmethod
def make_answer(cls, params=None):
    return [UploadableMediaFactory.make_answer() for _ in range(2)]