Code Monkey home page Code Monkey logo

mimesis-factory's Introduction

⛔️ DEPRECATED

This repository is now deprecated. We have integrated mimesis-factory into mimesis itself, and there is no longer a need to use a separate package. Refer to the Integration with factory_boy section for more details.

mimesis_factory

test codecov PyPI version wemake-python-styleguide

Description

Mimesis integration for factory_boy.

Installation

pip install mimesis_factory

Usage

Look at the example below and you’ll understand how it works:

class Account(object):
    def __init__(self, username, email, name, surname, age):
        self.username = username
        self.email = email
        self.name = name
        self.surname = surname
        self.age = age

Now, use the MimesisField class from mimesis_factory to define how fake data is generated:

import factory
from mimesis_factory import MimesisField

from account import Account


class AccountFactory(factory.Factory):
    class Meta(object):
        model = Account

    username = MimesisField('username', template='l_d')
    name = MimesisField('name', gender='female')
    surname = MimesisField('surname', gender='female')
    age = MimesisField('age', minimum=18, maximum=90)
    email = factory.LazyAttribute(
        lambda instance: '{0}@example.org'.format(instance.username)
    )
    access_token = MimesisField('token', entropy=32)

pytest

We also recommend to use pytest-factoryboy. This way it will be possible to integrate your factories into pytest fixtures.

License

mimesis_factory is released under the MIT License.

mimesis-factory's People

Contributors

casio avatar dependabot-preview[bot] avatar dependabot-support avatar lk-geimfari avatar proha avatar sobolevn avatar vovanbo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mimesis-factory's Issues

Inheritance of providers override attributes of the superclass.

It's happening for some classes because we use this:

class LocaleDepProvider(Address, Business, Code, Datetime,
                        Personal, Science, Text, Food):
    pass


class CommonProvider(ClothingSizes, Development, File, Hardware,
                     Internet, Numbers, Path, Structured, Transport,
                     UnitSystem, Games, Cryptographic):
    pass


class Provider(LocaleDepProvider, CommonProvider):
    pass

Where each class has attribute self._data. Given how the inheritance tree works, errors are possible.

How do I pass a random seed to fields?

I'm not sure how to seed fields in a factory class (or ideally, the entire class at once).

I tried doing something like the following, which does not work.

class AccountFactory(factory.Factory):
    class Meta(object):
        model = Account

    email = MimesisField('email', seed="randomseed")

Any pointers?

Thank you!

Django models support

We need to provide django support.

Things to be done:

  1. Tests
  2. Docs on how to bind these two packages together
  3. Examples

Cannot install from source to get latest features

Is there any way to install this from source using pip? I would like to use some of the provider functionality that has been added in since the 0.1.0 release last June. I tried

pip install -e git+https://github.com/mimesis-lab/mimesis-factory.git#egg=mimesis_factory

, but it is failing because there is no setup.py in the repository. This is the error I got:

$ pip install -e git+https://github.com/mimesis-lab/mimesis-factory.git#egg=mimesis_factory
Obtaining mimesis_factory from git+https://github.com/mimesis-lab/mimesis-factory.git#egg=mimesis_factory
  Cloning https://github.com/mimesis-lab/mimesis-factory.git to /home/matt/virtualenvs/stream/src/mimesis-factory
  Installing build dependencies ... done
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/matt/virtualenvs/stream/lib/python3.6/tokenize.py", line 452, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/home/matt/virtualenvs/stream/src/mimesis-factory/setup.py'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /home/matt/virtualenvs/stream/src/mimesis-factory/

What is the recommended way to install a more recent version of mimesis-factory? I'd be happy to help out if the solution is to add a setup.py.

Package is not installable

Since setup.py imports the module itself, it tries also import it's dependencies.
But there are no dependencies at this time yet. So, installation breaks.

Here's the line I am talking about:
https://github.com/mimesis-lab/mimesis-factory/blob/master/setup.py#L3

Output:

Installing mimesis-factory…
Collecting mimesis-factory
  Downloading mimesis_factory-0.0.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/qn/2gssw9hx48g81chw0398hlrr0000gn/T/pip-build-dx_ail0m/mimesis-factory/setup.py", line 3, in <module>
        from mimesis_factory import __version__
      File "/private/var/folders/qn/2gssw9hx48g81chw0398hlrr0000gn/T/pip-build-dx_ail0m/mimesis-factory/mimesis_factory/__init__.py", line 1, in <module>
        from mimesis_factory.main import Mimesis
      File "/private/var/folders/qn/2gssw9hx48g81chw0398hlrr0000gn/T/pip-build-dx_ail0m/mimesis-factory/mimesis_factory/main.py", line 1, in <module>
        from factory import declarations
    ModuleNotFoundError: No module named 'factory'
    
    ----------------------------------------

Error:  An error occurred while installing mimesis-factory!
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/qn/2gssw9hx48g81chw0398hlrr0000gn/T/pip-build-dx_ail0m/mimesis-factory/

Support for factory-boy 3+

Hey factory-boy have released version 3 but it looks like mimesis-factory depends on factory-boy (>=2.11,<3.0). Could we get this supported?

Much thanks for a great library!

Move mimesis_factory to mimesis.plugins

Starting from Mimesis version 15.0.0, this package will become a part of Mimesis. Once this transition is completed, this repository will be archived.

Rationale

This will help us always keep this package up-to-date.

Deps

Mimesis will still remain dependency-free. To utilize this plugin, developers will need to install factory_boy explicitly.

Usage

Here is an example of usage:

import factory
from mimesis.plugins.factory import MimesisField

from account import Account


class AccountFactory(factory.Factory):
    class Meta(object):
        model = Account

    username = MimesisField('username', template='l_d')
    name = MimesisField('name', gender='female')
    surname = MimesisField('surname', gender='female')
    age = MimesisField('age', minimum=18, maximum=90)
    email = factory.LazyAttribute(
        lambda instance: '{0}@example.org'.format(instance.username)
    )
    access_token = MimesisField('token', entropy=32)

For discussion purposes

One thing I'm not sure about is the class name. Should we keep MimesisField, or perhaps use something like FactoryField?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.