Django

Code

Changeset 6354

Show
Ignore:
Timestamp:
09/16/07 05:04:26 (1 year ago)
Author:
mtredinnick
Message:

Rewrote the backends test to be more portable. Was previously failing on MySQL.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/regressiontests/backends/models.py

    r6242 r6354  
    11from django.db import models 
     2from django.db import connection 
    23 
    34class Square(models.Model): 
     
    89        return "%s ** 2 == %s" % (self.root, self.square) 
    910 
     11if connection.features.uses_case_insensitive_names: 
     12    t_convert = lambda x: x.upper() 
     13else: 
     14    t_convert = lambda x: x 
     15qn = connection.ops.quote_name 
     16 
    1017__test__ = {'API_TESTS': """ 
    1118 
     
    1320>>> from django.db import connection 
    1421>>> cursor = connection.cursor() 
    15 >>> cursor.executemany('INSERT INTO BACKENDS_SQUARE (ROOT, SQUARE) VALUES (%s, %s)', 
    16 ...                    [(i, i**2) for i in range(-5, 6)]) and None or None 
     22>>> opts = Square._meta 
     23>>> f1, f2 = opts.get_field('root'), opts.get_field('square') 
     24>>> query = ('INSERT INTO %s (%s, %s) VALUES (%%s, %%s)' 
     25...         % (t_convert(opts.db_table), qn(f1.column), qn(f2.column))) 
     26>>> cursor.executemany(query, [(i, i**2) for i in range(-5, 6)]) and None or None 
    1727>>> Square.objects.order_by('root') 
    1828[<Square: -5 ** 2 == 25>, <Square: -4 ** 2 == 16>, <Square: -3 ** 2 == 9>, <Square: -2 ** 2 == 4>, <Square: -1 ** 2 == 1>, <Square: 0 ** 2 == 0>, <Square: 1 ** 2 == 1>, <Square: 2 ** 2 == 4>, <Square: 3 ** 2 == 9>, <Square: 4 ** 2 == 16>, <Square: 5 ** 2 == 25>] 
    1929 
    2030#4765: executemany with params=[] does nothing 
    21 >>> cursor.executemany('INSERT INTO BACKENDS_SQUARE (ROOT, SQUARE) VALUES (%s, %s)', []) and None or None 
     31>>> cursor.executemany(query, []) and None or None 
    2232>>> Square.objects.count() 
    233311