Django

Code

Changeset 5262

Show
Ignore:
Timestamp:
05/16/07 12:51:38 (1 year ago)
Author:
bouldersprinters
Message:

boulder-oracle-sprint: Fixed serializers_regress test cases for Oracle.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/boulder-oracle-sprint/tests/regressiontests/serializers_regress/tests.py

    r5235 r5262  
    33 
    44This class defines sample data and a dynamically generated 
    5 test case that is capable of testing the capabilities of  
     5test case that is capable of testing the capabilities of 
    66the serializers. This includes all valid data values, plus 
    77forward, backwards and self references. 
     
    1515from django.db import transaction 
    1616from django.core import management 
     17from django.conf import settings 
    1718 
    1819from models import * 
     
    2324    instance = klass(id=pk) 
    2425    instance.data = data 
    25     instance.save()     
     26    instance.save() 
    2627    return instance 
    2728 
     
    3334        instance.tags.create(data=tag) 
    3435    return instance 
    35      
     36 
    3637def fk_create(pk, klass, data): 
    3738    instance = klass(id=pk) 
     
    3940    instance.save() 
    4041    return instance 
    41      
     42 
    4243def m2m_create(pk, klass, data): 
    4344    instance = klass(id=pk) 
     
    6263def data_compare(testcase, pk, klass, data): 
    6364    instance = klass.objects.get(id=pk) 
    64     testcase.assertEqual(data, instance.data,  
     65    testcase.assertEqual(data, instance.data, 
    6566                         "Objects with PK=%d not equal; expected '%s' (%s), got '%s' (%s)" % (pk,data, type(data), instance.data, type(instance.data))) 
    6667 
     
    6970    testcase.assertEqual(data[0], instance.data) 
    7071    testcase.assertEqual(data[1:], [t.data for t in instance.tags.all()]) 
    71      
     72 
    7273def fk_compare(testcase, pk, klass, data): 
    7374    instance = klass.objects.get(id=pk) 
     
    8586    instance = klass.objects.get(data=data) 
    8687    testcase.assertEqual(data, instance.data) 
    87          
     88 
    8889# Define some data types. Each data type is 
    8990# actually a pair of functions; one to create 
     
    9798 
    9899test_data = [ 
    99     # Format: (data type, PK value, Model Class, data)   
     100    # Format: (data type, PK value, Model Class, data) 
    100101    (data_obj, 1, BooleanData, True), 
    101102    (data_obj, 2, BooleanData, False), 
     
    112113    (data_obj, 40, EmailData, "hovercraft@example.com"), 
    113114    (data_obj, 41, EmailData, None), 
     115    (data_obj, 42, EmailData, ""), 
    114116    (data_obj, 50, FileData, 'file:///foo/bar/whiz.txt'), 
    115117    (data_obj, 51, FileData, None), 
     118    (data_obj, 52, FileData, ""), 
    116119    (data_obj, 60, FilePathData, "/foo/bar/whiz.txt"), 
    117120    (data_obj, 61, FilePathData, None), 
     121    (data_obj, 62, FilePathData, ""), 
    118122    (data_obj, 70, FloatData, 12.345), 
    119123    (data_obj, 71, FloatData, -12.345), 
     
    127131    (data_obj, 90, IPAddressData, "127.0.0.1"), 
    128132    (data_obj, 91, IPAddressData, None), 
     133    (data_obj, 92, IPAddressData, ""), 
    129134    (data_obj, 100, NullBooleanData, True), 
    130135    (data_obj, 101, NullBooleanData, False), 
     
    138143    (data_obj, 140, SlugData, "this-is-a-slug"), 
    139144    (data_obj, 141, SlugData, None), 
    140     (data_obj, 150, SmallData, 12),  
    141     (data_obj, 151, SmallData, -12),  
    142     (data_obj, 152, SmallData, 0),  
    143     (data_obj, 153, SmallData, None),  
     145    (data_obj, 142, SlugData, ""), 
     146    (data_obj, 150, SmallData, 12), 
     147    (data_obj, 151, SmallData, -12), 
     148    (data_obj, 152, SmallData, 0), 
     149    (data_obj, 153, SmallData, None), 
    144150    (data_obj, 160, TextData, """This is a long piece of text. 
    145151It contains line breaks. 
     
    152158    (data_obj, 180, USStateData, "MA"), 
    153159    (data_obj, 181, USStateData, None), 
     160    (data_obj, 182, USStateData, ""), 
    154161    (data_obj, 190, XMLData, "<foo></foo>"), 
    155162    (data_obj, 191, XMLData, None), 
     163    (data_obj, 192, XMLData, ""), 
    156164 
    157165    (generic_obj, 200, GenericData, ['Generic Object 1', 'tag1', 'tag2']), 
     
    189197    (fk_obj, 451, FKDataToField, "UAnchor 2"), 
    190198    (fk_obj, 452, FKDataToField, None), 
    191      
     199 
    192200    (data_obj, 500, Anchor, "Anchor 3"), 
    193201    (data_obj, 501, Anchor, "Anchor 4"), 
     
    216224    (pk_obj, 730, PositiveSmallIntegerPKData, 12), 
    217225    (pk_obj, 740, SlugPKData, "this-is-a-slug"), 
    218     (pk_obj, 750, SmallPKData, 12),  
    219     (pk_obj, 751, SmallPKData, -12),  
    220     (pk_obj, 752, SmallPKData, 0),  
     226    (pk_obj, 750, SmallPKData, 12), 
     227    (pk_obj, 751, SmallPKData, -12), 
     228    (pk_obj, 752, SmallPKData, 0), 
    221229#     (pk_obj, 760, TextPKData, """This is a long piece of text. 
    222230# It contains line breaks. 
     
    227235#     (pk_obj, 790, XMLPKData, "<foo></foo>"), 
    228236] 
    229      
     237 
     238# Because Oracle treats the empty string as NULL, Oracle is expected to fail 
     239# when field.empty_strings_allowed is True and the value is None; skip these 
     240# tests. 
     241if settings.DATABASE_ENGINE == 'oracle': 
     242    test_data = [data for data in test_data 
     243                 if not (data[0] == data_obj and 
     244                         data[2]._meta.get_field('data').empty_strings_allowed and 
     245                         data[3] is None)] 
     246 
    230247# Dynamically create serializer tests to ensure that all 
    231248# registered serializers are automatically tested. 
     
    235252def serializerTest(format, self): 
    236253    # Clear the database first 
    237     management.flush(verbosity=0, interactive=False)     
     254    management.flush(verbosity=0, interactive=False) 
    238255 
    239256    # Create all the objects defined in the test data 
     
    246263    transaction.leave_transaction_management() 
    247264 
    248     # Add the generic tagged objects to the object list  
     265    # Add the generic tagged objects to the object list 
    249266    objects.extend(Tag.objects.all()) 
    250      
     267 
    251268    # Serialize the test database 
    252269    serialized_data = serializers.serialize(format, objects, indent=2) 
    253270 
    254271    # Flush the database and recreate from the serialized data 
    255     management.flush(verbosity=0, interactive=False)     
     272    management.flush(verbosity=0, interactive=False) 
    256273    transaction.enter_transaction_management() 
    257274    transaction.managed(True) 
     
    261278    transaction.leave_transaction_management() 
    262279 
    263     # Assert that the deserialized data is the same  
     280    # Assert that the deserialized data is the same 
    264281    # as the original source 
    265282    for (func, pk, klass, datum) in test_data: 
    266283        func[1](self, pk, klass, datum) 
    267      
     284 
    268285for format in serializers.get_serializer_formats(): 
    269286    setattr(SerializerTests, 'test_'+format+'_serializer', curry(serializerTest, format))