diff --git a/test.py b/test.py index 07a210c..fb8fa24 100644 --- a/test.py +++ b/test.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import os import unittest import sqlite3 @@ -48,6 +49,35 @@ class SQLiteTest(unittest.TestCase): # I have two plugins working with different names self._request('/') + def test_text_factory(self): + # set text factory to str, unicode (default) would cause + # PrammingError: You must not use 8-bit bytestrings .. exception + self.app.install(sqlite.Plugin(keyword='db2',text_factory=str)) + + @self.app.get('/') + def test(db, db2): + char = 'ööö' + db2.execute("CREATE TABLE todo (id INTEGER PRIMARY KEY, task char(100) NOT NULL)") + db2.execute("INSERT INTO todo (id,task) VALUES ('1',:TEST)", { "TEST": char }) + count = len(db2.execute("SELECT * FROM todo").fetchall()) + self.assertEqual(count, 1) + + self._request('/') + + def test_text_factory_fail(self): + self.app.install(sqlite.Plugin(keyword='db3',text_factory=unicode)) + + @self.app.get('/') + def test(db, db3): + char = 'ööö' + db3.execute("CREATE TABLE todo (id INTEGER PRIMARY KEY, task char(100) NOT NULL)") + try: + db3.execute("INSERT INTO todo (id,task) VALUES ('1',:TEST)", { "TEST": char }) + except sqlite3.ProgrammingError as e: + pass + + self._request('/') + def test_raise_sqlite_integrity_error(self): @self.app.get('/') def test(db):