94d40b12a4218d929b1cf60f4039c7b7cbc371fc
[philipp/winterrodeln/wrpylib.git] / tests / test_mwdb.py
1 #!/usr/bin/python3.4
2 import unittest
3 import sqlalchemy
4 from sqlalchemy.engine import create_engine
5 from sqlalchemy.orm import sessionmaker
6 import wrpylib.mwdb
7
8
9 class TestMwDb(unittest.TestCase):
10     @classmethod
11     def setUpClass(cls):
12         cls.engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=1')
13         cls.Session = sessionmaker(bind=cls.engine)
14
15     def setUp(self):
16         self.metadata = sqlalchemy.MetaData()
17         self.session = self.Session()
18
19     def tearDown(self):
20         self.session.rollback()
21
22     def test_page_table(self):
23         Page = wrpylib.mwdb.page_table(self.metadata)
24         page = self.session.query(Page).filter(Page.c.page_id==1321).first()
25         self.assertEqual(page.page_id, 1321)
26         self.assertEqual(type(page.page_title), str)
27         self.assertEqual(type(page.page_restrictions), bytes)
28         self.assertEqual(type(page.page_touched), str)
29
30     def test_revision_table(self):
31         Revision = wrpylib.mwdb.revision_table(self.metadata)
32         revision = self.session.query(Revision).filter(Revision.c.rev_id == 666).first()
33         self.assertEqual(revision.rev_id, 666)
34         self.assertEqual(type(revision.rev_comment), str)
35         self.assertEqual(type(revision.rev_user_text), str)
36         self.assertEqual(type(revision.rev_timestamp), str)
37
38     def test_text_table(self):
39         Text = wrpylib.mwdb.text_table(self.metadata)
40         text = self.session.query(Text).filter(Text.c.old_id == 51).first()
41         self.assertEqual(text.old_id, 51)
42         self.assertEqual(type(text.old_text), str)
43         self.assertEqual(type(text.old_flags), str)
44         self.assertEqual(text.old_flags, 'utf-8')
45
46
47     def test_user_table(self):
48         User = wrpylib.mwdb.user_table(self.metadata)
49         user = self.session.query(User).filter(User.c.user_id == 1).first()
50         self.assertEqual(user.user_id, 1)
51         self.assertEqual(type(user.user_name), str)
52         self.assertEqual(type(user.user_real_name), str)
53         self.assertEqual(type(user.user_email), str)
54         self.assertEqual(user.user_name, 'Philipp')
55
56
57     def test_categorylinks_table(self):
58         Categorylinks = wrpylib.mwdb.categorylinks_table(self.metadata)
59         categorylinks = self.session.query(Categorylinks).filter(Categorylinks.c.cl_from == 609).first()
60         self.assertEqual(categorylinks.cl_from, 609)
61         self.assertEqual(type(categorylinks.cl_to), str)
62         self.assertEqual(type(categorylinks.cl_sortkey), str)
63         self.assertEqual(categorylinks.cl_sortkey, 'ALT BĂ„RNBAD')