test the contract of load/refresh such that history is reset. This has never been an official contract but we are testing it here to ensure it is maintained given the loading performance enhancements.
(self)
| 2907 | eq_(canary, []) |
| 2908 | |
| 2909 | def test_changes_reset(self): |
| 2910 | """test the contract of load/refresh such that history is reset. |
| 2911 | |
| 2912 | This has never been an official contract but we are testing it |
| 2913 | here to ensure it is maintained given the loading performance |
| 2914 | enhancements. |
| 2915 | |
| 2916 | """ |
| 2917 | User = self.classes.User |
| 2918 | |
| 2919 | @event.listens_for(User, "load") |
| 2920 | def canary1(obj, context): |
| 2921 | obj.name = "new name!" |
| 2922 | |
| 2923 | @event.listens_for(User, "refresh") |
| 2924 | def canary2(obj, context, props): |
| 2925 | obj.name = "refreshed name!" |
| 2926 | |
| 2927 | sess = fixture_session() |
| 2928 | u1 = User(name="u1") |
| 2929 | sess.add(u1) |
| 2930 | sess.commit() |
| 2931 | sess.close() |
| 2932 | |
| 2933 | u1 = sess.query(User).first() |
| 2934 | eq_(attributes.get_history(u1, "name"), ((), ["new name!"], ())) |
| 2935 | assert "name" not in attributes.instance_state(u1).committed_state |
| 2936 | assert u1 not in sess.dirty |
| 2937 | |
| 2938 | sess.expire(u1) |
| 2939 | u1.id |
| 2940 | eq_(attributes.get_history(u1, "name"), ((), ["refreshed name!"], ())) |
| 2941 | assert "name" not in attributes.instance_state(u1).committed_state |
| 2942 | assert u1 in sess.dirty |
| 2943 | |
| 2944 | def test_repeated_rows(self): |
| 2945 | User = self.classes.User |
nothing calls this directly
no test coverage detected