@@ -57,47 +57,6 @@ class User(models.DomainModel):
5757 self .assertEqual (user2 .gender , 'female' )
5858 self .assertEqual (user2 .birth_date , '05/04/1985' )
5959
60- def test_data_attr (self ):
61- """Test model's __data__ attribute."""
62- class User (models .DomainModel ):
63- """Test user domain model."""
64-
65- id = fields .Int ()
66- email = fields .String ()
67- first_name = fields .String ()
68- last_name = fields .String ()
69- gender = fields .String ()
70- birth_date = fields .String ()
71-
72- user1 = User ()
73- user1 .id = 1
74- user1 .email = 'example1@example.com'
75- user1 .first_name = 'John'
76- user1 .last_name = 'Smith'
77- user1 .gender = 'male'
78- user1 .birth_date = '05/04/1988'
79-
80- user2 = User ()
81- user2 .id = 2
82- user2 .email = 'example2@example.com'
83- user2 .first_name = 'Jane'
84- user2 .last_name = 'Smith'
85- user2 .gender = 'female'
86- user2 .birth_date = '05/04/1985'
87-
88- self .assertEquals (user1 .__data__ , dict (id = 1 ,
89- email = 'example1@example.com' ,
90- first_name = 'John' ,
91- last_name = 'Smith' ,
92- gender = 'male' ,
93- birth_date = '05/04/1988' ))
94- self .assertEquals (user2 .__data__ , dict (id = 2 ,
95- email = 'example2@example.com' ,
96- first_name = 'Jane' ,
97- last_name = 'Smith' ,
98- gender = 'female' ,
99- birth_date = '05/04/1985' ))
100-
10160 def test_not_valid_unique_key_field (self ):
10261 """Test that error is raised when unique key is not correct."""
10362 with self .assertRaises (errors .Error ):
@@ -324,6 +283,40 @@ def test_get_method_on_collection(self):
324283 """Test method get on Collection of Model."""
325284 self .skipTest ("Test is not implemented yet" )
326285
286+ def test_get_data_method (self ):
287+ class Photo (models .DomainModel ):
288+ id = fields .Int ()
289+ url = fields .String ()
290+
291+ class Profile (models .DomainModel ):
292+ id = fields .Int ()
293+ name = fields .String ()
294+ main_photo = fields .Model (Photo )
295+ photos = fields .Collection (Photo )
296+ birth_date = fields .Date ()
297+ sequence = fields .Collection (fields .Int )
298+
299+ photo1 = Photo (id = 1 , url = 'http://boonya.info/wat.jpg?1' )
300+ photo2 = Photo (id = 2 , url = 'http://boonya.info/wat.jpg?2' )
301+ profile = Profile (id = 1 , name = 'John' , main_photo = photo1 ,
302+ photos = [photo1 , photo2 ],
303+ sequence = [1 , 1 , 2 , 3 , 5 , 8 , 13 ],
304+ birth_date = datetime .date (year = 1986 , month = 4 ,
305+ day = 26 ))
306+
307+ self .assertDictEqual (profile .get_data (), {
308+ 'id' : 1 ,
309+ 'name' : 'John' ,
310+ 'main_photo' : {'id' : 1 ,
311+ 'url' : 'http://boonya.info/wat.jpg?1' },
312+ 'photos' : [
313+ {'id' : 1 , 'url' : 'http://boonya.info/wat.jpg?1' },
314+ {'id' : 2 , 'url' : 'http://boonya.info/wat.jpg?2' }
315+ ],
316+ 'sequence' : [1 , 1 , 2 , 3 , 5 , 8 , 13 ],
317+ 'birth_date' : datetime .date (year = 1986 , month = 4 , day = 26 )
318+ })
319+
327320
328321class ModelReprTests (unittest .TestCase ):
329322 """Tests for model Pythonic representation."""
0 commit comments