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