e57398b25943058447b433216823c71ff04ad0cc
[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
27     def test_revision_table(self):
28         RevisionTable = wrpylib.mwdb.revision_table(self.metadata)
29         revision_table = self.session.query(RevisionTable).filter(RevisionTable.c.rev_id == 666).first()
30         self.assertEqual(revision_table.rev_id, 666)
31
32     def test_text_table(self):
33         TextTable = wrpylib.mwdb.text_table(self.metadata)
34         text_table = self.session.query(TextTable).filter(TextTable.c.old_id == 51).first()
35         self.assertEqual(text_table.old_id, 51)
36
37     def test_user_table(self):
38         UserTable = wrpylib.mwdb.user_table(self.metadata)
39         user_table = self.session.query(UserTable).filter(UserTable.c.user_id == 5).first()
40         self.assertEqual(user_table.user_id, 5)
41
42     def test_categorylinks_table(self):
43         CategorylinksTable = wrpylib.mwdb.categorylinks_table(self.metadata)
44         categorylinks_table = self.session.query(CategorylinksTable).filter(CategorylinksTable.c.cl_from == 229).first()
45         self.assertEqual(categorylinks_table.cl_from, 229)