def make_fixture(model_class, **kwargs):
    """
    Take the model_klass and generate a fixure for it

    Args:
        model_class (MongoEngine Document): model for which a fixture
            is needed
        kwargs (dict): any overrides instead of random values

    Returns:
        dict for now, other fixture types are not implemented yet
    """
    all_fields = get_fields(model_class)

    fields_for_random_generation = map(
        lambda x: getattr(model_class, x), all_fields
    )

    overrides = {}

    for kwarg, value in kwargs.items():
        if kwarg in all_fields:
            kwarg_field = getattr(model_class, kwarg)
            fields_for_random_generation.remove(kwarg_field)
            overrides.update({kwarg_field: value})

    random_values = get_random_values(fields_for_random_generation)

    values = dict(overrides, **random_values)

    assert len(all_fields) == len(values), (
        "Mismatch in values, {} != {}".format(
            len(all_fields), len(values)
        )
    )
    data = {k.name: v for k, v in values.items()}
    return model_class(**data)
def make_fixture ( model_class , ** kwargs ) : all_fields = get_fields ( model_class ) fields_for_random_generation = map ( lambda x : getattr ( model_class , x ) , all_fields ) overrides = { } for kwarg , value in kwargs . items ( ) : if kwarg in all_fields : kwarg_field = getattr ( model_class , kwarg ) fields_for_random_generation . remove ( kwarg_field ) overrides . update ( { kwarg_field : value } ) random_values = get_random_values ( fields_for_random_generation ) values = dict ( overrides , ** random_values ) assert len ( all_fields ) == len ( values ) , ( "Mismatch in values, {} != {}" . format ( len ( all_fields ) , len ( values ) ) ) data = { k . name : v for k , v in values . items ( ) } return model_class ( ** data )
Take the model_klass and generate a fixure for it

    Args:
        model_class (MongoEngine Document): model for which a fixture
            is needed
        kwargs (dict): any overrides instead of random values

    Returns:
        dict for now, other fixture types are not implemented yet