Skip to content

Example of usage

paulocheque edited this page Apr 9, 2012 · 5 revisions

Example of Usage (EDIT ME)

from django.db import models
from django.core.exceptions import ValidationError

class Author(models.Model):
    name = models.CharField(max_length=255)

class Book(models.Model):
    name = models.CharField(max_length=255)
    authors = models.ManyToManyField(Author)
from django.test import TestCase
from django_dynamic_fixture import G

class SearchingBooks(TestCase):
    def test_search_book_by_author(self):
        author1 = G(Author)
        author2 = G(Author)
        book1 = G(Book, authors=[author1])
        book2 = G(Book, authors=[author2])
        books = Book.objects.search_by_author(author1.name)
        self.assertTrue(book1 in books)
        self.assertTrue(book2 not in books)
Clone this wiki locally