test_base_ui.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # ============================================================================
  2. # This file is part of Pwman3.
  3. #
  4. # Pwman3 is free software; you can redistribute it 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) 2014 Oz Nahum Tiram <nahumoz@gmail.com>
  18. # ============================================================================
  19. import os
  20. import unittest
  21. from pwman.util.crypto_engine import CryptoEngine
  22. from .test_crypto_engine import give_key, DummyCallback
  23. from pwman.data.database import __DB_FORMAT__
  24. from .test_tools import (SetupTester)
  25. from pwman.data import factory
  26. from StringIO import StringIO
  27. import sys
  28. testdb = os.path.join(os.path.dirname(__file__), "test-baseui.pwman.db")
  29. class TestBaseUI(unittest.TestCase):
  30. def setUp(self):
  31. "test that the right db instance was created"
  32. dbver = __DB_FORMAT__
  33. self.dbtype = 'SQLite'
  34. self.db = factory.create(self.dbtype, dbver, testdb)
  35. self.tester = SetupTester(dbver, testdb)
  36. self.tester.create()
  37. def test_false(self):
  38. self.assertFalse(False)
  39. def test_get_tags(self):
  40. sys.stdin = StringIO("foo bar baz\n")
  41. tags = self.tester.cli._get_tags(reader=lambda: "foo bar baz")
  42. self.assertListEqual(['foo', 'bar', 'baz'], tags)
  43. sys.stdin = sys.__stdin__
  44. def test_do_newn(self):
  45. sys.stdin = StringIO("foo\nbar\nbaz\n")
  46. self.tester.cli.do_newn('')
  47. if __name__ == '__main__':
  48. ce = CryptoEngine.get()
  49. ce.callback = DummyCallback()
  50. ce.changepassword(reader=give_key)
  51. try:
  52. unittest.main(verbosity=2, failfast=True)
  53. except SystemExit:
  54. #os.remove(testdb)
  55. pass