sqlite: text_factory option tests
This commit is contained in:
parent
39ce9c354c
commit
9dc7eb10dc
30
test.py
30
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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user