Skip to content

Commit

Permalink
added factory-boy example # noqa
Browse files Browse the repository at this point in the history
  • Loading branch information
fcurella committed Apr 2, 2014
1 parent da737b5 commit 57ecb38
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ In a python environment with faker installed you can use it with:
> 'bar'


# Use with factory-boy

import factory
from faker import Factory as FakerFactory
from myapp.models import Book

faker = FakerFactory.create()


class Book(factory.Factory):
FACTORY_FOR = Book

title = factory.LazyAttribute(lambda x: faker.sentence(nb_words=4))
author_name = factory.LazyAttribute(lambda x: faker.name())


# Seeding the Generator

You may want to get always the same generated data - for instance when using Faker for unit testing purposes.
Expand All @@ -179,7 +195,6 @@ Calling the same script twice with the same seed produces the same results.
print fake.name() # Margaret Boehm



# Tests

Run tests:
Expand All @@ -195,7 +210,6 @@ Write documentation for providers:
$ python -m faker > docs.txt



## License

Faker is released under the MIT Licence. See the bundled LICENSE file for details.
Expand Down
19 changes: 19 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ How to create a Provider
> 'bar'


Use with factory-boy
--------------------

::

import factory
from faker import Factory as FakerFactory
from myapp.models import Book

faker = FakerFactory.create()


class Book(factory.Factory):
FACTORY_FOR = Book

title = factory.LazyAttribute(lambda x: faker.sentence(nb_words=4))
author_name = factory.LazyAttribute(lambda x: faker.name())


Seeding the Generator
---------------------

Expand Down

0 comments on commit 57ecb38

Please sign in to comment.