How to use the mixer.main.faker function in mixer

To help you get started, we’ve selected a few mixer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github klen / mixer / mixer / backend / marshmallow.py View on Github external
            return lambda: [fab() for _ in range(faker.small_positive_integer(4))]
github klen / mixer / mixer / backend / marshmallow.py View on Github external
        fields.DateTime: lambda: faker.date_time().isoformat(),
        fields.Nested: get_nested,
github klen / mixer / mixer / backend / django.py View on Github external
models.DateField: dt.date,
        models.DecimalField: decimal.Decimal,
        models.EmailField: t.EmailString,
        models.FloatField: float,
        models.GenericIPAddressField: t.IPString,
        models.IPAddressField: t.IP4String,
        models.IntegerField: int,
        models.PositiveSmallIntegerField: t.PositiveSmallInteger,
        models.SmallIntegerField: t.SmallInteger,
        models.TextField: t.Text,
        models.TimeField: dt.time,
        models.URLField: t.URL,
    }

    generators = {
        models.BinaryField: faker.pybytes,
        models.DateTimeField: get_datetime,
        models.FileField: get_file,
        models.FilePathField: lambda: MOCK_FILE,
        models.ForeignKey: get_relation,
        models.ImageField: get_image,
        models.ManyToManyField: get_relation,
        models.OneToOneField: get_relation,
    }


class TypeMixerMeta(BaseTypeMixerMeta):

    """ Load django models from strings. """

    def __new__(mcs, name, bases, params):
        """ Associate Scheme with Django models.
github klen / mixer / mixer / backend / mongoengine.py View on Github external
types = {
        BooleanField: bool,
        DateTimeField: datetime.datetime,
        DecimalField: decimal.Decimal,
        EmailField: t.EmailString,
        FloatField: float,
        IntField: int,
        StringField: str,
        URLField: t.URL,
        UUIDField: t.UUID,
    }

    generators = {
        GenericReferenceField: get_generic_reference,
        GeoPointField: faker.coordinates,
        LineStringField: get_linestring,
        ObjectIdField: get_objectid,
        PointField: get_pointfield,
        PolygonField: get_polygon,
    }


class TypeMixer(BaseTypeMixer):

    """ TypeMixer for Mongoengine. """

    factory = GenFactory

    def make_fabric(self, me_field, field_name=None, fake=None, kwargs=None): # noqa
        """ Make a fabric for field.
github klen / mixer / mixer / backend / django.py View on Github external
def get_datetime(**params):
    """ Support Django TZ support. """
    return faker.date_time(tzinfo=UTC if settings.USE_TZ else None)