Code

Ticket #2333: modeltests.patch

File modeltests.patch, 20.8 KB (added by russellm, 8 years ago)

Changes to the modeltests

  • basic/models.py

     
    1313    def __str__(self): 
    1414        return self.headline 
    1515 
    16 API_TESTS = """ 
    17  
     16__test__ = {'API_TESTS': """ 
    1817# No articles are in the system yet. 
    1918>>> Article.objects.all() 
    2019[] 
     
    314313>>> Article.objects.all() 
    315314[<Article: Article 6>, <Article: Default headline>, <Article: Article 7>, <Article: Updated article 8>] 
    316315 
    317 """ 
     316"""} 
    318317 
    319318from django.conf import settings 
    320319 
    321320building_docs = getattr(settings, 'BUILDING_DOCS', False) 
    322321 
    323322if building_docs or settings.DATABASE_ENGINE == 'postgresql': 
    324     API_TESTS += """ 
     323    __test__['API_TESTS'] += """ 
    325324# In PostgreSQL, microsecond-level precision is available. 
    326325>>> a9 = Article(headline='Article 9', pub_date=datetime(2005, 7, 31, 12, 30, 45, 180)) 
    327326>>> a9.save() 
     
    330329""" 
    331330 
    332331if building_docs or settings.DATABASE_ENGINE == 'mysql': 
    333     API_TESTS += """ 
     332    __test__['API_TESTS'] += """ 
    334333# In MySQL, microsecond-level precision isn't available. You'll lose 
    335334# microsecond-level precision once the data is saved. 
    336335>>> a9 = Article(headline='Article 9', pub_date=datetime(2005, 7, 31, 12, 30, 45, 180)) 
     
    339338datetime.datetime(2005, 7, 31, 12, 30, 45) 
    340339""" 
    341340 
    342 API_TESTS += """ 
     341__test__['API_TESTS'] += """ 
    343342 
    344343# You can manually specify the primary key when creating a new object. 
    345344>>> a101 = Article(id=101, headline='Article 101', pub_date=datetime(2005, 7, 31, 12, 30, 45)) 
  • m2m_recursive/models.py

     
    2222    def __str__(self): 
    2323        return self.name 
    2424 
    25 API_TESTS = """ 
     25__test__ = {'API_TESTS':""" 
    2626>>> a = Person(name='Anne') 
    2727>>> a.save() 
    2828>>> b = Person(name='Bill') 
     
    189189>>> d.stalkers.all() 
    190190[<Person: Chuck>] 
    191191 
    192 """ 
     192"""} 
  • one_to_one/models.py

     
    3030    def __str__(self): 
    3131        return "%s the waiter at %s" % (self.name, self.restaurant) 
    3232 
    33 API_TESTS = """ 
     33__test__ = {'API_TESTS':""" 
    3434# Create a couple of Places. 
    3535>>> p1 = Place(name='Demon Dogs', address='944 W. Fullerton') 
    3636>>> p1.save() 
     
    151151# Delete the restaurant; the waiter should also be removed 
    152152>>> r = Restaurant.objects.get(pk=1) 
    153153>>> r.delete() 
    154 """ 
     154"""} 
  • m2o_recursive/models.py

     
    1919    def __str__(self): 
    2020        return self.name 
    2121 
    22 API_TESTS = """ 
     22__test__ = {'API_TESTS':""" 
    2323# Create a few Category objects. 
    2424>>> r = Category(id=None, name='Root category', parent=None) 
    2525>>> r.save() 
     
    3737[] 
    3838>>> c.parent 
    3939<Category: Root category> 
    40 """ 
     40"""} 
  • custom_managers/models.py

     
    5858    def __str__(self): 
    5959        return self.name 
    6060 
    61 API_TESTS = """ 
     61__test__ = {'API_TESTS':""" 
    6262>>> p1 = Person(first_name='Bugs', last_name='Bunny', fun=True) 
    6363>>> p1.save() 
    6464>>> p2 = Person(first_name='Droopy', last_name='Dog', fun=False) 
     
    104104# to the first manager defined in the class. In this case, it's "cars". 
    105105>>> Car._default_manager.order_by('name') 
    106106[<Car: Corvette>, <Car: Neon>] 
    107 """ 
     107"""} 
  • invalid_models/models.py

     
    7878 
    7979 
    8080 
    81 error_log = """invalid_models.fielderrors: "charfield": CharFields require a "maxlength" attribute. 
     81model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "maxlength" attribute. 
    8282invalid_models.fielderrors: "floatfield": FloatFields require a "decimal_places" attribute. 
    8383invalid_models.fielderrors: "floatfield": FloatFields require a "max_digits" attribute. 
    8484invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute. 
  • many_to_many/models.py

     
    2828    class Meta: 
    2929        ordering = ('headline',) 
    3030 
    31 API_TESTS = """ 
     31__test__ = {'API_TESTS':""" 
    3232# Create a couple of Publications. 
    3333>>> p1 = Publication(id=None, title='The Python Journal') 
    3434>>> p1.save() 
     
    231231>>> p1.article_set.all() 
    232232[<Article: NASA uses Python>] 
    233233 
    234 """ 
     234"""} 
  • m2m_and_m2o/models.py

     
    2121        ordering = ('num',) 
    2222 
    2323 
    24 API_TESTS = """ 
     24__test__ = {'API_TESTS':""" 
    2525>>> Issue.objects.all() 
    2626[] 
    2727>>> r = User(username='russell') 
     
    6363[<Issue: 1>, <Issue: 2>, <Issue: 3>] 
    6464>>> Issue.objects.filter(Q(client=r.id) | Q(cc__id__exact=r.id)) 
    6565[<Issue: 1>, <Issue: 2>, <Issue: 3>] 
    66 """ 
     66"""} 
  • validation/models.py

     
    2020    def __str__(self): 
    2121        return self.name 
    2222 
    23 API_TESTS = """ 
     23__test__ = {'API_TESTS':""" 
    2424 
    2525>>> import datetime 
    2626>>> valid_params = { 
     
    146146>>> p.validate() 
    147147{'email': ['Enter a valid e-mail address.']} 
    148148 
    149 """ 
     149"""} 
  • or_lookups/models.py

     
    2323    def __str__(self): 
    2424        return self.headline 
    2525 
    26 API_TESTS = """ 
     26__test__ = {'API_TESTS':""" 
    2727>>> from datetime import datetime 
    2828>>> from django.db.models import Q 
    2929 
     
    101101[<Article: Hello>] 
    102102>>> Article.objects.complex_filter(Q(pk=1) | Q(pk=2)) 
    103103[<Article: Hello>, <Article: Goodbye>] 
    104 """ 
     104"""} 
  • mutually_referential/models.py

     
    1414    name = CharField(maxlength=100) 
    1515    parent = ForeignKey(Parent) 
    1616 
    17 API_TESTS = """ 
     17__test__ = {'API_TESTS':""" 
    1818# Create a Parent 
    1919>>> q = Parent(name='Elizabeth') 
    2020>>> q.save() 
     
    2929 
    3030>>> q.delete() 
    3131 
    32 """ 
    33  No newline at end of file 
     32"""} 
     33 No newline at end of file 
  • custom_methods/models.py

     
    3636        # positional arguments to Article(). 
    3737        return [self.__class__(*row) for row in cursor.fetchall()] 
    3838 
    39 API_TESTS = """ 
     39__test__ = {'API_TESTS':""" 
    4040# Create a couple of Articles. 
    4141>>> from datetime import date 
    4242>>> a = Article(id=None, headline='Area man programs in Python', pub_date=date(2005, 7, 27)) 
     
    5555[<Article: Area man programs in Python>] 
    5656>>> b.articles_from_same_day_2() 
    5757[<Article: Area man programs in Python>] 
    58 """ 
     58"""} 
  • empty/models.py

     
    1010class Empty(models.Model): 
    1111    pass 
    1212 
    13 API_TESTS = """ 
     13__test__ = {'API_TESTS':""" 
    1414>>> m = Empty() 
    1515>>> m.id 
    1616>>> m.save() 
     
    2121>>> m.id is not None 
    2222True 
    2323 
    24 """ 
     24"""} 
  • many_to_one_null/models.py

     
    2323    def __str__(self): 
    2424        return self.headline 
    2525 
    26 API_TESTS = """ 
     26__test__ = {'API_TESTS':""" 
    2727# Create a Reporter. 
    2828>>> r = Reporter(name='John Smith') 
    2929>>> r.save() 
     
    121121>>> Article.objects.filter(reporter__isnull=True) 
    122122[<Article: First>, <Article: Fourth>] 
    123123 
    124 """ 
     124"""} 
  • get_or_create/models.py

     
    1515    def __str__(self): 
    1616        return '%s %s' % (self.first_name, self.last_name) 
    1717 
    18 API_TESTS = """ 
     18__test__ = {'API_TESTS':""" 
    1919# Acting as a divine being, create an Person. 
    2020>>> from datetime import date 
    2121>>> p = Person(first_name='John', last_name='Lennon', birthday=date(1940, 10, 9)) 
     
    4949False 
    5050>>> Person.objects.count() 
    51512 
    52 """ 
     52"""} 
  • custom_pk/models.py

     
    2727    def __str__(self): 
    2828        return self.name 
    2929 
    30 API_TESTS = """ 
     30__test__ = {'API_TESTS':""" 
    3131>>> dan = Employee(employee_code='ABC123', first_name='Dan', last_name='Jones') 
    3232>>> dan.save() 
    3333>>> Employee.objects.all() 
     
    8888>>> Business.objects.filter(employees__first_name__startswith='Fran') 
    8989[<Business: Sears>] 
    9090 
    91 """ 
     91"""} 
  • reverse_lookup/models.py

     
    2727    def __str(self): 
    2828        return self.name 
    2929 
    30 API_TESTS = """ 
     30__test__ = {'API_TESTS':""" 
    3131>>> john = User(name="John Doe") 
    3232>>> john.save() 
    3333>>> jim = User(name="Jim Bo") 
     
    5656Traceback (most recent call last): 
    5757    ... 
    5858TypeError: Cannot resolve keyword 'choice' into field 
    59 """ 
     59"""} 
  • m2o_recursive2/models.py

     
    1717    def __str__(self): 
    1818        return self.full_name 
    1919 
    20 API_TESTS = """ 
     20__test__ = {'API_TESTS':""" 
    2121# Create two Person objects -- the mom and dad in our family. 
    2222>>> dad = Person(full_name='John Smith Senior', mother=None, father=None) 
    2323>>> dad.save() 
     
    4040[] 
    4141>>> kid.fathers_child_set.all() 
    4242[] 
    43 """ 
     43"""} 
  • m2m_multiple/models.py

     
    2828    def __str__(self): 
    2929        return self.headline 
    3030 
    31 API_TESTS = """ 
     31__test__ = {'API_TESTS':""" 
    3232>>> from datetime import datetime 
    3333 
    3434>>> c1 = Category(name='Sports') 
     
    7676[] 
    7777>>> c4.secondary_article_set.all() 
    7878[<Article: Area man steals>, <Article: Area man runs>] 
    79 """ 
     79"""} 
  • m2m_intermediary/models.py

     
    3434    def __str__(self): 
    3535        return '%s (%s)' % (self.reporter, self.position) 
    3636 
    37 API_TESTS = """ 
     37__test__ = {'API_TESTS':""" 
    3838# Create a few Reporters. 
    3939>>> r1 = Reporter(first_name='John', last_name='Smith') 
    4040>>> r1.save() 
     
    6565<Article: This is a test> 
    6666>>> r1.writer_set.all() 
    6767[<Writer: John Smith (Main writer)>] 
    68 """ 
     68"""} 
  • str/models.py

     
    1717    def __str__(self): 
    1818        return self.headline 
    1919 
    20 API_TESTS = """ 
     20__test__ = {'API_TESTS':""" 
    2121# Create an Article. 
    2222>>> from datetime import datetime 
    2323>>> a = Article(headline='Area man programs in Python', pub_date=datetime(2005, 7, 28)) 
     
    2828 
    2929>>> a 
    3030<Article: Area man programs in Python> 
    31 """ 
     31"""} 
  • transactions/models.py

     
    1717    def __str__(self): 
    1818        return "%s %s" % (self.first_name, self.last_name) 
    1919 
    20 API_TESTS = """ 
     20__test__ = {'API_TESTS':""" 
    2121>>> from django.db import connection, transaction 
    22 """ 
     22"""} 
    2323 
    2424from django.conf import settings 
    2525 
    2626building_docs = getattr(settings, 'BUILDING_DOCS', False) 
    2727 
    2828if building_docs or settings.DATABASE_ENGINE != 'mysql': 
    29     API_TESTS += """ 
     29    __test__['API_TESTS'] += """ 
    3030# the default behavior is to autocommit after each save() action 
    3131>>> def create_a_reporter_then_fail(first, last): 
    3232...     a = Reporter(first_name=first, last_name=last) 
  • model_inheritance/models.py

     
    2626    def __str__(self): 
    2727        return "%s the italian restaurant" % self.name 
    2828 
    29 API_TESTS = """ 
     29__test__ = {'API_TESTS':""" 
    3030# Make sure Restaurant has the right fields in the right order. 
    3131>>> [f.name for f in Restaurant._meta.fields] 
    3232['id', 'name', 'address', 'serves_hot_dogs', 'serves_pizza'] 
     
    5050>>> ir.save() 
    5151 
    5252 
    53 """ 
     53"""} 
  • lookup/models.py

     
    1515    def __str__(self): 
    1616        return self.headline 
    1717 
    18 API_TESTS = """ 
     18__test__ = {'API_TESTS':""" 
    1919# Create a couple of Articles. 
    2020>>> from datetime import datetime 
    2121>>> a1 = Article(headline='Article 1', pub_date=datetime(2005, 7, 26)) 
     
    182182[<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>] 
    183183>>> Article.objects.exclude(headline="Article 7") 
    184184[<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

     
    2323    def __str__(self): 
    2424        return self.name 
    2525 
    26 API_TESTS = """ 
     26__test__ = {'API_TESTS':""" 
    2727>>> a = Person(name='Adrian', gender='M') 
    2828>>> a.save() 
    2929>>> s = Person(name='Sara', gender='F') 
     
    3636'Male' 
    3737>>> s.get_gender_display() 
    3838'Female' 
    39 """ 
     39"""} 
  • save_delete_hooks/models.py

     
    2424        super(Person, self).delete() # Call the "real" delete() method 
    2525        print "After deletion" 
    2626 
    27 API_TESTS = """ 
     27__test__ = {'API_TESTS':""" 
    2828>>> p1 = Person(first_name='John', last_name='Smith') 
    2929>>> p1.save() 
    3030Before save 
     
    3939 
    4040>>> Person.objects.all() 
    4141[] 
    42 """ 
     42"""} 
  • pagination/models.py

     
    1515    def __str__(self): 
    1616        return self.headline 
    1717 
    18 API_TESTS = """ 
     18__test__ = {'API_TESTS':""" 
    1919# prepare a list of objects for pagination 
    2020>>> from datetime import datetime 
    2121>>> for x in range(1, 10): 
     
    6464>>> paginator.last_on_page(1) 
    65659 
    6666 
    67 """ 
     67"""} 
  • get_latest/models.py

     
    2929    def __str__(self): 
    3030        return self.name 
    3131 
    32 API_TESTS = """ 
     32__test__ = {'API_TESTS':""" 
    3333# Because no Articles exist yet, get_latest() raises ArticleDoesNotExist. 
    3434>>> Article.objects.latest() 
    3535Traceback (most recent call last): 
     
    7676 
    7777>>> Person.objects.latest('birthday') 
    7878<Person: Stephanie> 
    79 """ 
     79"""} 
  • generic_relations/models.py

     
    5353    def __str__(self): 
    5454        return self.name 
    5555         
    56 API_TESTS = """ 
     56__test__ = {'API_TESTS':""" 
    5757# Create the world in 7 lines of code... 
    5858>>> lion = Animal(common_name="Lion", latin_name="Panthera leo") 
    5959>>> platypus = Animal(common_name="Platypus", latin_name="Ornithorhynchus anatinus") 
     
    105105[<TaggedItem: shiny>] 
    106106>>> TaggedItem.objects.filter(content_type__pk=ctype.id, object_id=quartz.id) 
    107107[<TaggedItem: clearish>] 
    108 """ 
     108"""} 
  • serializers/models.py

     
    3737    def __str__(self): 
    3838        return self.headline 
    3939 
    40 API_TESTS = """ 
     40__test__ = {'API_TESTS':""" 
    4141# Create some data: 
    4242>>> from datetime import datetime 
    4343>>> sports = Category(name="Sports") 
     
    118118>>> Article.objects.all() 
    119119[<Article: Just kidding; I love TV poker>, <Article: Time to reform copyright>] 
    120120 
    121 """ 
     121"""} 
  • properties/models.py

     
    2020 
    2121    full_name_2 = property(_get_full_name, _set_full_name) 
    2222 
    23 API_TESTS = """ 
     23__test__ = {'API_TESTS':""" 
    2424>>> a = Person(first_name='John', last_name='Lennon') 
    2525>>> a.save() 
    2626>>> a.full_name 
     
    3737>>> a2.save() 
    3838>>> a2.first_name 
    3939'Paul' 
    40 """ 
     40"""} 
  • reserved_names/models.py

     
    2424    def __str__(self): 
    2525        return self.when 
    2626 
    27 API_TESTS = """ 
     27__test__ = {'API_TESTS':""" 
    2828>>> import datetime 
    2929>>> day1 = datetime.date(2005, 1, 1) 
    3030>>> day2 = datetime.date(2006, 2, 2) 
     
    5353 
    5454>>> Thing.objects.filter(where__month=1) 
    5555[<Thing: a>] 
    56 """ 
     56"""} 
  • many_to_one/models.py

     
    2525    class Meta: 
    2626        ordering = ('headline',) 
    2727 
    28 API_TESTS = """ 
     28__test__ = {'API_TESTS':""" 
    2929# Create a few Reporters. 
    3030>>> r = Reporter(first_name='John', last_name='Smith', email='john@example.com') 
    3131>>> r.save() 
     
    263263>>> Article.objects.all() 
    264264[] 
    265265 
    266 """ 
     266"""} 
  • ordering/models.py

     
    2424    def __str__(self): 
    2525        return self.headline 
    2626 
    27 API_TESTS = """ 
     27__test__ = {'API_TESTS':""" 
    2828# Create a couple of Articles. 
    2929>>> from datetime import datetime 
    3030>>> a1 = Article(headline='Article 1', pub_date=datetime(2005, 7, 26)) 
     
    6464# don't know what order the output will be in. 
    6565>>> Article.objects.order_by('?') 
    6666[...] 
    67 """ 
     67"""} 
  • custom_columns/models.py

     
    1515    def __str__(self): 
    1616        return '%s %s' % (self.first_name, self.last_name) 
    1717 
    18 API_TESTS = """ 
     18__test__ = {'API_TESTS':""" 
    1919# Create a Person. 
    2020>>> p = Person(first_name='John', last_name='Smith') 
    2121>>> p.save() 
     
    5050Traceback (most recent call last): 
    5151    ... 
    5252AttributeError: 'Person' object has no attribute 'last' 
    53 """ 
     53"""} 
  • field_defaults/models.py

     
    1919    def __str__(self): 
    2020        return self.headline 
    2121 
    22 API_TESTS = """ 
     22__test__ = {'API_TESTS':""" 
    2323>>> from datetime import datetime 
    2424 
    2525# No articles are in the system yet. 
     
    4848>>> d = now - a.pub_date 
    4949>>> d.seconds < 5 
    5050True 
    51 """ 
     51"""} 
  • manipulators/models.py

     
    2121    def __str__(self): 
    2222        return self.name 
    2323 
    24 API_TESTS = """ 
     24__test__ = {'API_TESTS':""" 
    2525>>> from django.utils.datastructures import MultiValueDict 
    2626 
    2727# Create a Musician object via the default AddManipulator. 
     
    8888<Album: Ultimate Ella> 
    8989>>> a2.release_date 
    9090datetime.date(2005, 2, 13) 
    91 """ 
     91"""}