-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_unicode.py
More file actions
81 lines (73 loc) · 2.67 KB
/
Copy pathtest_unicode.py
File metadata and controls
81 lines (73 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from sqlobject import *
from sqlobject.tests.dbtest import *
########################################
## Unicode columns
########################################
class TestUnicode(SQLObject):
count = IntCol(alternateID=True)
col1 = UnicodeCol(alternateID=True, length=100)
col2 = UnicodeCol(dbEncoding='latin1')
data = [u'\u00f0', u'test', 'ascii test']
items = []
def setup():
global items
items = []
setupClass(TestUnicode)
if TestUnicode._connection.dbName == 'postgres':
TestUnicode._connection.query('SET client_encoding TO latin1')
for i, s in enumerate(data):
items.append(TestUnicode(count=i, col1=s, col2=s))
def test_create():
setup()
for s, item in zip(data, items):
assert item.col1 == s
assert item.col2 == s
conn = TestUnicode._connection
rows = conn.queryAll("""
SELECT count, col1, col2
FROM test_unicode
ORDER BY count
""")
for count, col1, col2 in rows:
assert data[count].encode('utf-8') == col1
assert data[count].encode('latin1') == col2
def test_select():
setup()
for i, value in enumerate(data):
rows = list(TestUnicode.select(TestUnicode.q.col1 == value))
assert len(rows) == 1
rows = list(TestUnicode.select(TestUnicode.q.col2 == value))
assert len(rows) == 1
rows = list(TestUnicode.select(AND(
TestUnicode.q.col1 == value,
TestUnicode.q.col2 == value
)))
assert len(rows) == 1
rows = list(TestUnicode.selectBy(col1=value))
assert len(rows) == 1
rows = list(TestUnicode.selectBy(col2=value))
assert len(rows) == 1
rows = list(TestUnicode.selectBy(col1=value, col2=value))
assert len(rows) == 1
row = TestUnicode.byCol1(value)
assert row.count == i
rows = list(TestUnicode.select(OR(
TestUnicode.q.col1 == u'\u00f0',
TestUnicode.q.col2 == u'test'
)))
assert len(rows) == 2
rows = list(TestUnicode.selectBy(col1=u'\u00f0', col2=u'test'))
assert len(rows) == 0
# starts/endswith/contains
rows = list(TestUnicode.select(TestUnicode.q.col1.startswith("test")))
assert len(rows) == 1
rows = list(TestUnicode.select(TestUnicode.q.col1.endswith("test")))
assert len(rows) == 2
rows = list(TestUnicode.select(TestUnicode.q.col1.contains("test")))
assert len(rows) == 2
rows = list(TestUnicode.select(TestUnicode.q.col1.startswith(u"\u00f0")))
assert len(rows) == 1
rows = list(TestUnicode.select(TestUnicode.q.col1.endswith(u"\u00f0")))
assert len(rows) == 1
rows = list(TestUnicode.select(TestUnicode.q.col1.contains(u"\u00f0")))
assert len(rows) == 1