#!/usr/bin/python3.4
import unittest
+import MySQLdb
import sqlalchemy
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import sessionmaker
self.assertEqual(type(categorylinks.cl_to), str)
self.assertEqual(type(categorylinks.cl_sortkey), str)
self.assertEqual(categorylinks.cl_sortkey, 'ALT BÄRNBAD')
+
+
+class TestMySqlPython(unittest.TestCase):
+ """Note: Many of those tests failed in MySQL_python version 1.2.3 and earlier
+ because byte strings are returned instead of unicode for columns having
+ a _bin collation, see https://sourceforge.net/p/mysql-python/bugs/289/
+ This has been fixed in MySQL_python version 1.2.4."""
+ @classmethod
+ def setUpClass(cls):
+ cls.db = MySQLdb.connect(db='philipp_winterrodeln_wiki', charset='utf8', use_unicode=True)
+
+ def setUp(self):
+ self.cursor = self.db.cursor()
+
+ def exec_sql(self, sql):
+ self.cursor.execute(sql)
+ row = self.cursor.fetchone()
+ return row
+
+ def test_datatype_page(self):
+ result = self.exec_sql('select page_title, page_restrictions, page_touched from page where page_id = 1321')
+ assert type(result[0]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ assert type(result[1]) == bytes # tinyblob NOT NULL
+ assert type(result[2]) == bytes # binary(14) NOT NULL
+
+ def test_datatype_revision(self):
+ result = self.exec_sql('select rev_comment, rev_user_text, rev_timestamp from revision where rev_id = 7586')
+ assert type(result[0]) == bytes # tinyblob NOT NULL
+ assert type(result[1]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ assert type(result[2]) == bytes # binary(14) NOT NULL
+
+ def test_datatypes_text(self):
+ result = self.exec_sql('select old_text, old_flags from text where old_id = 7438')
+ assert type(result[0]) == bytes # mediumblob NOT NULL
+ assert type(result[1]) == bytes # tinyblob NOT NULL
+
+ def test_datatype_user(self):
+ result = self.exec_sql('select user_name, user_real_name, user_email from user where user_id = 1')
+ assert type(result[0]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ assert type(result[1]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ assert type(result[2]) == str # tinytext NOT NULL
+ assert result[0] == 'Philipp'
+
+ def test_datatype_categorylinks(self):
+ result = self.exec_sql('select cl_to, cl_sortkey from categorylinks where cl_from = 609')
+ assert type(result[0]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ assert type(result[1]) == bytes # varbinary(230) NOT NULL
+++ /dev/null
-#!/usr/bin/python3.4
-# Note: Many of those tests fail in MySQL_python version 1.2.3 and earlier
-# because byte strings are returned instead of unicode for columns having
-# a _bin collation, see https://sourceforge.net/p/mysql-python/bugs/289/
-# This has been fixed in MySQL_python version 1.2.4.
-import MySQLdb
-import unittest
-
-
-def exec_sql(sql):
- db = MySQLdb.connect(db='philipp_winterrodeln_wiki', charset='utf8', use_unicode=True)
- # db = MySQLdb.connect(db='philipp_winterrodeln_wiki', charset='utf8', use_unicode=False)
- cursor = db.cursor()
- cursor.execute(sql)
- row = cursor.fetchone()
- return row
-
-
-class TestMySqlPython(unittest.TestCase):
- def test_datatype_page(self):
- result = exec_sql('select page_title, page_restrictions, page_touched from page where page_id = 1321')
- assert type(result[0]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
- assert type(result[1]) == bytes # tinyblob NOT NULL
- assert type(result[2]) == bytes # binary(14) NOT NULL
-
-
- def test_datatype_revision(self):
- result = exec_sql('select rev_comment, rev_user_text, rev_timestamp from revision where rev_id = 7586')
- assert type(result[0]) == bytes # tinyblob NOT NULL
- assert type(result[1]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
- assert type(result[2]) == bytes # binary(14) NOT NULL
-
-
- def test_datatypes_text(self):
- result = exec_sql('select old_text, old_flags from text where old_id = 7438')
- assert type(result[0]) == bytes # mediumblob NOT NULL
- assert type(result[1]) == bytes # tinyblob NOT NULL
-
-
- def test_datatype_user(self):
- result = exec_sql('select user_name, user_real_name, user_email from user where user_id = 1')
- assert type(result[0]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
- assert type(result[1]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
- assert type(result[2]) == str # tinytext NOT NULL
- assert result[0] == 'Philipp'
-
-
- def test_datatype_categorylinks(self):
- result = exec_sql('select cl_to, cl_sortkey from categorylinks where cl_from = 609')
- assert type(result[0]) == str # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
- assert type(result[1]) == bytes # varbinary(230) NOT NULL
-