Changeset 5262
- Timestamp:
- 05/16/07 12:51:38 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/boulder-oracle-sprint/tests/regressiontests/serializers_regress/tests.py
r5235 r5262 3 3 4 4 This class defines sample data and a dynamically generated 5 test case that is capable of testing the capabilities of 5 test case that is capable of testing the capabilities of 6 6 the serializers. This includes all valid data values, plus 7 7 forward, backwards and self references. … … 15 15 from django.db import transaction 16 16 from django.core import management 17 from django.conf import settings 17 18 18 19 from models import * … … 23 24 instance = klass(id=pk) 24 25 instance.data = data 25 instance.save() 26 instance.save() 26 27 return instance 27 28 … … 33 34 instance.tags.create(data=tag) 34 35 return instance 35 36 36 37 def fk_create(pk, klass, data): 37 38 instance = klass(id=pk) … … 39 40 instance.save() 40 41 return instance 41 42 42 43 def m2m_create(pk, klass, data): 43 44 instance = klass(id=pk) … … 62 63 def data_compare(testcase, pk, klass, data): 63 64 instance = klass.objects.get(id=pk) 64 testcase.assertEqual(data, instance.data, 65 testcase.assertEqual(data, instance.data, 65 66 "Objects with PK=%d not equal; expected '%s' (%s), got '%s' (%s)" % (pk,data, type(data), instance.data, type(instance.data))) 66 67 … … 69 70 testcase.assertEqual(data[0], instance.data) 70 71 testcase.assertEqual(data[1:], [t.data for t in instance.tags.all()]) 71 72 72 73 def fk_compare(testcase, pk, klass, data): 73 74 instance = klass.objects.get(id=pk) … … 85 86 instance = klass.objects.get(data=data) 86 87 testcase.assertEqual(data, instance.data) 87 88 88 89 # Define some data types. Each data type is 89 90 # actually a pair of functions; one to create … … 97 98 98 99 test_data = [ 99 # Format: (data type, PK value, Model Class, data) 100 # Format: (data type, PK value, Model Class, data) 100 101 (data_obj, 1, BooleanData, True), 101 102 (data_obj, 2, BooleanData, False), … … 112 113 (data_obj, 40, EmailData, "hovercraft@example.com"), 113 114 (data_obj, 41, EmailData, None), 115 (data_obj, 42, EmailData, ""), 114 116 (data_obj, 50, FileData, 'file:///foo/bar/whiz.txt'), 115 117 (data_obj, 51, FileData, None), 118 (data_obj, 52, FileData, ""), 116 119 (data_obj, 60, FilePathData, "/foo/bar/whiz.txt"), 117 120 (data_obj, 61, FilePathData, None), 121 (data_obj, 62, FilePathData, ""), 118 122 (data_obj, 70, FloatData, 12.345), 119 123 (data_obj, 71, FloatData, -12.345), … … 127 131 (data_obj, 90, IPAddressData, "127.0.0.1"), 128 132 (data_obj, 91, IPAddressData, None), 133 (data_obj, 92, IPAddressData, ""), 129 134 (data_obj, 100, NullBooleanData, True), 130 135 (data_obj, 101, NullBooleanData, False), … … 138 143 (data_obj, 140, SlugData, "this-is-a-slug"), 139 144 (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), 144 150 (data_obj, 160, TextData, """This is a long piece of text. 145 151 It contains line breaks. … … 152 158 (data_obj, 180, USStateData, "MA"), 153 159 (data_obj, 181, USStateData, None), 160 (data_obj, 182, USStateData, ""), 154 161 (data_obj, 190, XMLData, "<foo></foo>"), 155 162 (data_obj, 191, XMLData, None), 163 (data_obj, 192, XMLData, ""), 156 164 157 165 (generic_obj, 200, GenericData, ['Generic Object 1', 'tag1', 'tag2']), … … 189 197 (fk_obj, 451, FKDataToField, "UAnchor 2"), 190 198 (fk_obj, 452, FKDataToField, None), 191 199 192 200 (data_obj, 500, Anchor, "Anchor 3"), 193 201 (data_obj, 501, Anchor, "Anchor 4"), … … 216 224 (pk_obj, 730, PositiveSmallIntegerPKData, 12), 217 225 (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), 221 229 # (pk_obj, 760, TextPKData, """This is a long piece of text. 222 230 # It contains line breaks. … … 227 235 # (pk_obj, 790, XMLPKData, "<foo></foo>"), 228 236 ] 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. 241 if 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 230 247 # Dynamically create serializer tests to ensure that all 231 248 # registered serializers are automatically tested. … … 235 252 def serializerTest(format, self): 236 253 # Clear the database first 237 management.flush(verbosity=0, interactive=False) 254 management.flush(verbosity=0, interactive=False) 238 255 239 256 # Create all the objects defined in the test data … … 246 263 transaction.leave_transaction_management() 247 264 248 # Add the generic tagged objects to the object list 265 # Add the generic tagged objects to the object list 249 266 objects.extend(Tag.objects.all()) 250 267 251 268 # Serialize the test database 252 269 serialized_data = serializers.serialize(format, objects, indent=2) 253 270 254 271 # Flush the database and recreate from the serialized data 255 management.flush(verbosity=0, interactive=False) 272 management.flush(verbosity=0, interactive=False) 256 273 transaction.enter_transaction_management() 257 274 transaction.managed(True) … … 261 278 transaction.leave_transaction_management() 262 279 263 # Assert that the deserialized data is the same 280 # Assert that the deserialized data is the same 264 281 # as the original source 265 282 for (func, pk, klass, datum) in test_data: 266 283 func[1](self, pk, klass, datum) 267 284 268 285 for format in serializers.get_serializer_formats(): 269 286 setattr(SerializerTests, 'test_'+format+'_serializer', curry(serializerTest, format))
