diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-08-25 19:10:43 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-08-25 19:10:43 -0400 |
commit | 8c8d6ee95dbd06cb8bba5272f1e5cc138aadc49c (patch) | |
tree | 983d55ba24401e26905553c59aa7a767f6571e0e /test/ext/test_mutable.py | |
parent | a16ee423e4528bd7a6ba6375cccd88b7450c58d3 (diff) | |
parent | 88f7ec6a0efe68305d5d1ee429565c1778ec6a87 (diff) | |
download | sqlalchemy-8c8d6ee95dbd06cb8bba5272f1e5cc138aadc49c.tar.gz |
Merge branch 'mutable-dict-coerce-fix' of https://bitbucket.org/goodscloud/sqlalchemy into pr27
Diffstat (limited to 'test/ext/test_mutable.py')
-rw-r--r-- | test/ext/test_mutable.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/ext/test_mutable.py b/test/ext/test_mutable.py index dc0b5ba1c..305eb8c3a 100644 --- a/test/ext/test_mutable.py +++ b/test/ext/test_mutable.py @@ -332,6 +332,59 @@ class MutableAssociationScalarJSONTest(_MutableDictTestBase, fixtures.MappedTest ) +class CustomMutableAssociationScalarJSONTest(_MutableDictTestBase, fixtures.MappedTest): + + CustomMutableDict = None + + @classmethod + def _type_fixture(cls): + if not(getattr(cls, 'CustomMutableDict')): + MutableDict = super(CustomMutableAssociationScalarJSONTest, cls)._type_fixture() + class CustomMutableDict(MutableDict): + pass + cls.CustomMutableDict = CustomMutableDict + return cls.CustomMutableDict + + @classmethod + def define_tables(cls, metadata): + import json + + class JSONEncodedDict(TypeDecorator): + impl = VARCHAR(50) + + def process_bind_param(self, value, dialect): + if value is not None: + value = json.dumps(value) + + return value + + def process_result_value(self, value, dialect): + if value is not None: + value = json.loads(value) + return value + + CustomMutableDict = cls._type_fixture() + CustomMutableDict.associate_with(JSONEncodedDict) + + Table('foo', metadata, + Column('id', Integer, primary_key=True, + test_needs_autoincrement=True), + Column('data', JSONEncodedDict), + Column('unrelated_data', String(50)) + ) + + def test_pickle_parent(self): + # Picklers don't know how to pickle CustomMutableDict, but we aren't testing that here + pass + + def test_coerce(self): + sess = Session() + f1 = Foo(data={'a': 'b'}) + sess.add(f1) + sess.flush() + eq_(type(f1.data), self._type_fixture()) + + class _CompositeTestBase(object): @classmethod def define_tables(cls, metadata): |