Updated new deref test

This commit is contained in:
Ross Lawley 2012-02-29 11:23:43 +00:00
parent 398fd4a548
commit 5a1eaa0a98

View File

@ -783,41 +783,30 @@ class FieldTest(unittest.TestCase):
root = root.reload() root = root.reload()
self.assertEquals(root.children, [company]) self.assertEquals(root.children, [company])
self.assertEquals(company.parents, [root]) self.assertEquals(company.parents, [root])
def test_dict_in_dbref_instance(self): def test_dict_in_dbref_instance(self):
class Person(Document): class Person(Document):
name = StringField(max_length=250, required=True) name = StringField(max_length=250, required=True)
meta = { "ordering" : "name" }
class Room(Document): class Room(Document):
number = StringField(max_length=250, required=True) number = StringField(max_length=250, required=True)
staffs_with_position = ListField(DictField()) staffs_with_position = ListField(DictField())
meta = { "ordering" : "number" }
Person.drop_collection() Person.drop_collection()
Room.drop_collection()
# 201
bob = Person.objects.create(name='Bob') bob = Person.objects.create(name='Bob')
bob.save() bob.save()
keven = Person.objects.create(name='Keven')
keven.save()
sarah = Person.objects.create(name='Sarah') sarah = Person.objects.create(name='Sarah')
sarah.save() sarah.save()
room_201 = Room.objects.create( number = "201") room_101 = Room.objects.create(number="101")
room_201.staffs_with_position = [ {'position_key': 'window', 'staff' : sarah.to_dbref() }, room_101.staffs_with_position = [
{ 'position_key': 'door', 'staff': bob.to_dbref() }, {'position_key': 'window', 'staff': sarah},
{ 'position_key': 'center' , 'staff' : keven.to_dbref() } ] {'position_key': 'door', 'staff': bob.to_dbref()}]
room_201.save() room_101.save()
room = Room.objects.first().select_related() room = Room.objects.first().select_related()
room.to_mongo() self.assertEquals(room.staffs_with_position[0]['staff'], sarah)
self.assertEquals(room.staffs_with_position[1]['staff'], bob)