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.
13 db = MySQLdb.connect(db='philipp_winterrodeln_wiki', charset='utf8', use_unicode=True)
14 # db = MySQLdb.connect(db='philipp_winterrodeln_wiki', charset='utf8', use_unicode=False)
17 row = cursor.fetchone()
21 class TestMySqlPython(unittest.TestCase):
22 def test_datatype_page(self):
23 result = exec_sql('select page_title, page_restrictions, page_touched from page where page_id = 1321')
24 assert type(result[0]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
25 assert type(result[1]) == bytes # tinyblob NOT NULL
26 assert type(result[2]) == bytes # binary(14) NOT NULL
29 def test_datatype_revision(self):
30 result = exec_sql('select rev_comment, rev_user_text, rev_timestamp from revision where rev_id = 7586')
31 assert type(result[0]) == bytes # tinyblob NOT NULL
32 assert type(result[1]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
33 assert type(result[2]) == bytes # binary(14) NOT NULL
36 def test_datatypes_text(self):
37 result = exec_sql('select old_text, old_flags from text where old_id = 7438')
38 assert type(result[0]) == bytes # mediumblob NOT NULL
39 assert type(result[1]) == bytes # tinyblob NOT NULL
42 def test_datatype_user(self):
43 result = exec_sql('select user_name, user_real_name, user_email from user where user_id = 1')
44 assert type(result[0]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
45 assert type(result[1]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
46 assert type(result[2]) == str # tinytext NOT NULL
47 assert result[0] == 'Philipp'
50 def test_datatype_categorylinks(self):
51 result = exec_sql('select cl_to, cl_sortkey from categorylinks where cl_from = 609')
52 assert type(result[0]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
53 assert type(result[1]) == bytes # varbinary(230) NOT NULL