Now the tests are using the unittest module.
[philipp/winterrodeln/wrpylib.git] / tests / test_sqlalchemy.py
1 #!/usr/bin/python2.7
2 # -*- coding: iso-8859-15 -*-
3 import types
4 from sqlalchemy import schema
5 from sqlalchemy.engine import create_engine
6 from sqlalchemy.sql import select
7 from wrpylib import mwdb
8 import unittest
9
10
11 def connect():
12     engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=1')
13     # engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0')
14     connection = engine.connect()
15     transaction = connection.begin()
16     return connection
17
18
19 class TestSqlAlchemy(unittest.TestCase):
20     def test_datatype_page(self):
21         metadata = schema.MetaData()
22         tpage = mwdb.page_table(metadata)
23         page = connect().execute(select([tpage], tpage.c.page_id == 1321)).first()
24         assert type(page.page_title) == types.UnicodeType
25         assert type(page.page_restrictions) == types.StringType
26         assert type(page.page_touched) == types.UnicodeType
27
28
29     def test_datatype_revision(self):
30         metadata = schema.MetaData()
31         trevision = mwdb.revision_table(metadata)
32         revision = connect().execute(select([trevision], trevision.c.rev_id == 7586)).first()
33         assert type(revision.rev_comment) == types.UnicodeType
34         assert type(revision.rev_user_text) == types.UnicodeType
35         assert type(revision.rev_timestamp) == types.UnicodeType
36
37
38     def test_datatypes_text(self):
39         metadata = schema.MetaData()
40         ttext = mwdb.text_table(metadata)
41         text = connect().execute(select([ttext], ttext.c.old_id==7438)).first()
42         assert type(text.old_text) == types.UnicodeType
43         assert type(text.old_flags) == types.UnicodeType
44         assert text.old_flags == u'utf-8'
45
46
47     def test_datatype_user(self):
48         metadata = schema.MetaData()
49         tuser = mwdb.user_table(metadata)
50         user = connect().execute(select([tuser], tuser.c.user_id == 1)).first()
51         assert type(user.user_name) == types.UnicodeType
52         assert type(user.user_real_name) == types.UnicodeType
53         assert type(user.user_email) == types.UnicodeType
54         assert user.user_name == u'Philipp'
55
56
57     def test_datatype_categorylinks(self):
58         metadata = schema.MetaData()
59         tcategorylinks = mwdb.categorylinks_table(metadata)
60         categorylinks = connect().execute(select([tcategorylinks], tcategorylinks.c.cl_from == 609)).first()
61         assert type(categorylinks.cl_to) == types.UnicodeType
62         assert type(categorylinks.cl_sortkey) == types.UnicodeType
63         assert categorylinks.cl_sortkey == u'ALT BĂ„RNBAD'
64