Skip to content

Commit cbfce0c

Browse files
committed
Issue #8: Test coverage first
1 parent 2a99328 commit cbfce0c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/test_models.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class User(models.DomainModel):
5959

6060
def test_data_attr(self):
6161
"""Test model's __data__ attribute."""
62+
6263
class User(models.DomainModel):
6364
"""Test user domain model."""
6465

@@ -324,12 +325,47 @@ def test_get_method_on_collection(self):
324325
"""Test method get on Collection of Model."""
325326
self.skipTest("Test is not implemented yet")
326327

328+
def test_get_data_method(self):
329+
class Photo(models.DomainModel):
330+
id = fields.Int()
331+
url = fields.String()
332+
333+
class Profile(models.DomainModel):
334+
id = fields.Int()
335+
name = fields.String()
336+
main_photo = fields.Model(Photo)
337+
photos = fields.Collection(Photo)
338+
birth_date = fields.Date()
339+
sequence = fields.Collection(fields.Int)
340+
341+
photo1 = Photo(id=1, url='http://boonya.info/wat.jpg?1')
342+
photo2 = Photo(id=2, url='http://boonya.info/wat.jpg?2')
343+
profile = Profile(id=1, name='John', main_photo=photo1,
344+
photos=[photo1, photo2],
345+
sequence=[1, 1, 2, 3, 5, 8, 13],
346+
birth_date=datetime.date(year=1986, month=4,
347+
day=26))
348+
349+
self.assertDictEqual(profile.get_data(), {
350+
'id': 1,
351+
'name': 'John',
352+
'main_photo': {'id': 1,
353+
'url': 'http://boonya.info/wat.jpg?1'},
354+
'photos': [
355+
{'id': 1, 'url': 'http://boonya.info/wat.jpg?1'},
356+
{'id': 2, 'url': 'http://boonya.info/wat.jpg?2'}
357+
],
358+
'sequence': [1, 1, 2, 3, 5, 8, 13],
359+
'birth_date': datetime.date(year=1986, month=4, day=26)
360+
})
361+
327362

328363
class ModelReprTests(unittest.TestCase):
329364
"""Tests for model Pythonic representation."""
330365

331366
def test_repr(self):
332367
"""Test model __repr__()."""
368+
333369
class User(models.DomainModel):
334370
"""Test user domain model."""
335371

0 commit comments

Comments
 (0)