test_postgresql.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # ============================================================================
  2. # This file is part of Pwman3.
  3. #
  4. # Pwman3 is free software; you can redistribute iut and/or modify
  5. # it under the terms of the GNU General Public License, version 2
  6. # as published by the Free Software Foundation;
  7. #
  8. # Pwman3 is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with Pwman3; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. # ============================================================================
  17. # Copyright (C) 2015 Oz Nahum Tiram <nahumoz@gmail.com>
  18. # ============================================================================
  19. import os
  20. import unittest
  21. import sys
  22. from pwman.data.drivers.postgresql import PostgresqlDatabase
  23. from pwman.data.nodes import Node
  24. from pwman.util.crypto_engine import CryptoEngine
  25. from .test_crypto_engine import give_key, DummyCallback
  26. import psycopg2 as pg
  27. class TestPostGresql(unittest.TestCase):
  28. @classmethod
  29. def setUpClass(self):
  30. secret = open('secret.txt').readline().strip()
  31. u = "postgresql://oz123:%s@localhost/pwman" % secret
  32. self.db = PostgresqlDatabase(u)
  33. self.db._open()
  34. @classmethod
  35. def tearDownClass(self):
  36. self.db._cur.execute("TRUNCATE DBVERSION")
  37. self.db._cur.execute("TRUNCATE NODE")
  38. def test_1_con(self):
  39. self.assertIsInstance(self.db._cur, pg._psycopg.cursor)
  40. def test_2_create_tables(self):
  41. self.db._create_tables()
  42. if __name__ == '__main__':
  43. ce = CryptoEngine.get()
  44. ce.callback = DummyCallback()
  45. ce.changepassword(reader=give_key)
  46. unittest.main(verbosity=2, failfast=True)