Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return lambda: [fab() for _ in range(faker.small_positive_integer(4))]
fields.DateTime: lambda: faker.date_time().isoformat(),
fields.Nested: get_nested,
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.
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.
def get_datetime(**params):
""" Support Django TZ support. """
return faker.date_time(tzinfo=UTC if settings.USE_TZ else None)