Improved existing tests for wrpylib.mwdb.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sun, 29 Jan 2017 13:01:13 +0000 (13:01 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sun, 29 Jan 2017 13:01:13 +0000 (13:01 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wrpylib/trunk@2610 7aebc617-e5e2-0310-91dc-80fb5f6d2477

tests/test_mwdb.py

index ec04eb4909a806e30a6147812c428ad1054838ef..ccbda84719d1cffbcd31505e20603b56113f90fd 100644 (file)
@@ -1,26 +1,43 @@
 #!/usr/bin/python3.4
 import unittest
-import wrpylib.mwdb
 import sqlalchemy
+from sqlalchemy.engine import create_engine
+from sqlalchemy.orm import sessionmaker
+import wrpylib.mwdb
 
 
 class TestMwDb(unittest.TestCase):
-    def test_page_table(self):
-        metadata = sqlalchemy.MetaData()
-        page_table = wrpylib.mwdb.page_table(metadata)
+    @classmethod
+    def setUpClass(cls):
+        cls.metadata = sqlalchemy.MetaData()
+        cls.engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=1')
+        cls.Session = sessionmaker(bind=cls.engine)
+
+    def setUp(self):
+        self.session = self.Session()
 
+    def tearDown(self):
+        self.session.rollback()
+
+    def test_page_table(self):
+        Page = wrpylib.mwdb.page_table(self.metadata)
+        page = self.session.query(Page).filter(Page.c.page_id==1321).first()
+        self.assertEqual(page.page_id, 1321)
 
     def test_revision_table(self):
         metadata = sqlalchemy.MetaData()
-        revision_table = wrpylib.mwdb.revision_table(metadata)
-
+        RevisionTable = wrpylib.mwdb.revision_table(metadata)
+        revision_table = self.session.query(RevisionTable).filter(RevisionTable.c.rev_id == 666).first()
+        self.assertEqual(revision_table.rev_id, 666)
 
     def test_text_table(self):
         metadata = sqlalchemy.MetaData()
-        text_table = wrpylib.mwdb.text_table(metadata)
-
+        TextTable = wrpylib.mwdb.text_table(metadata)
+        text_table = self.session.query(TextTable).filter(TextTable.c.old_id == 51).first()
+        self.assertEqual(text_table.old_id, 51)
 
     def test_categorylinks_table(self):
         metadata = sqlalchemy.MetaData()
-        categorylinks_table = wrpylib.mwdb.categorylinks_table(metadata)
-
+        CategorylinksTable = wrpylib.mwdb.categorylinks_table(metadata)
+        categorylinks_table = self.session.query(CategorylinksTable).filter(CategorylinksTable.c.cl_from == 229).first()
+        self.assertEqual(categorylinks_table.cl_from, 229)