|
43 | 43 | from crate.testing.settings import crate_host
|
44 | 44 |
|
45 | 45 |
|
46 |
| -class SqlAlchemyCompilerTest(ParametrizedTestCase): |
| 46 | +class SqlAlchemyCompilerTest(ParametrizedTestCase, ExtraAssertions): |
47 | 47 |
|
48 | 48 | def setUp(self):
|
49 | 49 | self.crate_engine = sa.create_engine('crate://')
|
@@ -257,6 +257,34 @@ def test_insert_manyvalues(self):
|
257 | 257 | mock.call(mock.ANY, 'INSERT INTO mytable (name) VALUES (?)', ('foo_4', ), None),
|
258 | 258 | ])
|
259 | 259 |
|
| 260 | + def test_for_update(self): |
| 261 | + """ |
| 262 | + Verify the `CrateCompiler.for_update_clause` method to |
| 263 | + omit the clause, since CrateDB does not support it. |
| 264 | + """ |
| 265 | + |
| 266 | + with warnings.catch_warnings(record=True) as w: |
| 267 | + |
| 268 | + # By default, warnings from a loop will only be emitted once. |
| 269 | + # This scenario tests exactly this behaviour, to verify logs |
| 270 | + # don't get flooded. |
| 271 | + warnings.simplefilter("once") |
| 272 | + |
| 273 | + selectable = self.mytable.select().with_for_update() |
| 274 | + _ = str(selectable.compile(bind=self.crate_engine)) |
| 275 | + |
| 276 | + selectable = self.mytable.select().with_for_update() |
| 277 | + statement = str(selectable.compile(bind=self.crate_engine)) |
| 278 | + |
| 279 | + # Verify SQL statement. |
| 280 | + self.assertEqual(statement, "SELECT mytable.name, mytable.data \nFROM mytable") |
| 281 | + |
| 282 | + # Verify if corresponding warning is emitted, once. |
| 283 | + self.assertEqual(len(w), 1) |
| 284 | + self.assertIsSubclass(w[-1].category, UserWarning) |
| 285 | + self.assertIn("CrateDB does not support the 'INSERT ... FOR UPDATE' clause, " |
| 286 | + "it will be omitted when generating SQL statements.", str(w[-1].message)) |
| 287 | + |
260 | 288 |
|
261 | 289 | FakeCursor = MagicMock(name='FakeCursor', spec=Cursor)
|
262 | 290 |
|
|
0 commit comments