-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated serialization and deserialization to support
- Loading branch information
1 parent
d2d02d6
commit f64b814
Showing
4 changed files
with
54 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
import json | ||
|
||
from expects import expect | ||
from ._helpers import MyList | ||
from ._helpers import MyList, MyDict | ||
|
||
from booby import errors, fields, models | ||
|
||
|
@@ -228,7 +228,7 @@ def test_should_return_dict_with_model_mapped_fields(self): | |
|
||
expect(result).to.have.keys(name='Jack', email='[email protected]') | ||
|
||
def test_should_deserialize_embedded_model_if_field_is_embedded_field(self): | ||
def test_should_deserialize_embedded_dict_if_field_is_embedded_field(self): | ||
result = UserWithTokenAndMappedFields.deserialize({ | ||
'name': 'Jack', 'email': '[email protected]', | ||
'token': { | ||
|
@@ -238,6 +238,16 @@ def test_should_deserialize_embedded_model_if_field_is_embedded_field(self): | |
|
||
expect(result['token']).to.have.keys(key='foo', secret='bar') | ||
|
||
def test_should_deserialize_embedded_mutable_mapping_if_field_is_embedded_field(self): | ||
result = UserWithTokenAndMappedFields.deserialize({ | ||
'name': 'Jack', 'email': '[email protected]', | ||
'token': MyDict( | ||
accessToken='foo', secretToken='bar' | ||
) | ||
}) | ||
|
||
expect(result['token']).to.have.keys(key='foo', secret='bar') | ||
|
||
|
||
class TestSerializeModel(object): | ||
def test_should_return_dict_with_model_fields(self): | ||
|
@@ -285,6 +295,16 @@ def test_should_serialize_list_of_models_and_values(self): | |
expect(result['tokens']).to.equal([self.token1.serialize(), 'foo', | ||
self.token2.serialize()]) | ||
|
||
def test_should_serialize_mutable_sequence_of_models(self): | ||
user = UserWithList( | ||
name='Jack', email='[email protected]', | ||
tokens=MyList(self.token1, self.token2)) | ||
|
||
result = user.serialize() | ||
|
||
expect(result['tokens']).to.equal([self.token1.serialize(), | ||
self.token2.serialize()]) | ||
|
||
def setup(self): | ||
self.token1 = TokenWithMappedFields(key='foo', secret='bar') | ||
self.token2 = TokenWithMappedFields(key='fuu', secret='baz') | ||
|