(self)
| 197 | |
| 198 | @provision.allow_stale_updates |
| 199 | def test_basic(self): |
| 200 | Foo = self.classes.Foo |
| 201 | |
| 202 | s1 = self._fixture() |
| 203 | f1 = Foo(value="f1") |
| 204 | f2 = Foo(value="f2") |
| 205 | s1.add_all((f1, f2)) |
| 206 | s1.commit() |
| 207 | |
| 208 | f1.value = "f1rev2" |
| 209 | with conditional_sane_rowcount_warnings(update=True): |
| 210 | s1.commit() |
| 211 | |
| 212 | s2 = fixture_session() |
| 213 | f1_s = s2.get(Foo, f1.id) |
| 214 | f1_s.value = "f1rev3" |
| 215 | with conditional_sane_rowcount_warnings(update=True): |
| 216 | s2.commit() |
| 217 | |
| 218 | f1.value = "f1rev3mine" |
| 219 | |
| 220 | # Only dialects with a sane rowcount can detect the |
| 221 | # StaleDataError |
| 222 | if testing.db.dialect.supports_sane_rowcount: |
| 223 | assert_raises_message( |
| 224 | sa.orm.exc.StaleDataError, |
| 225 | r"UPDATE statement on table 'version_table' expected " |
| 226 | r"to update 1 row\(s\); 0 were matched.", |
| 227 | s1.commit, |
| 228 | ), |
| 229 | s1.rollback() |
| 230 | else: |
| 231 | with conditional_sane_rowcount_warnings(update=True): |
| 232 | s1.commit() |
| 233 | |
| 234 | # new in 0.5 ! don't need to close the session |
| 235 | f1 = s1.get(Foo, f1.id) |
| 236 | f2 = s1.get(Foo, f2.id) |
| 237 | |
| 238 | f1_s.value = "f1rev4" |
| 239 | with conditional_sane_rowcount_warnings(update=True): |
| 240 | s2.commit() |
| 241 | |
| 242 | s1.delete(f1) |
| 243 | s1.delete(f2) |
| 244 | |
| 245 | if testing.db.dialect.supports_sane_multi_rowcount: |
| 246 | assert_raises_message( |
| 247 | sa.orm.exc.StaleDataError, |
| 248 | r"DELETE statement on table 'version_table' expected " |
| 249 | r"to delete 2 row\(s\); 1 were matched.", |
| 250 | s1.commit, |
| 251 | ) |
| 252 | else: |
| 253 | with conditional_sane_rowcount_warnings(delete=True): |
| 254 | s1.commit() |
| 255 | |
| 256 | def test_multiple_updates(self): |
nothing calls this directly
no test coverage detected