"""
        pattern = "{{first_name}}{{city_suffix}}"
        return self.generator.parse(pattern)

    def municipality(self):
        """ Formatter for generating danish municipality names
        """
        return self.generator.parse("{{city}} kommune")

    def street_name(self):
        """ Formatter for generating danish street names
        """
        return self.generator.parse("{{name}}s {{street_suffix}}")


Faker.add_provider(CodingPiratesProvider, locale="dk_DK")
Faker.add_provider(DanishProvider, locale="dk_DK")


LOCALE = "dk_DK"
TIMEZONE = pytz.timezone("Europe/Copenhagen")
# Setting default locale (this is not documented or intended by factory_boy)
Faker._DEFAULT_LOCALE = LOCALE


def datetime_after(dt):
    """
    For use with lazy attribute to generate DateTime's after the given
    datetime.
    """
    END_OF_TIME = date.today() + timedelta(days=60 * 365)
Пример #2
0
from datetime import timedelta
from random import randrange

from factory import (Faker, DjangoModelFactory, LazyAttribute, post_generation)

from networkapi.utility.faker import ImageProvider
from networkapi.utility.faker.helpers import reseed
from networkapi.milestones.models import Milestone

Faker.add_provider(ImageProvider)


class MilestoneFactory(DjangoModelFactory):
    class Meta:
        model = Milestone
        exclude = (
            'headline_sentence',
            'link_label_sentence',
            'milestone_length',
        )

    # Model Attributes
    headline = LazyAttribute(lambda o: o.headline_sentence.rstrip('.'))
    description = Faker('paragraph',
                        nb_sentences=4,
                        variable_nb_sentences=True)
    link_label = LazyAttribute(lambda o: o.link_label_sentence.rstrip('.'))
    link_url = Faker('url')
    start_date = Faker('date_time_between', start_date='-30d', end_date='+30d')
    end_date = LazyAttribute(
        lambda o: o.start_date + timedelta(days=o.milestone_length))
Пример #3
0
    def __init__(self, generator):
        super().__init__(generator)
        self._rand = random.Random(42)

    def subscription_state(self):
        return _SubscriptionStateProvider._STATES[self._rand.randrange(
            0, len(_SubscriptionStateProvider._STATES))]


class _LanguageProvider(BaseProvider):
    _LANGUAGES = [
        "eng",
        "spa",
        "kor",
        "cmn",
        "vie",
    ]

    def __init__(self, generator):
        super().__init__(generator)
        self._rand = random.Random(24)

    def language(self):
        return _LanguageProvider._LANGUAGES[self._rand.randrange(
            0, len(_LanguageProvider._LANGUAGES))]


Faker.add_provider(_SubscriptionStateProvider)
Faker.add_provider(_LanguageProvider)
Пример #4
0
from django.conf import settings
from factory.django import DjangoModelFactory
from wagtail_factories import (PageFactory, ImageFactory)
from factory import (Faker, SubFactory, LazyAttribute, Trait)
import networkapi.wagtailpages.models
from networkapi.highlights.factory import HighlightFactory
from networkapi.news.factory import NewsFactory
from networkapi.utility.faker import StreamfieldProvider

streamfield_fields = [
    'header', 'paragraph', 'image', 'spacer', 'image_text2', 'quote'
]

Faker.add_provider(StreamfieldProvider)

sentence_faker: Faker = Faker('sentence', nb_words=3, variable_nb_words=False)
header_faker: Faker = Faker('sentence', nb_words=6, variable_nb_words=True)
description_faker: Faker = Faker('paragraphs', nb=6)


class CTAFactory(DjangoModelFactory):
    class Meta:
        abstract = True
        exclude = (
            'header_text',
            'description_text',
        )

    name = Faker('text', max_nb_chars=35)
    header = LazyAttribute(lambda o: o.header_text.rstrip('.'))
    description = LazyAttribute(lambda o: ''.join(o.description_text))
Пример #5
0
from factory import Faker
from factory.base import FactoryMetaClass
from graphene import ResolveInfo
from minio import Minio
from minio.definitions import Object as MinioStatObject
from pytest_factoryboy import register

from .caluma_core.faker import MultilangProvider
from .caluma_core.models import HistoricalRecords
from .caluma_form import factories as form_factories
from .caluma_logging import factories as logging_factories
from .caluma_user.models import AnonymousUser, OIDCUser
from .caluma_workflow import factories as workflow_factories
from .schema import schema

Faker.add_provider(MultilangProvider)


def register_module(module):
    for _, obj in inspect.getmembers(module):
        if isinstance(obj, FactoryMetaClass) and not obj._meta.abstract:
            register(obj)


register_module(form_factories)
register_module(logging_factories)
register_module(workflow_factories)


@pytest.fixture(scope="function", autouse=True)
def _autoclear_cache():
from random import choice

from app import create_app
from app.model import Todo
from factory import Factory, Faker, Sequence
from faker.providers import BaseProvider
from pytest import fixture


class TaksProvider(BaseProvider):
    def todo_state(self):
        return choice(['todo', 'doing', 'done'])


Faker.add_provider(TaksProvider)

schema = {
    "type": "array",
    'properties': {
        'id': {
            'type': 'integer'
        },
        'name': {
            'type': 'string'
        },
        'description': {
            'type': 'string'
        },
        'urgent': {
            'type': 'boolean'
        },
Пример #7
0
from factory import Factory, Faker

from serial import Task
from fakes import TaskProvider

Faker.add_provider(TaskProvider)


class TaskFactory(Factory):
    class Meta:
        model = Task

    task_name = Faker('task_name')
    state = Faker('state')
Пример #8
0
SPECIES = OrderedDict([('mouse', 0.95), ('rat', 0.05)])


class DjauntyProvider(BaseProvider):
    def doi(self):
        num = self.random_int(min=1000, max=999999999)
        post_size = self.random_int(min=1, max=10)
        post = self.bothify('?' * post_size).lower()
        return f'10.{num}/{post}'

    def keyword(self):
        letters = self.random_int(min=6, max=16)
        return self.lexify('?' * letters).lower()


Faker.add_provider(company)
Faker.add_provider(date_time)
Faker.add_provider(DjauntyProvider)


class Optional(LazyFunction):
    def evaluate(self, instance, step, extra):
        if random() < instance.null_ratio:
            return None
        else:
            return self.function.evaluate(instance, step, extra)


class PublicationFactory(DjangoModelFactory):
    class Meta:
        model = Publication