Skip to content

Commit

Permalink
Issue #8: Test coverage first
Browse files Browse the repository at this point in the history
  • Loading branch information
boonya committed Mar 8, 2016
1 parent 2a99328 commit c70e384
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BaseModelsTests(unittest.TestCase):

def test_set_and_get_attrs(self):
"""Test setting and getting of domain model attributes."""

class User(models.DomainModel):
"""Test user domain model."""

Expand Down Expand Up @@ -59,6 +60,7 @@ class User(models.DomainModel):

def test_data_attr(self):
"""Test model's __data__ attribute."""

class User(models.DomainModel):
"""Test user domain model."""

Expand Down Expand Up @@ -157,6 +159,7 @@ class Model(models.DomainModel):

def test_field_could_not_be_rebound_in_different_model(self):
"""Test that field could not be rebound."""

class Model1(models.DomainModel):
"""Test model."""

Expand Down Expand Up @@ -324,12 +327,47 @@ def test_get_method_on_collection(self):
"""Test method get on Collection of Model."""
self.skipTest("Test is not implemented yet")

def test_get_data_method(self):
class Photo(models.DomainModel):
id = fields.Int()
url = fields.String()

class Profile(models.DomainModel):
id = fields.Int()
name = fields.String()
main_photo = fields.Model(Photo)
photos = fields.Collection(Photo)
birth_date = fields.Date()
sequence = fields.Collection(fields.Int)

photo1 = Photo(id=1, url='http://boonya.info/wat.jpg?1')
photo2 = Photo(id=2, url='http://boonya.info/wat.jpg?2')
profile = Profile(id=1, name='John', main_photo=photo1,
photos=[photo1, photo2],
sequence=[1, 1, 2, 3, 5, 8, 13],
birth_date=datetime.date(year=1986, month=04,
day=26))

self.assertDictEqual(profile.get_data(), {
'id': 1,
'name': 'John',
'main_photo': {'id': 1,
'url': 'http://boonya.info/wat.jpg?1'},
'photos': [
{'id': 1, 'url': 'http://boonya.info/wat.jpg?1'},
{'id': 2, 'url': 'http://boonya.info/wat.jpg?2'}
],
'sequence': [1, 1, 2, 3, 5, 8, 13],
'birth_date': datetime.date(year=1986, month=04, day=26)
})


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

def test_repr(self):
"""Test model __repr__()."""

class User(models.DomainModel):
"""Test user domain model."""

Expand Down Expand Up @@ -364,6 +402,7 @@ class ModelStrTests(unittest.TestCase):

def test_str_with_single_view_key(self):
"""Test model __str__()."""

class User(models.DomainModel):
"""Test user domain model."""

Expand Down Expand Up @@ -397,6 +436,7 @@ class User(models.DomainModel):

def test_str_with_multiple_view_keys(self):
"""Test model __str__()."""

class User(models.DomainModel):
"""Test user domain model."""

Expand Down Expand Up @@ -430,6 +470,7 @@ class User(models.DomainModel):

def test_str_without_view_key(self):
"""Test model __str__()."""

class User(models.DomainModel):
"""Test user domain model."""

Expand All @@ -456,6 +497,7 @@ class ModelSlotsOptimizationTests(unittest.TestCase):

def test_model_slots(self):
"""Test model slots optimization."""

class Model(models.DomainModel):
"""Test model."""

Expand All @@ -470,6 +512,7 @@ class Model(models.DomainModel):

def test_model_slots_disabling(self):
"""Test disabling of model slots optimization."""

class Model(models.DomainModel):
"""Test model."""

Expand All @@ -489,6 +532,7 @@ class ModelsEqualityComparationsTests(unittest.TestCase):

def test_models_equal_single_key(self):
"""Test models equality comparator based on unique key."""

class Model(models.DomainModel):
"""Test domain model with single unique key."""

Expand All @@ -506,6 +550,7 @@ class Model(models.DomainModel):

def test_models_not_equal_single_key(self):
"""Test that models are not equal."""

class Model(models.DomainModel):
"""Test domain model with single unique key."""

Expand All @@ -523,6 +568,7 @@ class Model(models.DomainModel):

def test_models_equal_multiple_keys(self):
"""Test models equality comparator based on unique key."""

class Model(models.DomainModel):
"""Test domain model with multiple unique key."""

Expand All @@ -543,6 +589,7 @@ class Model(models.DomainModel):

def test_models_not_equal_multiple_keys(self):
"""Test that models are not equal."""

class Model(models.DomainModel):
"""Test domain model with multiple unique key."""

Expand All @@ -563,6 +610,7 @@ class Model(models.DomainModel):

def test_models_not_equal_multiple_keys_first_equal(self):
"""Test that models are not equal."""

class Model(models.DomainModel):
"""Test domain model with multiple unique key."""

Expand All @@ -583,6 +631,7 @@ class Model(models.DomainModel):

def test_models_not_equal_different_classes(self):
"""Test that models are not equal."""

class Model1(models.DomainModel):
"""Test domain model with single unique key."""

Expand All @@ -606,6 +655,7 @@ class Model2(models.DomainModel):

def test_models_not_equal_scalar_value(self):
"""Test that model and scalar value are not equal."""

class Model(models.DomainModel):
"""Test domain model with single unique key."""

Expand All @@ -620,6 +670,7 @@ class Model(models.DomainModel):

def test_models_not_equal_unknown_unique_key(self):
"""Test that models are not equal."""

class Model(models.DomainModel):
"""Test domain model without unique key."""

Expand All @@ -636,6 +687,7 @@ class Model(models.DomainModel):

def test_same_models_equal_unknown_unique_key(self):
"""Test that models are not equal."""

class Model(models.DomainModel):
"""Test domain model without unique key."""

Expand All @@ -649,6 +701,7 @@ class Model(models.DomainModel):

def test_non_equal_models_in_set_single_key(self):
"""Test that non-equal models work properly with sets."""

class Model(models.DomainModel):
"""Test domain model with single unique key."""

Expand All @@ -671,6 +724,7 @@ class Model(models.DomainModel):

def test_equal_models_in_set_single_key(self):
"""Test that equal models work properly with sets."""

class Model(models.DomainModel):
"""Test domain model with single unique key."""

Expand All @@ -693,6 +747,7 @@ class Model(models.DomainModel):

def test_non_equal_models_in_set_multiple_keys(self):
"""Test that non-equal models work properly with sets."""

class Model(models.DomainModel):
"""Test domain model with multiple unique key."""

Expand All @@ -719,6 +774,7 @@ class Model(models.DomainModel):

def test_equal_models_in_set_multiple_keys(self):
"""Test that equal models work properly with sets."""

class Model(models.DomainModel):
"""Test domain model with multiple unique key."""

Expand All @@ -745,6 +801,7 @@ class Model(models.DomainModel):

def test_non_equal_models_in_set_without_unique_key(self):
"""Test that non-equal models work properly with sets."""

class Model(models.DomainModel):
"""Test domain model without unique key."""

Expand All @@ -766,6 +823,7 @@ class Model(models.DomainModel):

def test_equal_models_in_set_without_unique_key(self):
"""Test that equal models work properly with sets."""

class Model(models.DomainModel):
"""Test domain model without unique key."""

Expand All @@ -785,6 +843,7 @@ class Model(models.DomainModel):

def test_models_collection_extending(self):
"""Test model's collection extending."""

class Credit(models.DomainModel):
"""Test credit domain model."""

Expand Down

0 comments on commit c70e384

Please sign in to comment.