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 def test_datatype_page():
21 result = exec_sql('select page_title, page_restrictions, page_touched from page where page_id = 1321')
22 assert type(result[0]) == types.UnicodeType # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
23 assert type(result[1]) == types.StringType # tinyblob NOT NULL
24 assert type(result[2]) == types.StringType # binary(14) NOT NULL
27 def test_datatype_revision():
28 result = exec_sql('select rev_comment, rev_user_text, rev_timestamp from revision where rev_id = 7586')
29 assert type(result[0]) == types.StringType # tinyblob NOT NULL
30 assert type(result[1]) == types.UnicodeType # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
31 assert type(result[2]) == types.StringType # binary(14) NOT NULL
34 def test_datatypes_text():
35 result = exec_sql('select old_text, old_flags from text where old_id = 7438')
36 assert type(result[0]) == types.StringType # mediumblob NOT NULL
37 assert type(result[1]) == types.StringType # tinyblob NOT NULL
40 def test_datatype_user():
41 result = exec_sql('select user_name, user_real_name, user_email from user where user_id = 1')
42 assert type(result[0]) == types.UnicodeType # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
43 assert type(result[1]) == types.UnicodeType # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
44 assert type(result[2]) == types.UnicodeType # tinytext NOT NULL
45 assert result[0] == u'Philipp'
48 def test_datatype_categorylinks():
49 result = exec_sql('select cl_to, cl_sortkey from categorylinks where cl_from = 609')
50 assert type(result[0]) == types.UnicodeType # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
51 assert type(result[1]) == types.StringType # varbinary(230) NOT NULL