test_mysql.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 unittest
  20. import sys
  21. from .test_crypto_engine import give_key, DummyCallback
  22. if sys.version_info.major > 2: # pragma: no cover
  23. from urllib.parse import urlparse
  24. else: # pragma: no cover
  25. from urlparse import urlparse
  26. from pwman.data.drivers.mysql import MySQLDatabase
  27. from pwman.util.crypto_engine import CryptoEngine
  28. class TestMySQLDatabase(unittest.TestCase):
  29. @classmethod
  30. def setUpClass(self):
  31. u = "mysql://pwman:123456@localhost/pwmantest"
  32. u = urlparse(u)
  33. # password required, for all hosts
  34. # u = "postgresql://<user>:<pass>@localhost/pwman"
  35. self.db = MySQLDatabase(u)
  36. self.db._open()
  37. @classmethod
  38. def tearDownClass(self):
  39. self.db._cur.execute("DROP TABLE LOOKUP")
  40. self.db._cur.execute("DROP TABLE TAG")
  41. self.db._cur.execute("DROP TABLE NODE")
  42. self.db._cur.execute("DROP TABLE DBVERSION")
  43. self.db._cur.execute("DROP TABLE CRYPTO")
  44. self.db._con.commit()
  45. if __name__ == '__main__':
  46. ce = CryptoEngine.get()
  47. ce.callback = DummyCallback()
  48. ce.changepassword(reader=give_key)
  49. unittest.main(verbosity=2, failfast=True)