Ticket #6783: 6783_tests.2.diff

File 6783_tests.2.diff, 1.6 KB (added by Philippe Raoult, 16 years ago)

slightly better tests

  • tests/regressiontests/model_regress/models.py

     
    2525    #5218: Test models with non-default primary keys / AutoFields
    2626    movie_id = models.AutoField(primary_key=True)
    2727    name = models.CharField(max_length=60)
     28    rating = models.DecimalField(max_digits=6, decimal_places=3, default=2.5)
     29   
    2830
    2931__test__ = {'API_TESTS': """
    3032(NOTE: Part of the regression test here is merely parsing the model
     
    5052>>> a4 = Article.objects.get(pk=a3.id)
    5153>>> len(a4.article_text)
    52545000
     55"""}
    5356
     57import locale
     58test_locale_available  = False
     59try:
     60    locale.setlocale(locale.LC_NUMERIC,'fr_FR')
     61    test_locale_available  = True
     62except:
     63    pass
     64
     65if test_locale_available:
     66    __test__['LOCALE_TESTS'] = """
     67# check for #6783
     68>>> from django.db.models.fields import DecimalField
     69>>> import locale
     70>>> pre_locale = locale.getlocale()[0]
     71>>> d = DecimalField(max_digits=6, decimal_places=3)
     72>>> locale.setlocale(locale.LC_NUMERIC,'fr_FR')
     73'fr_FR'
     74>>> print "%.1f" % 2.3
     752.3
     76
     77# locale is in effect, but print doesn't use it, and neither does DecimalField.format_number
     78>>> locale.format("%.1f",2.3)
     79'2,3'
     80>>> print d.format_number(3.456)
     813.456
     82
     83# we can safely save decimalfields into the DB even with the funky locale
     84>>> m = Movie(name = "Rambo", rating = 4.2)
     85>>> m.save()
     86>>> res = locale.setlocale(locale.LC_NUMERIC, pre_locale)
    5487"""
    55 }
Back to Top