~therve/storm/twisted-integration

« back to all changes in this revision

Viewing changes to tests/store/base.py

Flush the store if the local key for a reference is unset (as opposed to None).

This causes Reference.__get__() to look up the correct remote row 
in this situation rather than returning None.
[r=niemeyer,therve] [f=324724]

Show diffs side-by-side

added added

removed removed

Lines of Context:
2989
2989
        # Bypass the store to prevent flushing.
2990
2990
        self.assertEquals(self.get_bar_200_title(), "Title 200")
2991
2991
 
2992
 
    def test_reference_wont_touch_store_when_key_is_unset(self):
2993
 
        bar = self.store.get(Bar, 200)
2994
 
        del bar.foo_id
2995
 
        bar.title = u"Don't flush this!"
2996
 
 
2997
 
        self.assertEquals(bar.foo, None)
2998
 
 
2999
 
        # Bypass the store to prevent flushing.
3000
 
        connection = self.store._connection
3001
 
        result = connection.execute("SELECT title FROM bar WHERE id=200")
3002
 
        self.assertEquals(result.get_one()[0], "Title 200")
3003
 
 
3004
2992
    def test_reference_wont_touch_store_with_composed_key_none(self):
3005
2993
        class Bar(object):
3006
2994
            __storm_table__ = "bar"
3189
3177
        self.store.remove(bar)
3190
3178
        self.assertEquals(foo.bar, None)
3191
3179
 
 
3180
    def test_back_reference_on_pending_add(self):
 
3181
        ref1 = SelfRef()
 
3182
        ref2 = SelfRef()
 
3183
        self.store.add(ref1)
 
3184
        self.store.add(ref2)
 
3185
 
 
3186
        ref1.selfref = ref2
 
3187
        # ref2 has not been added to the database yet, but is linked
 
3188
        # to ref1.
 
3189
        self.assertEqual(ref2.id, None)
 
3190
        self.assertEqual(ref2.selfref_on_remote, ref1)
 
3191
 
3192
3192
    def test_reference_loop_with_undefined_keys_fails(self):
3193
3193
        """A loop of references with undefined keys raises OrderLoopError."""
3194
3194
        ref1 = SelfRef()