test_postgresql.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. def test_con(self):
  38. self.assertIsInstance(self.db._cur, pg._psycopg.cursor)
  39. if __name__ == '__main__':
  40. ce = CryptoEngine.get()
  41. ce.callback = DummyCallback()
  42. ce.changepassword(reader=give_key)
  43. unittest.main(verbosity=2, failfast=True)