diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-05-22 15:42:59 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-05-23 15:14:04 -0400 |
| commit | f46551de450a76de4105bda3be8d0d5c5fc0d52c (patch) | |
| tree | 2bf640007f988f6851c359eee7e38886b81239d9 /test/ext | |
| parent | a987942761542666be89f40a9ac4a35e001b8265 (diff) | |
| download | sqlalchemy-f46551de450a76de4105bda3be8d0d5c5fc0d52c.tar.gz | |
Add AttributeEvents.modified
Added new event handler :meth:`.AttributeEvents.modified` which is
triggered when the func:`.attributes.flag_modified` function is
invoked, which is common when using the :mod:`sqlalchemy.ext.mutable`
extension module.
Change-Id: Ic152f1d5c53087d780b24ed7f1f1571527b9e8fc
Fixes: #3303
Diffstat (limited to 'test/ext')
| -rw-r--r-- | test/ext/test_mutable.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ext/test_mutable.py b/test/ext/test_mutable.py index 23bccafe9..366b2006f 100644 --- a/test/ext/test_mutable.py +++ b/test/ext/test_mutable.py @@ -2,6 +2,7 @@ from sqlalchemy import Integer, ForeignKey, String, func from sqlalchemy.types import PickleType, TypeDecorator, VARCHAR from sqlalchemy.orm import mapper, Session, composite, column_property from sqlalchemy.orm.mapper import Mapper +from sqlalchemy.orm import attributes from sqlalchemy.orm.instrumentation import ClassManager from sqlalchemy.testing.schema import Table, Column from sqlalchemy.testing import eq_, assert_raises_message, assert_raises @@ -9,6 +10,8 @@ from sqlalchemy.testing.util import picklers from sqlalchemy.testing import fixtures from sqlalchemy.ext.mutable import MutableComposite from sqlalchemy.ext.mutable import MutableDict, MutableList, MutableSet +from sqlalchemy.testing import mock +from sqlalchemy import event class Foo(fixtures.BasicEntity): @@ -112,6 +115,19 @@ class _MutableDictTestBase(_MutableDictTestFixture): eq_(f1.data, {'a': 'c'}) + def test_modified_event(self): + canary = mock.Mock() + event.listen(Foo.data, "modified", canary) + + f1 = Foo(data={"a": "b"}) + f1.data["a"] = "c" + + eq_( + canary.mock_calls, + [mock.call( + f1, attributes.Event(Foo.data.impl, attributes.OP_MODIFIED))] + ) + def test_clear(self): sess = Session() |
