How to use the mixer.mix_types.Field 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 / main.py View on Github external
def __load_fields(self):
        """ Return scheme's fields. """
        for fname in dir(self.__scheme):
            if fname.startswith('_'):
                continue
            prop = getattr(self.__scheme, fname)
            yield fname, t.Field(prop, fname)
github klen / mixer / mixer / main.py View on Github external
def gen_value(self, field_name, field, fake=None, unique=False):
        """ Generate values from basic types.

        :return : (name, value) for later use

        """
        fake = self.__fake if fake is None else fake
        if not field:
            field = t.Field(getattr(self.__scheme, field_name, None), field_name)

        fab = self.get_fabric(field, field_name, fake=fake)

        try:
            value = fab()
        except ValueError:
            value = None
        except Exception as exc:
            LOGGER.exception(exc)
            raise ValueError("Generation for %s (%s) has been stopped. Exception: %s" % (
                field_name, self.__scheme.__name__, exc))

        if unique and value is not SKIP_VALUE:
            counter = 0
            try:
                while value in self.__gen_values[field_name]:
github klen / mixer / mixer / backend / yadm.py View on Github external
def __load_fields(self):
        for fname, field in self.__scheme.__fields__.items():
            yield fname, t.Field(field, fname)
github klen / mixer / mixer / backend / django.py View on Github external
def __load_fields(self):
        private_fields = getattr(self.__scheme._meta, 'private_fields', [])

        for field in private_fields:
            yield field.name, t.Field(field, field.name)

        for field in self.__scheme._meta.fields:

            if isinstance(field, models.AutoField)\
                    and self.__mixer and self.__mixer.params.get('commit'):
                continue

            yield field.name, t.Field(field, field.name)

        for field in self.__scheme._meta.local_many_to_many:
            yield field.name, t.Field(field, field.name)
github klen / mixer / mixer / backend / pony.py View on Github external
def __load_fields(self):
        for attr in self.__scheme._attrs_:
            yield attr.column, t.Field(attr, attr.column)
github klen / mixer / mixer / backend / sqlalchemy.py View on Github external
def __load_fields(self):
        """ Prepare SQLALchemyTypeMixer.

        Select columns and relations for data generation.

        """
        mapper = self.__scheme._sa_class_manager.mapper
        relations = set()
        if hasattr(mapper, 'relationships'):
            for rel in mapper.relationships:
                relations |= rel.local_columns
                yield rel.key, t.Field(rel, rel.key)

        for key, column in mapper.columns.items():
            if column not in relations:
                yield key, t.Field(column, key)
github klen / mixer / mixer / backend / sqlalchemy.py View on Github external
def __load_fields(self):
        """ Prepare SQLALchemyTypeMixer.

        Select columns and relations for data generation.

        """
        mapper = self.__scheme._sa_class_manager.mapper
        relations = set()
        if hasattr(mapper, 'relationships'):
            for rel in mapper.relationships:
                relations |= rel.local_columns
                yield rel.key, t.Field(rel, rel.key)

        for key, column in mapper.columns.items():
            if column not in relations:
                yield key, t.Field(column, key)
github klen / mixer / mixer / backend / mongoengine.py View on Github external
def __load_fields(self):
        for fname, field in self.__scheme._fields.items():

            yield fname, t.Field(field, fname)