def test_cursor_executemany(self): self.cursor.executemany("SELECT", [("A", ), ("B", )]) self.assertEqual("execute", self.cursor.cursor.method) self.assertEqual("SELECT", self.cursor.cursor.query) self.assertEqual([("A", ), ("B", )], self.cursor.cursor.args) zc = ZopeConnection(MyConnectionStub2(), self.typeInfo) self.cursor = ZopeCursor(zc.conn.cursor(), zc) self.cursor.executemany("SELECT", [("A", ), ("B", )]) self.assertEqual("executemany", self.cursor.cursor.method) self.assertEqual("SELECT", self.cursor.cursor.query) self.assertEqual([("A", ), ("B", )], self.cursor.cursor.args)
def executemany(operation, seq_of_parameters=None): """See IZopeCursor""" raise RuntimeError('Oos') try: return ZopeCursor.execute(self, operation, seq_of_parameters) except psycopg2.Error as error: _handle_psycopg_exception(error)
def executemany(operation, seq_of_parameters=None): """See IZopeCursor""" raise RuntimeError, 'Oos' try: return ZopeCursor.execute(self, operation, seq_of_parameters) except psycopg2.Error, error: _handle_psycopg_exception(error)
def test_cursor_executemany(self): self.cursor.executemany("SELECT", [("A",), ("B",)]) self.assertEqual("execute", self.cursor.cursor.method) self.assertEqual("SELECT", self.cursor.cursor.query) self.assertEqual([("A",), ("B",)], self.cursor.cursor.args) zc = ZopeConnection(MyConnectionStub2(), self.typeInfo) self.cursor = ZopeCursor(zc.conn.cursor(), zc) self.cursor.executemany("SELECT", [("A",), ("B",)]) self.assertEqual("executemany", self.cursor.cursor.method) self.assertEqual("SELECT", self.cursor.cursor.query) self.assertEqual([("A",), ("B",)], self.cursor.cursor.args)
def execute(self, operation, parameters=None): """See IZopeCursor""" try: return ZopeCursor.execute(self, operation, parameters) except psycopg2.Error as error: _handle_psycopg_exception(error)
def setUp(self): self.typeInfo = MyTypeInfoStub() zc = ZopeConnection(MyConnectionStub(), self.typeInfo) self.cursor = ZopeCursor(zc.conn.cursor(), zc)
class ZopeCursorTests(TestCase): def setUp(self): self.typeInfo = MyTypeInfoStub() zc = ZopeConnection(MyConnectionStub(), self.typeInfo) self.cursor = ZopeCursor(zc.conn.cursor(), zc) def tearDown(self): transaction.abort() def test_cursor_fetchone(self): results = self.cursor.fetchone() expected = converted[0] self.assertEqual( results, expected, 'type conversion was not performed in cursor.fetchone:\n' 'got %r, expected %r' % (results, expected)) def test_cursor_fetchone_no_more_results(self): self.cursor.cursor._raw = [] results = self.cursor.fetchone() expected = None self.assertEqual( results, expected, 'type conversion was not performed in cursor.fetchone:\n' 'got %r, expected %r' % (results, expected)) def test_cursor_fetchmany(self): results = self.cursor.fetchmany() expected = converted[:2] self.assertEqual( results, expected, 'type conversion was not performed in cursor.fetchmany:\n' 'got %r,\n' 'expected %r' % (results, expected)) def test_cursor_fetchall(self): results = self.cursor.fetchall() expected = converted self.assertEqual( results, expected, 'type conversion was not performed in cursor.fetchall:\n' 'got %r,\n' 'expected %r' % (results, expected)) def test_cursor_executemany(self): self.cursor.executemany("SELECT", [("A", ), ("B", )]) self.assertEqual("execute", self.cursor.cursor.method) self.assertEqual("SELECT", self.cursor.cursor.query) self.assertEqual([("A", ), ("B", )], self.cursor.cursor.args) zc = ZopeConnection(MyConnectionStub2(), self.typeInfo) self.cursor = ZopeCursor(zc.conn.cursor(), zc) self.cursor.executemany("SELECT", [("A", ), ("B", )]) self.assertEqual("executemany", self.cursor.cursor.method) self.assertEqual("SELECT", self.cursor.cursor.query) self.assertEqual([("A", ), ("B", )], self.cursor.cursor.args) def test_cursor_query_encoding(self): self.cursor.execute(u'\u0422\u0435\u0441\u0442') self.assertEqual('\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82', self.cursor.cursor.query) self.typeInfo.setEncoding("windows-1251") self.cursor.execute(u'\u0422\u0435\u0441\u0442') self.assertEqual('\xd2\xe5\xf1\xf2', self.cursor.cursor.query) def test_cursor_tuple_args_encoding(self): self.typeInfo.setEncoding("windows-1251") self.cursor.execute("SELECT * FROM table", (u'\u0422\u0435\u0441\u0442', )) self.assertEqual(('\xd2\xe5\xf1\xf2', ), self.cursor.cursor.args) def test_cursor_list_args_encoding(self): self.typeInfo.setEncoding("windows-1251") self.cursor.execute(u'\u0422\u0435\u0441\u0442', [u'\u0422\u0435\u0441\u0442']) self.assertEqual('\xd2\xe5\xf1\xf2', self.cursor.cursor.query) self.assertEqual(['\xd2\xe5\xf1\xf2'], self.cursor.cursor.args) self.cursor.execute("SELECT * FROM table", [(u'\u0422\u0435\u0441\u0442', )]) self.assertEqual([('\xd2\xe5\xf1\xf2', )], self.cursor.cursor.args) self.cursor.execute("SELECT * FROM table", [[u'\u0422\u0435\u0441\u0442']]) self.assertEqual([['\xd2\xe5\xf1\xf2']], self.cursor.cursor.args) self.cursor.execute("SELECT * FROM table", [{ "value": u'\u0422\u0435\u0441\u0442' }]) self.assertEqual([{ "value": '\xd2\xe5\xf1\xf2' }], self.cursor.cursor.args) def test_cursor_dict_args_encoding(self): self.typeInfo.setEncoding("windows-1251") self.cursor.execute("SELECT * FROM table", {"value": u'\u0422\u0435\u0441\u0442'}) self.assertEqual({"value": '\xd2\xe5\xf1\xf2'}, self.cursor.cursor.args)
class ZopeCursorTests(TestCase): def setUp(self): self.typeInfo = MyTypeInfoStub() zc = ZopeConnection(MyConnectionStub(), self.typeInfo) self.cursor = ZopeCursor(zc.conn.cursor(), zc) def tearDown(self): transaction.abort() def test_cursor_fetchone(self): results = self.cursor.fetchone() expected = converted[0] self.assertEqual(results, expected, 'type conversion was not performed in cursor.fetchone:\n' 'got %r, expected %r' % (results, expected)) def test_cursor_fetchone_no_more_results(self): self.cursor.cursor._raw = [] results = self.cursor.fetchone() expected = None self.assertEqual(results, expected, 'type conversion was not performed in cursor.fetchone:\n' 'got %r, expected %r' % (results, expected)) def test_cursor_fetchmany(self): results = self.cursor.fetchmany() expected = converted[:2] self.assertEqual(results, expected, 'type conversion was not performed in cursor.fetchmany:\n' 'got %r,\n' 'expected %r' % (results, expected)) def test_cursor_fetchall(self): results = self.cursor.fetchall() expected = converted self.assertEqual(results, expected, 'type conversion was not performed in cursor.fetchall:\n' 'got %r,\n' 'expected %r' % (results, expected)) def test_cursor_executemany(self): self.cursor.executemany("SELECT", [("A",), ("B",)]) self.assertEqual("execute", self.cursor.cursor.method) self.assertEqual("SELECT", self.cursor.cursor.query) self.assertEqual([("A",), ("B",)], self.cursor.cursor.args) zc = ZopeConnection(MyConnectionStub2(), self.typeInfo) self.cursor = ZopeCursor(zc.conn.cursor(), zc) self.cursor.executemany("SELECT", [("A",), ("B",)]) self.assertEqual("executemany", self.cursor.cursor.method) self.assertEqual("SELECT", self.cursor.cursor.query) self.assertEqual([("A",), ("B",)], self.cursor.cursor.args) def test_cursor_query_encoding(self): self.cursor.execute(u'\u0422\u0435\u0441\u0442') self.assertEqual('\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82', self.cursor.cursor.query) self.typeInfo.setEncoding("windows-1251") self.cursor.execute(u'\u0422\u0435\u0441\u0442') self.assertEqual('\xd2\xe5\xf1\xf2', self.cursor.cursor.query) def test_cursor_tuple_args_encoding(self): self.typeInfo.setEncoding("windows-1251") self.cursor.execute("SELECT * FROM table", (u'\u0422\u0435\u0441\u0442',)) self.assertEqual(('\xd2\xe5\xf1\xf2',), self.cursor.cursor.args) def test_cursor_list_args_encoding(self): self.typeInfo.setEncoding("windows-1251") self.cursor.execute(u'\u0422\u0435\u0441\u0442', [u'\u0422\u0435\u0441\u0442']) self.assertEqual('\xd2\xe5\xf1\xf2', self.cursor.cursor.query) self.assertEqual(['\xd2\xe5\xf1\xf2'], self.cursor.cursor.args) self.cursor.execute("SELECT * FROM table", [(u'\u0422\u0435\u0441\u0442',)]) self.assertEqual([('\xd2\xe5\xf1\xf2',)], self.cursor.cursor.args) self.cursor.execute("SELECT * FROM table", [[u'\u0422\u0435\u0441\u0442']]) self.assertEqual([['\xd2\xe5\xf1\xf2']], self.cursor.cursor.args) self.cursor.execute("SELECT * FROM table", [{"value": u'\u0422\u0435\u0441\u0442'}]) self.assertEqual([{"value": '\xd2\xe5\xf1\xf2'}], self.cursor.cursor.args) def test_cursor_dict_args_encoding(self): self.typeInfo.setEncoding("windows-1251") self.cursor.execute("SELECT * FROM table", {"value": u'\u0422\u0435\u0441\u0442'}) self.assertEqual({"value": '\xd2\xe5\xf1\xf2'}, self.cursor.cursor.args)
def execute(self, operation, parameters=None): """See IZopeCursor""" try: return ZopeCursor.execute(self, operation, parameters) except psycopg2.Error, error: _handle_psycopg_exception(error)