2 # -*- coding: iso-8859-15 -*-
3 # Note: Many of those tests fail in MySQL_python version 1.2.3 and earlier
4 # because byte strings are returned instead of unicode for columns having
5 # a _bin collation, see https://sourceforge.net/p/mysql-python/bugs/289/
6 # This has been fixed in MySQL_python version 1.2.4.
12 db = MySQLdb.connect(db='philipp_winterrodeln_wiki', charset='utf8', use_unicode=True)
13 # db = MySQLdb.connect(db='philipp_winterrodeln_wiki', charset='utf8', use_unicode=False)
16 row = cursor.fetchone()
20 class TestMySqlPython(unittest.TestCase):
21 def test_datatype_page(self):
22 result = exec_sql('select page_title, page_restrictions, page_touched from page where page_id = 1321')
23 assert type(result[0]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
24 assert type(result[1]) == bytes # tinyblob NOT NULL
25 assert type(result[2]) == bytes # binary(14) NOT NULL
28 def test_datatype_revision(self):
29 result = exec_sql('select rev_comment, rev_user_text, rev_timestamp from revision where rev_id = 7586')
30 assert type(result[0]) == bytes # tinyblob NOT NULL
31 assert type(result[1]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
32 assert type(result[2]) == bytes # binary(14) NOT NULL
35 def test_datatypes_text(self):
36 result = exec_sql('select old_text, old_flags from text where old_id = 7438')
37 assert type(result[0]) == bytes # mediumblob NOT NULL
38 assert type(result[1]) == bytes # tinyblob NOT NULL
41 def test_datatype_user(self):
42 result = exec_sql('select user_name, user_real_name, user_email from user where user_id = 1')
43 assert type(result[0]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
44 assert type(result[1]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
45 assert type(result[2]) == str # tinytext NOT NULL
46 assert result[0] == 'Philipp'
49 def test_datatype_categorylinks(self):
50 result = exec_sql('select cl_to, cl_sortkey from categorylinks where cl_from = 609')
51 assert type(result[0]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
52 assert type(result[1]) == bytes # varbinary(230) NOT NULL