test_database_v0.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from pwman_tstlib import *
  2. initTest(__file__)
  3. import pathlib
  4. from libpwman.database import *
  5. class Test_Database_v0(TestCase):
  6. """Legacy version 0 database format.
  7. """
  8. def test_v0(self):
  9. db = PWManDatabase(filename=pathlib.Path("tests", "test_database_v0.db"),
  10. passphrase="test")
  11. self.assertEqual(db.getCategoryNames(),
  12. sorted([ "testcategory", "testcategory2", "testcategory3" ]))
  13. self.assertEqual(db.getEntryTitles("testcategory"),
  14. sorted([ "testtitle", "foo", "biz" ]))
  15. self.assertEqual(db.getEntryTitles("testcategory2"),
  16. sorted([ "testtitle2" ]))
  17. self.assertEqual(db.getEntryTitles("testcategory3"),
  18. sorted([ "testtitle3" ]))
  19. entry = db.getEntry("testcategory", "testtitle")
  20. self.assertEqual(entry.user, "testuser")
  21. self.assertEqual(entry.pw, "testpassword")
  22. entryBulk = db.getEntryBulk(entry)
  23. self.assertEqual(entryBulk.data, "testbulk")
  24. entry = db.getEntry("testcategory", "foo")
  25. self.assertEqual(entry.user, "bar")
  26. self.assertEqual(entry.pw, "")
  27. entryBulk = db.getEntryBulk(entry)
  28. self.assertIsNone(entryBulk)
  29. entry = db.getEntry("testcategory", "biz")
  30. self.assertEqual(entry.user, "baz")
  31. self.assertEqual(entry.pw, "")
  32. entryBulk = db.getEntryBulk(entry)
  33. self.assertIsNone(entryBulk)
  34. entry = db.getEntry("testcategory2", "testtitle2")
  35. self.assertEqual(entry.user, "testuser2")
  36. self.assertEqual(entry.pw, "testpassword2")
  37. entryBulk = db.getEntryBulk(entry)
  38. self.assertIsNone(entryBulk)
  39. entry = db.getEntry("testcategory3", "testtitle3")
  40. self.assertEqual(entry.user, "testuser3")
  41. self.assertEqual(entry.pw, "")
  42. entryBulk = db.getEntryBulk(entry)
  43. self.assertIsNone(entryBulk)