Ticket #14471: tests.py

File tests.py, 915 bytes (added by Lucky, 14 years ago)
Line 
1__test__ = {"doctest": """
2
3>>> a1 = Author.objects.create(name='Albert Einstein')
4>>> isinstance(Book.objects, CustomManager)
5True
6>>> isinstance(a1.book_set, CustomManager)
7True
8
9>>> b1 = Book.objects.create(author=a1, title='How to be smart',
10... extra_arg='extra argument detected')
11[extra argument detected]
12
13>>> b2 = a1.book_set.create(title='How to program',
14... extra_arg='extra argument detected')
15[extra argument detected]
16
17"""}
18
19
20from django.db import models
21
22
23class CustomManager(models.Manager):
24
25 def create(self, **kwargs):
26 print '[%s]' % kwargs.pop('extra_arg', '')
27 return super(CustomManager, self).create(**kwargs)
28
29
30class Author(models.Model):
31 name = models.CharField(max_length=10)
32
33
34class Book(models.Model):
35 title = models.CharField(max_length=10)
36 author = models.ForeignKey(Author)
37 objects = CustomManager()
Back to Top