Ticket #8134: intermediatefixturestest.diff
File intermediatefixturestest.diff, 3.9 KB (added by , 16 years ago) |
---|
-
tests/regressiontests/serializers_regress/models.py
132 132 class FKDataToO2O(models.Model): 133 133 data = models.ForeignKey(O2OData, null=True) 134 134 135 class M2MIntermediateData(models.Model): 136 data = models.ManyToManyField(Anchor, null=True, through='Intermediate') 137 138 class Intermediate(models.Model): 139 left = models.ForeignKey(M2MIntermediateData) 140 right = models.ForeignKey(Anchor) 141 extra = models.CharField(max_length=30, blank=True, default='doesn\'t matter') 142 135 143 # The following test classes are for validating the 136 144 # deserialization of objects that use a user-defined 137 145 # field as the primary key. … … 243 251 class ExplicitInheritBaseModel(BaseModel): 244 252 parent = models.OneToOneField(BaseModel) 245 253 child_data = models.IntegerField() 254 255 No newline at end of file -
tests/regressiontests/serializers_regress/tests.py
54 54 instance.data = data 55 55 return [instance] 56 56 57 def im2m_create(pk, klass, data): 58 instance = klass(id=pk) 59 models.Model.save_base(instance, raw=True) 60 return [instance] 61 62 def im_create(pk, klass, data): 63 instance = klass(id=pk) 64 setattr(instance, 'right_id', data['right']) 65 setattr(instance, 'left_id', data['left']) 66 if 'extra' in data: 67 setattr(instance, 'extra', data['extra']) 68 models.Model.save_base(instance, raw=True) 69 return [instance] 70 57 71 def o2o_create(pk, klass, data): 58 72 instance = klass() 59 73 instance.data_id = data … … 99 113 instance = klass.objects.get(id=pk) 100 114 testcase.assertEqual(data, [obj.id for obj in instance.data.all()]) 101 115 116 def im2m_compare(testcase, pk, klass, data): 117 instance = klass.objects.get(id=pk) 118 #actually nothing else to check, the instance just should exist 119 120 def im_compare(testcase, pk, klass, data): 121 instance = klass.objects.get(id=pk) 122 testcase.assertEqual(data['left'], instance.left_id) 123 testcase.assertEqual(data['right'], instance.right_id) 124 if 'extra' in data: 125 testcase.assertEqual(data['extra'], instance.extra) 126 else: 127 testcase.assertEqual('doesn\'t matter', instance.extra) 128 102 129 def o2o_compare(testcase, pk, klass, data): 103 130 instance = klass.objects.get(data=data) 104 131 testcase.assertEqual(data, instance.data_id) … … 119 146 generic_obj = (generic_create, generic_compare) 120 147 fk_obj = (fk_create, fk_compare) 121 148 m2m_obj = (m2m_create, m2m_compare) 149 im2m_obj = (im2m_create, im2m_compare) 150 im_obj = (im_create, im_compare) 122 151 o2o_obj = (o2o_create, o2o_compare) 123 152 pk_obj = (pk_create, pk_compare) 124 153 inherited_obj = (inherited_create, inherited_compare) … … 231 260 (fk_obj, 452, FKDataToField, None), 232 261 233 262 (fk_obj, 460, FKDataToO2O, 300), 263 264 (im2m_obj, 470, M2MIntermediateData, None), 265 266 #testing post- and prereferences and extra fields 267 (im_obj, 480, Intermediate, {'right': 300, 'left': 470}), 268 (im_obj, 481, Intermediate, {'right': 300, 'left': 490}), 269 (im_obj, 482, Intermediate, {'right': 500, 'left': 470}), 270 (im_obj, 483, Intermediate, {'right': 500, 'left': 490}), 271 (im_obj, 484, Intermediate, {'right': 300, 'left': 470, 'extra': "extra"}), 272 (im_obj, 485, Intermediate, {'right': 300, 'left': 490, 'extra': "extra"}), 273 (im_obj, 486, Intermediate, {'right': 500, 'left': 470, 'extra': "extra"}), 274 (im_obj, 487, Intermediate, {'right': 500, 'left': 490, 'extra': "extra"}), 275 276 (im2m_obj, 490, M2MIntermediateData, []), 234 277 235 278 (data_obj, 500, Anchor, "Anchor 3"), 236 279 (data_obj, 501, Anchor, "Anchor 4"),