def test_decorator(self, connections_mock): cursor = connections_mock.set_results((1,), (1,), using='thisdb') wrapped = locking.lock(lambda: 1 / 0, 'pudding', using='thisdb') with self.assertRaises(ZeroDivisionError): wrapped() cursor.execute.assert_any_call("SELECT GET_LOCK(%s, %s)", ("AnotherDatabase:pudding", 3)) cursor.execute.assert_any_call("SELECT RELEASE_LOCK(%s)", ("AnotherDatabase:pudding",)) self.assertEqual(cursor.execute.call_count, 2)
def test_proxy(self): lock = locking.lock('pudding', using='thisdb', timeout=10) self.assertEqual(lock.nickname, 'pudding') self.assertEqual(lock.using, 'thisdb') self.assertEqual(lock.timeout, 10)