Ticket #2333: modeltests.patch
File modeltests.patch, 20.8 KB (added by , 18 years ago) |
---|
-
basic/models.py
13 13 def __str__(self): 14 14 return self.headline 15 15 16 API_TESTS = """ 17 16 __test__ = {'API_TESTS': """ 18 17 # No articles are in the system yet. 19 18 >>> Article.objects.all() 20 19 [] … … 314 313 >>> Article.objects.all() 315 314 [<Article: Article 6>, <Article: Default headline>, <Article: Article 7>, <Article: Updated article 8>] 316 315 317 """ 316 """} 318 317 319 318 from django.conf import settings 320 319 321 320 building_docs = getattr(settings, 'BUILDING_DOCS', False) 322 321 323 322 if building_docs or settings.DATABASE_ENGINE == 'postgresql': 324 API_TESTS+= """323 __test__['API_TESTS'] += """ 325 324 # In PostgreSQL, microsecond-level precision is available. 326 325 >>> a9 = Article(headline='Article 9', pub_date=datetime(2005, 7, 31, 12, 30, 45, 180)) 327 326 >>> a9.save() … … 330 329 """ 331 330 332 331 if building_docs or settings.DATABASE_ENGINE == 'mysql': 333 API_TESTS+= """332 __test__['API_TESTS'] += """ 334 333 # In MySQL, microsecond-level precision isn't available. You'll lose 335 334 # microsecond-level precision once the data is saved. 336 335 >>> a9 = Article(headline='Article 9', pub_date=datetime(2005, 7, 31, 12, 30, 45, 180)) … … 339 338 datetime.datetime(2005, 7, 31, 12, 30, 45) 340 339 """ 341 340 342 API_TESTS+= """341 __test__['API_TESTS'] += """ 343 342 344 343 # You can manually specify the primary key when creating a new object. 345 344 >>> a101 = Article(id=101, headline='Article 101', pub_date=datetime(2005, 7, 31, 12, 30, 45)) -
m2m_recursive/models.py
22 22 def __str__(self): 23 23 return self.name 24 24 25 API_TESTS ="""25 __test__ = {'API_TESTS':""" 26 26 >>> a = Person(name='Anne') 27 27 >>> a.save() 28 28 >>> b = Person(name='Bill') … … 189 189 >>> d.stalkers.all() 190 190 [<Person: Chuck>] 191 191 192 """ 192 """} -
one_to_one/models.py
30 30 def __str__(self): 31 31 return "%s the waiter at %s" % (self.name, self.restaurant) 32 32 33 API_TESTS ="""33 __test__ = {'API_TESTS':""" 34 34 # Create a couple of Places. 35 35 >>> p1 = Place(name='Demon Dogs', address='944 W. Fullerton') 36 36 >>> p1.save() … … 151 151 # Delete the restaurant; the waiter should also be removed 152 152 >>> r = Restaurant.objects.get(pk=1) 153 153 >>> r.delete() 154 """ 154 """} -
m2o_recursive/models.py
19 19 def __str__(self): 20 20 return self.name 21 21 22 API_TESTS ="""22 __test__ = {'API_TESTS':""" 23 23 # Create a few Category objects. 24 24 >>> r = Category(id=None, name='Root category', parent=None) 25 25 >>> r.save() … … 37 37 [] 38 38 >>> c.parent 39 39 <Category: Root category> 40 """ 40 """} -
custom_managers/models.py
58 58 def __str__(self): 59 59 return self.name 60 60 61 API_TESTS ="""61 __test__ = {'API_TESTS':""" 62 62 >>> p1 = Person(first_name='Bugs', last_name='Bunny', fun=True) 63 63 >>> p1.save() 64 64 >>> p2 = Person(first_name='Droopy', last_name='Dog', fun=False) … … 104 104 # to the first manager defined in the class. In this case, it's "cars". 105 105 >>> Car._default_manager.order_by('name') 106 106 [<Car: Corvette>, <Car: Neon>] 107 """ 107 """} -
invalid_models/models.py
78 78 79 79 80 80 81 error_log= """invalid_models.fielderrors: "charfield": CharFields require a "maxlength" attribute.81 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "maxlength" attribute. 82 82 invalid_models.fielderrors: "floatfield": FloatFields require a "decimal_places" attribute. 83 83 invalid_models.fielderrors: "floatfield": FloatFields require a "max_digits" attribute. 84 84 invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute. -
many_to_many/models.py
28 28 class Meta: 29 29 ordering = ('headline',) 30 30 31 API_TESTS ="""31 __test__ = {'API_TESTS':""" 32 32 # Create a couple of Publications. 33 33 >>> p1 = Publication(id=None, title='The Python Journal') 34 34 >>> p1.save() … … 231 231 >>> p1.article_set.all() 232 232 [<Article: NASA uses Python>] 233 233 234 """ 234 """} -
m2m_and_m2o/models.py
21 21 ordering = ('num',) 22 22 23 23 24 API_TESTS ="""24 __test__ = {'API_TESTS':""" 25 25 >>> Issue.objects.all() 26 26 [] 27 27 >>> r = User(username='russell') … … 63 63 [<Issue: 1>, <Issue: 2>, <Issue: 3>] 64 64 >>> Issue.objects.filter(Q(client=r.id) | Q(cc__id__exact=r.id)) 65 65 [<Issue: 1>, <Issue: 2>, <Issue: 3>] 66 """ 66 """} -
validation/models.py
20 20 def __str__(self): 21 21 return self.name 22 22 23 API_TESTS ="""23 __test__ = {'API_TESTS':""" 24 24 25 25 >>> import datetime 26 26 >>> valid_params = { … … 146 146 >>> p.validate() 147 147 {'email': ['Enter a valid e-mail address.']} 148 148 149 """ 149 """} -
or_lookups/models.py
23 23 def __str__(self): 24 24 return self.headline 25 25 26 API_TESTS ="""26 __test__ = {'API_TESTS':""" 27 27 >>> from datetime import datetime 28 28 >>> from django.db.models import Q 29 29 … … 101 101 [<Article: Hello>] 102 102 >>> Article.objects.complex_filter(Q(pk=1) | Q(pk=2)) 103 103 [<Article: Hello>, <Article: Goodbye>] 104 """ 104 """} -
mutually_referential/models.py
14 14 name = CharField(maxlength=100) 15 15 parent = ForeignKey(Parent) 16 16 17 API_TESTS ="""17 __test__ = {'API_TESTS':""" 18 18 # Create a Parent 19 19 >>> q = Parent(name='Elizabeth') 20 20 >>> q.save() … … 29 29 30 30 >>> q.delete() 31 31 32 """ 33 No newline at end of file 32 """} 33 No newline at end of file -
custom_methods/models.py
36 36 # positional arguments to Article(). 37 37 return [self.__class__(*row) for row in cursor.fetchall()] 38 38 39 API_TESTS ="""39 __test__ = {'API_TESTS':""" 40 40 # Create a couple of Articles. 41 41 >>> from datetime import date 42 42 >>> a = Article(id=None, headline='Area man programs in Python', pub_date=date(2005, 7, 27)) … … 55 55 [<Article: Area man programs in Python>] 56 56 >>> b.articles_from_same_day_2() 57 57 [<Article: Area man programs in Python>] 58 """ 58 """} -
empty/models.py
10 10 class Empty(models.Model): 11 11 pass 12 12 13 API_TESTS ="""13 __test__ = {'API_TESTS':""" 14 14 >>> m = Empty() 15 15 >>> m.id 16 16 >>> m.save() … … 21 21 >>> m.id is not None 22 22 True 23 23 24 """ 24 """} -
many_to_one_null/models.py
23 23 def __str__(self): 24 24 return self.headline 25 25 26 API_TESTS ="""26 __test__ = {'API_TESTS':""" 27 27 # Create a Reporter. 28 28 >>> r = Reporter(name='John Smith') 29 29 >>> r.save() … … 121 121 >>> Article.objects.filter(reporter__isnull=True) 122 122 [<Article: First>, <Article: Fourth>] 123 123 124 """ 124 """} -
get_or_create/models.py
15 15 def __str__(self): 16 16 return '%s %s' % (self.first_name, self.last_name) 17 17 18 API_TESTS ="""18 __test__ = {'API_TESTS':""" 19 19 # Acting as a divine being, create an Person. 20 20 >>> from datetime import date 21 21 >>> p = Person(first_name='John', last_name='Lennon', birthday=date(1940, 10, 9)) … … 49 49 False 50 50 >>> Person.objects.count() 51 51 2 52 """ 52 """} -
custom_pk/models.py
27 27 def __str__(self): 28 28 return self.name 29 29 30 API_TESTS ="""30 __test__ = {'API_TESTS':""" 31 31 >>> dan = Employee(employee_code='ABC123', first_name='Dan', last_name='Jones') 32 32 >>> dan.save() 33 33 >>> Employee.objects.all() … … 88 88 >>> Business.objects.filter(employees__first_name__startswith='Fran') 89 89 [<Business: Sears>] 90 90 91 """ 91 """} -
reverse_lookup/models.py
27 27 def __str(self): 28 28 return self.name 29 29 30 API_TESTS ="""30 __test__ = {'API_TESTS':""" 31 31 >>> john = User(name="John Doe") 32 32 >>> john.save() 33 33 >>> jim = User(name="Jim Bo") … … 56 56 Traceback (most recent call last): 57 57 ... 58 58 TypeError: Cannot resolve keyword 'choice' into field 59 """ 59 """} -
m2o_recursive2/models.py
17 17 def __str__(self): 18 18 return self.full_name 19 19 20 API_TESTS ="""20 __test__ = {'API_TESTS':""" 21 21 # Create two Person objects -- the mom and dad in our family. 22 22 >>> dad = Person(full_name='John Smith Senior', mother=None, father=None) 23 23 >>> dad.save() … … 40 40 [] 41 41 >>> kid.fathers_child_set.all() 42 42 [] 43 """ 43 """} -
m2m_multiple/models.py
28 28 def __str__(self): 29 29 return self.headline 30 30 31 API_TESTS ="""31 __test__ = {'API_TESTS':""" 32 32 >>> from datetime import datetime 33 33 34 34 >>> c1 = Category(name='Sports') … … 76 76 [] 77 77 >>> c4.secondary_article_set.all() 78 78 [<Article: Area man steals>, <Article: Area man runs>] 79 """ 79 """} -
m2m_intermediary/models.py
34 34 def __str__(self): 35 35 return '%s (%s)' % (self.reporter, self.position) 36 36 37 API_TESTS ="""37 __test__ = {'API_TESTS':""" 38 38 # Create a few Reporters. 39 39 >>> r1 = Reporter(first_name='John', last_name='Smith') 40 40 >>> r1.save() … … 65 65 <Article: This is a test> 66 66 >>> r1.writer_set.all() 67 67 [<Writer: John Smith (Main writer)>] 68 """ 68 """} -
str/models.py
17 17 def __str__(self): 18 18 return self.headline 19 19 20 API_TESTS ="""20 __test__ = {'API_TESTS':""" 21 21 # Create an Article. 22 22 >>> from datetime import datetime 23 23 >>> a = Article(headline='Area man programs in Python', pub_date=datetime(2005, 7, 28)) … … 28 28 29 29 >>> a 30 30 <Article: Area man programs in Python> 31 """ 31 """} -
transactions/models.py
17 17 def __str__(self): 18 18 return "%s %s" % (self.first_name, self.last_name) 19 19 20 API_TESTS ="""20 __test__ = {'API_TESTS':""" 21 21 >>> from django.db import connection, transaction 22 """ 22 """} 23 23 24 24 from django.conf import settings 25 25 26 26 building_docs = getattr(settings, 'BUILDING_DOCS', False) 27 27 28 28 if building_docs or settings.DATABASE_ENGINE != 'mysql': 29 API_TESTS+= """29 __test__['API_TESTS'] += """ 30 30 # the default behavior is to autocommit after each save() action 31 31 >>> def create_a_reporter_then_fail(first, last): 32 32 ... a = Reporter(first_name=first, last_name=last) -
model_inheritance/models.py
26 26 def __str__(self): 27 27 return "%s the italian restaurant" % self.name 28 28 29 API_TESTS ="""29 __test__ = {'API_TESTS':""" 30 30 # Make sure Restaurant has the right fields in the right order. 31 31 >>> [f.name for f in Restaurant._meta.fields] 32 32 ['id', 'name', 'address', 'serves_hot_dogs', 'serves_pizza'] … … 50 50 >>> ir.save() 51 51 52 52 53 """ 53 """} -
lookup/models.py
15 15 def __str__(self): 16 16 return self.headline 17 17 18 API_TESTS ="""18 __test__ = {'API_TESTS':""" 19 19 # Create a couple of Articles. 20 20 >>> from datetime import datetime 21 21 >>> a1 = Article(headline='Article 1', pub_date=datetime(2005, 7, 26)) … … 182 182 [<Article: Article% with percent sign>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 7>, <Article: Article 1>] 183 183 >>> Article.objects.exclude(headline="Article 7") 184 184 [<Article: Article% with percent sign>, <Article: Article_ with underscore>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 1>] 185 """ 185 """} -
choices/models.py
23 23 def __str__(self): 24 24 return self.name 25 25 26 API_TESTS ="""26 __test__ = {'API_TESTS':""" 27 27 >>> a = Person(name='Adrian', gender='M') 28 28 >>> a.save() 29 29 >>> s = Person(name='Sara', gender='F') … … 36 36 'Male' 37 37 >>> s.get_gender_display() 38 38 'Female' 39 """ 39 """} -
save_delete_hooks/models.py
24 24 super(Person, self).delete() # Call the "real" delete() method 25 25 print "After deletion" 26 26 27 API_TESTS ="""27 __test__ = {'API_TESTS':""" 28 28 >>> p1 = Person(first_name='John', last_name='Smith') 29 29 >>> p1.save() 30 30 Before save … … 39 39 40 40 >>> Person.objects.all() 41 41 [] 42 """ 42 """} -
pagination/models.py
15 15 def __str__(self): 16 16 return self.headline 17 17 18 API_TESTS ="""18 __test__ = {'API_TESTS':""" 19 19 # prepare a list of objects for pagination 20 20 >>> from datetime import datetime 21 21 >>> for x in range(1, 10): … … 64 64 >>> paginator.last_on_page(1) 65 65 9 66 66 67 """ 67 """} -
get_latest/models.py
29 29 def __str__(self): 30 30 return self.name 31 31 32 API_TESTS ="""32 __test__ = {'API_TESTS':""" 33 33 # Because no Articles exist yet, get_latest() raises ArticleDoesNotExist. 34 34 >>> Article.objects.latest() 35 35 Traceback (most recent call last): … … 76 76 77 77 >>> Person.objects.latest('birthday') 78 78 <Person: Stephanie> 79 """ 79 """} -
generic_relations/models.py
53 53 def __str__(self): 54 54 return self.name 55 55 56 API_TESTS ="""56 __test__ = {'API_TESTS':""" 57 57 # Create the world in 7 lines of code... 58 58 >>> lion = Animal(common_name="Lion", latin_name="Panthera leo") 59 59 >>> platypus = Animal(common_name="Platypus", latin_name="Ornithorhynchus anatinus") … … 105 105 [<TaggedItem: shiny>] 106 106 >>> TaggedItem.objects.filter(content_type__pk=ctype.id, object_id=quartz.id) 107 107 [<TaggedItem: clearish>] 108 """ 108 """} -
serializers/models.py
37 37 def __str__(self): 38 38 return self.headline 39 39 40 API_TESTS ="""40 __test__ = {'API_TESTS':""" 41 41 # Create some data: 42 42 >>> from datetime import datetime 43 43 >>> sports = Category(name="Sports") … … 118 118 >>> Article.objects.all() 119 119 [<Article: Just kidding; I love TV poker>, <Article: Time to reform copyright>] 120 120 121 """ 121 """} -
properties/models.py
20 20 21 21 full_name_2 = property(_get_full_name, _set_full_name) 22 22 23 API_TESTS ="""23 __test__ = {'API_TESTS':""" 24 24 >>> a = Person(first_name='John', last_name='Lennon') 25 25 >>> a.save() 26 26 >>> a.full_name … … 37 37 >>> a2.save() 38 38 >>> a2.first_name 39 39 'Paul' 40 """ 40 """} -
reserved_names/models.py
24 24 def __str__(self): 25 25 return self.when 26 26 27 API_TESTS ="""27 __test__ = {'API_TESTS':""" 28 28 >>> import datetime 29 29 >>> day1 = datetime.date(2005, 1, 1) 30 30 >>> day2 = datetime.date(2006, 2, 2) … … 53 53 54 54 >>> Thing.objects.filter(where__month=1) 55 55 [<Thing: a>] 56 """ 56 """} -
many_to_one/models.py
25 25 class Meta: 26 26 ordering = ('headline',) 27 27 28 API_TESTS ="""28 __test__ = {'API_TESTS':""" 29 29 # Create a few Reporters. 30 30 >>> r = Reporter(first_name='John', last_name='Smith', email='john@example.com') 31 31 >>> r.save() … … 263 263 >>> Article.objects.all() 264 264 [] 265 265 266 """ 266 """} -
ordering/models.py
24 24 def __str__(self): 25 25 return self.headline 26 26 27 API_TESTS ="""27 __test__ = {'API_TESTS':""" 28 28 # Create a couple of Articles. 29 29 >>> from datetime import datetime 30 30 >>> a1 = Article(headline='Article 1', pub_date=datetime(2005, 7, 26)) … … 64 64 # don't know what order the output will be in. 65 65 >>> Article.objects.order_by('?') 66 66 [...] 67 """ 67 """} -
custom_columns/models.py
15 15 def __str__(self): 16 16 return '%s %s' % (self.first_name, self.last_name) 17 17 18 API_TESTS ="""18 __test__ = {'API_TESTS':""" 19 19 # Create a Person. 20 20 >>> p = Person(first_name='John', last_name='Smith') 21 21 >>> p.save() … … 50 50 Traceback (most recent call last): 51 51 ... 52 52 AttributeError: 'Person' object has no attribute 'last' 53 """ 53 """} -
field_defaults/models.py
19 19 def __str__(self): 20 20 return self.headline 21 21 22 API_TESTS ="""22 __test__ = {'API_TESTS':""" 23 23 >>> from datetime import datetime 24 24 25 25 # No articles are in the system yet. … … 48 48 >>> d = now - a.pub_date 49 49 >>> d.seconds < 5 50 50 True 51 """ 51 """} -
manipulators/models.py
21 21 def __str__(self): 22 22 return self.name 23 23 24 API_TESTS ="""24 __test__ = {'API_TESTS':""" 25 25 >>> from django.utils.datastructures import MultiValueDict 26 26 27 27 # Create a Musician object via the default AddManipulator. … … 88 88 <Album: Ultimate Ella> 89 89 >>> a2.release_date 90 90 datetime.date(2005, 2, 13) 91 """ 91 """}