1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import os
- import unittest
- import sys
- from pwman.data.drivers.postgresql import PostgresqlDatabase
- from pwman.data.nodes import Node
- from pwman.util.crypto_engine import CryptoEngine
- from .test_crypto_engine import give_key, DummyCallback
- import psycopg2 as pg
- class TestPostGresql(unittest.TestCase):
- @classmethod
- def setUpClass(self):
- secret = open('secret.txt').readline().strip()
- u = "postgresql://oz123:%s@localhost/pwman" % secret
- self.db = PostgresqlDatabase(u)
- self.db._open()
- @classmethod
- def tearDownClass(self):
- self.db._cur.execute("DROP TABLE LOOKUP")
- self.db._cur.execute("DROP TABLE TAG")
- self.db._cur.execute("DROP TABLE NODE")
- self.db._cur.execute("DROP TABLE DBVERSION")
- self.db._cur.execute("DROP TABLE CRYPTO")
- self.db._con.commit()
- def test_1_con(self):
- self.assertIsInstance(self.db._cur, pg._psycopg.cursor)
- def test_2_create_tables(self):
- self.db._create_tables()
-
- self.db._create_tables()
- def test_3_load_key(self):
- self.db.savekey('SECRET$6$KEY')
- secretkey = self.db.loadkey()
- self.assertEqual(secretkey, 'SECRET$6$KEY')
- def test_4_save_crypto(self):
- self.db.save_crypto_info("TOP", "SECRET")
- secretkey = self.db.loadkey()
- self.assertEqual(secretkey, 'TOP$6$SECRET')
- row = self.db.fetch_crypto_info()
- self.assertEqual(row, ('TOP', 'SECRET'))
- def test_5_add_node(self):
- self.db.add_node(("TBONE", "S3K43T", "example.org", "some note"))
- if __name__ == '__main__':
- ce = CryptoEngine.get()
- ce.callback = DummyCallback()
- ce.changepassword(reader=give_key)
- unittest.main(verbosity=2, failfast=True)
|