from setuptools import setup
setup(name='wrpylib',
- version='0.1.2',
+ version='0.1.3',
description='Winterrodeln Python Library',
author='Philipp Spitzer',
author_email='philipp.spitzer@winterrodeln.org',
--- /dev/null
+#!/usr/bin/python2.7
+# -*- coding: iso-8859-15 -*-
+# 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 types
+
+
+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
+
+
+def test_datatype_page():
+ result = exec_sql('select page_title, page_restrictions, page_touched from page where page_id = 1321')
+ assert type(result[0]) == types.UnicodeType # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ assert type(result[1]) == types.StringType # tinyblob NOT NULL
+ assert type(result[2]) == types.StringType # binary(14) NOT NULL
+
+
+def test_datatype_revision():
+ result = exec_sql('select rev_comment, rev_user_text, rev_timestamp from revision where rev_id = 7586')
+ assert type(result[0]) == types.StringType # tinyblob NOT NULL
+ assert type(result[1]) == types.UnicodeType # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ assert type(result[2]) == types.StringType # binary(14) NOT NULL
+
+
+def test_datatypes_text():
+ result = exec_sql('select old_text, old_flags from text where old_id = 7438')
+ assert type(result[0]) == types.StringType # mediumblob NOT NULL
+ assert type(result[1]) == types.StringType # tinyblob NOT NULL
+
+
+def test_datatype_user():
+ result = exec_sql('select user_name, user_real_name, user_email from user where user_id = 1')
+ assert type(result[0]) == types.UnicodeType # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ assert type(result[1]) == types.UnicodeType # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ assert type(result[2]) == types.UnicodeType # tinytext NOT NULL
+ assert result[0] == u'Philipp'
+
+
+def test_datatype_categorylinks():
+ result = exec_sql('select cl_to, cl_sortkey from categorylinks where cl_from = 609')
+ assert type(result[0]) == types.UnicodeType # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ assert type(result[1]) == types.StringType # varbinary(230) NOT NULL
+
--- /dev/null
+#!/usr/bin/python2.7
+# -*- coding: iso-8859-15 -*-
+import types
+from sqlalchemy import schema
+from sqlalchemy.engine import create_engine
+from sqlalchemy.sql import select
+from wrpylib import mwdb
+
+
+def connect():
+ engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=1')
+ # engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0')
+ connection = engine.connect()
+ transaction = connection.begin()
+ return connection
+
+
+def test_datatype_page():
+ metadata = schema.MetaData()
+ tpage = mwdb.page_table(metadata)
+ page = connect().execute(select([tpage], tpage.c.page_id == 1321)).first()
+ assert type(page.page_title) == types.UnicodeType
+ assert type(page.page_restrictions) == types.StringType
+ assert type(page.page_touched) == types.UnicodeType
+
+
+def test_datatype_revision():
+ metadata = schema.MetaData()
+ trevision = mwdb.revision_table(metadata)
+ revision = connect().execute(select([trevision], trevision.c.rev_id == 7586)).first()
+ assert type(revision.rev_comment) == types.UnicodeType
+ assert type(revision.rev_user_text) == types.UnicodeType
+ assert type(revision.rev_timestamp) == types.UnicodeType
+
+
+def test_datatypes_text():
+ metadata = schema.MetaData()
+ ttext = mwdb.text_table(metadata)
+ text = connect().execute(select([ttext], ttext.c.old_id==7438)).first()
+ assert type(text.old_text) == types.UnicodeType
+ assert type(text.old_flags) == types.UnicodeType
+ assert text.old_flags == u'utf-8'
+
+
+def test_datatype_user():
+ metadata = schema.MetaData()
+ tuser = mwdb.user_table(metadata)
+ user = connect().execute(select([tuser], tuser.c.user_id == 1)).first()
+ assert type(user.user_name) == types.UnicodeType
+ assert type(user.user_real_name) == types.UnicodeType
+ assert type(user.user_email) == types.UnicodeType
+ assert user.user_name == u'Philipp'
+
+
+def test_datatype_categorylinks():
+ metadata = schema.MetaData()
+ tcategorylinks = mwdb.categorylinks_table(metadata)
+ categorylinks = connect().execute(select([tcategorylinks], tcategorylinks.c.cl_from == 609)).first()
+ assert type(categorylinks.cl_to) == types.UnicodeType
+ assert type(categorylinks.cl_sortkey) == types.UnicodeType
+ assert categorylinks.cl_sortkey == u'ALT BÄRNBAD'
+
return Table("page", metadata,
Column("page_id", types.Integer, primary_key=True),
Column("page_namespace", types.Integer, nullable=False),
- Column("page_title", types.Unicode(255), nullable=False),
- Column("page_restrictions", types.Unicode, nullable=False),
+ Column("page_title", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ Column("page_restrictions", types.String, nullable=False), # tinyblob NOT NULL
Column("page_counter", types.Integer, nullable=False),
Column("page_is_redirect", types.Integer, nullable=False),
Column("page_is_new", types.Integer, nullable=False),
Column("page_random", types.Float, nullable=False),
- Column("page_touched", types.Unicode(14), nullable=False),
+ Column("page_touched", types.String(14, convert_unicode='force'), nullable=False), # binary(14) NOT NULL
Column("page_latest", types.Integer, nullable=False),
Column("page_len", types.Integer, nullable=False),
)
Column("rev_id", types.Integer, nullable=False, primary_key=True),
Column("rev_page", types.Integer, nullable=False, primary_key=True),
Column("rev_text_id", types.Integer, nullable=False),
- Column("rev_comment", types.Unicode),
+ Column("rev_comment", types.String(convert_unicode='force'), nullable=False), # tinyblob NOT NULL
Column("rev_user", types.Integer, nullable=False),
- Column("rev_user_text", types.Unicode(255), nullable=False),
- Column("rev_timestamp", types.Unicode(14), nullable=False),
+ Column("rev_user_text", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ Column("rev_timestamp", types.String(14, convert_unicode='force'), nullable=False), # binary(14) NOT NULL
Column("rev_minor_edit", types.Integer, nullable=False),
Column("rev_deleted", types.Integer, nullable=False),
Column("rev_len", types.Integer, nullable=False),
"""
return Table("text", metadata,
Column("old_id", types.Integer, primary_key=True),
- Column("old_text", types.Unicode),
- Column("old_flags", types.Unicode),
+ Column("old_text", types.String(convert_unicode='force')), # mediumblob NOT NULL
+ Column("old_flags", types.String(convert_unicode='force')), # tinyblob NOT NULL
)
"""
return Table('user', metadata,
Column("user_id", types.Integer, primary_key=True),
- Column("user_name", types.Unicode(255), nullable=False),
- Column("user_real_name", types.Unicode(255), nullable=False),
+ Column("user_name", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ Column("user_real_name", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
# "user_password"
# "user_newpassword"
# "user_newpass_time"
- Column("user_email", types.Unicode, nullable=False),
+ Column("user_email", types.Unicode, nullable=False), # tinytext NOT NULL
# "user_touched"
# "user_token"
# "user_email_authenticated"
"""
return Table("categorylinks", metadata,
Column("cl_from", types.Integer, nullable=False, primary_key=True),
- Column("cl_to", types.Unicode(255), nullable=False, primary_key=True),
- Column("cl_sortkey", types.Unicode, nullable=False),
+ Column("cl_to", types.Unicode(255), nullable=False, primary_key=True), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+ Column("cl_sortkey", types.String(convert_unicode='force'), nullable=False), # varbinary(230) NOT NULL
Column("cl_timestamp", types.DateTime, nullable=False),
)
is raised. No other exception type should be raised under normal circumstances.
>>> from sqlalchemy.engine import create_engine
- >>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0')
- >>> # see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
+ >>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=1')
>>> update_wrsledruncache(engine.connect())
"""
metadata = schema.MetaData()
is raised. No other exception type should be raised under normal circumstances.
>>> from sqlalchemy.engine import create_engine
- >>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0')
- >>> # see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
+ >>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=1')
>>> update_wrinncache(engine.connect())
"""
metadata = schema.MetaData()
>>> from sqlalchemy.engine import create_engine
>>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=1')
- >>> # see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
>>> update_wrreportcache(engine.connect())
"""
metadata = schema.MetaData()
is raised. No other exception type should be raised under normal circumstances.
>>> from sqlalchemy.engine import create_engine
- >>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0')
- >>> # or: engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0&passwd=XXXXX')
- >>> # see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
- >>> connection = engine.connect()
- >>> update_wrmapcache(connection)
+ >>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=1')
+ >>> # or: engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=1&passwd=XXXXX')
+ >>> update_wrmapcache(engine.connect())
"""
metadata = schema.MetaData()
page = mwdb.page_table(metadata)