Skip to content

Commit

Permalink
Better README examples
Browse files Browse the repository at this point in the history
  • Loading branch information
paulocheque committed Mar 28, 2020
1 parent fc76b39 commit cc44826
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,49 @@ Documentation
http://django-dynamic-fixture.readthedocs.org/en/latest/index.html


Basic example
-------------
Basic examples
--------------

> Customize only the important details of the test:
```python
from ddf import G
from my_library import Author, Book

def test_search_book_by_author():
author1 = G(Author)
author2 = G(Author)
book1 = G(Book, authors=[author1], main_author__name='Eistein')
book1 = G(Book, authors=[author1])
book2 = G(Book, authors=[author2])
books = Book.objects.search_by_author(author1.name)
assert book1 in books
assert book2 not in books
```

> Using some goodies to keep the test code smaller:
```python
from ddf import G

def test_search_book_by_author():
author1, author2 = G('my_library.Author', n=2)
book1 = G('my_library.Book', authors=[author1])
book2 = G('my_library.Book', authors=[author2])
books = Book.objects.search_by_author(author1.name)
assert book1 in books
assert book2 not in books
```

> Configuring data from relationship fields:
```python
from ddf import G

def test_search_book_by_author():
book1 = G(Book, main_author__name='Eistein')
book2 = G(Book)
books = Book.objects.search_by_author(book1.main_author.name)
assert book1 in books
assert book2 not in books
assert book1.main_author.name == 'Eistein'
```

0 comments on commit cc44826

Please sign in to comment.