django-faker-again

This is yet another Faker supporting library for Django.


License
Apache-2.0
Install
pip install django-faker-again==0.1.0a1

Documentation

Discontinuation Announcement

This project was meant to be a replacement for joke2k's django-faker, however it is archived due to the limitation of my development time.

However, there are possibly better alternatives. For instance, I find it quite easier and better to use faker with Django.

An Example for Pytest and Django

After you install the original faker, all you have to do is to create a couple of fixtures.

Assuming I have a model as below:

class Contact(models.Model):
    name = models.CharField(max_length=64)
    surname = models.CharField(max_length=64)

Now, we need a couple of fixtures:

@pytest.fixture(scope="module")
def fake():
    return faker.Faker()

@pytest.fixture
def contact_factory(fake):
    def factory(**kwargs):
        name = kwargs.pop("name", fake.first_name())
        surname = kwargs.pop("surname", fake.last_name())
        return Contact.objects.create(name=name, surname=surname)
    return factory

Now we can use contact_factory in our test case as below:

def test_whatever(contact_factory):
    contact1 = contact_factory(name="John")  # John <random>
    contact2 = contact_factory(surname="Doe") # <random> Doe
    contact3 = contact_factory() # <random> <random>

django-faker-again

PyPI - Version PyPI - License PyPI - Python Version Travis Coveralls github

This is yet another Faker supporting library for Django. There are many alternatives such as joke2k's solution and gregmuellegger's solution, but most of these libraries have older or broken dependencies and some does not even support Django 1.10+.

That's why this project tends to provide the ease of use of Faker with Django, yet the architecture of the project can be different from alternatives, so keep in mind that it will not compatible with solutions given above.

How to Use

The documentation will be available in no time.