def test_ignores_unknown_event_types(self): connection = pretend.stub( fetchone=lambda: self.create_event(None, None, None)) listener = MySQLDatabaseListener(None, connection, None, DummyLogger()) iterable = iter(listener) res = next(iterable) self.assertIs(res, None)
def test_invalidate_row_succeeds_on_cache_delete_failure(self): cache = pretend.stub(delete=lambda key: fail(Exception()), ) d = Driver(FormattingKeyMaker({"foo_table": ["bar"]}), cache, DummyLogger()) invalidate_d = d.invalidate_row("foo_table", {}) res = self.successResultOf(invalidate_d) self.assertIs(res, None)
def test_invalidate_row_calls_cache_delete(self): cache = pretend.stub( delete=pretend.call_recorder(lambda key: succeed(None))) d = Driver(FormattingKeyMaker({"foo_table": ["bar", "baz"]}), cache, DummyLogger()) d.invalidate_row("foo_table", {}) self.assertEqual( cache.delete.calls, [pretend.call("bar"), pretend.call("baz")])
def test_invalidate_row_waits_for_cache_delete(self): d1 = Deferred() cache = pretend.stub(delete=lambda key: d1, ) d = Driver(FormattingKeyMaker({"foo_table": ["bar"]}), cache, DummyLogger()) invalidate_d = d.invalidate_row("foo_table", {}) self.assertNoResult(invalidate_d) d1.callback(None) res = self.successResultOf(invalidate_d) self.assertIs(res, None)
def test_calls_invalidate_row_on_update_row_v2(self): connection = pretend.stub(fetchone=lambda: self.create_event( UPDATE_ROWS_EVENT_V2, "my_table", [{ "before_values": {} }])) d = Deferred() driver = pretend.stub( invalidate_row=pretend.call_recorder(lambda table, row: d)) listener = MySQLDatabaseListener(None, connection, driver, DummyLogger()) iterable = iter(listener) res = next(iterable) self.assertEqual(driver.invalidate_row.calls, [ pretend.call("my_table", {}), ]) self.assertIs(res, d)
def test_calls_invalidate_row_multiple_times_on_update_row(self): connection = pretend.stub(fetchone=lambda: self.create_event( UPDATE_ROWS_EVENT_V2, "my_table", [ { "before_values": {} }, { "before_values": {} }, ])) driver = pretend.stub( invalidate_row=pretend.call_recorder(lambda table, row: None)) listener = MySQLDatabaseListener(None, connection, driver, DummyLogger()) iterable = iter(listener) next(iterable) next(iterable) self.assertEqual(driver.invalidate_row.calls, [ pretend.call("my_table", {}), pretend.call("my_table", {}), ])
def test_invalidate_row_returns_deferred(self): d = Driver(FormattingKeyMaker({}), None, DummyLogger()) res = self.successResultOf(d.invalidate_row("foo_table", {})) self.assertIs(res, None)