-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
576ecaa
commit f74d6de
Showing
4 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Test circular definitions.""" | ||
|
||
import factory | ||
|
||
from pytest_factoryboy import register | ||
|
||
|
||
class Book(object): | ||
|
||
"""Book model.""" | ||
|
||
def __init__(self, name=None, price=None, author=None): | ||
self.editions = [] | ||
self.name = name | ||
self.price = price | ||
self.author = author | ||
self.author.books.append(self) | ||
|
||
|
||
class Author(object): | ||
|
||
"""Author model.""" | ||
|
||
def __init__(self, name): | ||
self.books = [] | ||
self.name = name | ||
self.user = None | ||
|
||
|
||
class AuthorFactory(factory.Factory): | ||
|
||
class Meta: | ||
model = Author | ||
|
||
name = "Charles Dickens" | ||
|
||
book = factory.RelatedFactory('tests.test_circular.BookFactory', 'author') | ||
|
||
|
||
class BookFactory(factory.Factory): | ||
|
||
class Meta: | ||
model = Book | ||
|
||
name = "Alice in Wonderland" | ||
price = factory.LazyAttribute(lambda f: 3.99) | ||
author = factory.SubFactory(AuthorFactory) | ||
|
||
|
||
register(AuthorFactory) | ||
register(BookFactory) | ||
|
||
|
||
def test_circular(author): | ||
assert author.books |