sqlite3_ds_test.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2011 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. from isc.datasrc import sqlite3_ds
  16. import os
  17. import socket
  18. import unittest
  19. TESTDATA_PATH = os.environ['TESTDATA_PATH'] + os.sep
  20. class TestSqlite3_ds(unittest.TestCase):
  21. def test_zone_exist(self):
  22. # The following file must be non existent and must be non
  23. # "creatable"; the sqlite3 library will try to create a new
  24. # DB file if it doesn't exist, so to test a failure case the
  25. # create operation should also fail. The "nodir", a non
  26. # existent directory, is inserted for this purpose.
  27. nodir = "/nodir/notexist"
  28. self.assertRaises(sqlite3_ds.Sqlite3DSError,
  29. sqlite3_ds.zone_exist, "example.com", nodir)
  30. # Open a broken database file
  31. self.assertRaises(sqlite3_ds.Sqlite3DSError,
  32. sqlite3_ds.zone_exist, "example.com",
  33. TESTDATA_PATH + "brokendb.sqlite3")
  34. self.assertTrue(sqlite3_ds.zone_exist("example.com.",
  35. TESTDATA_PATH + "example.com.sqlite3"))
  36. self.assertFalse(sqlite3_ds.zone_exist("example.org.",
  37. TESTDATA_PATH + "example.com.sqlite3"))
  38. if __name__ == '__main__':
  39. unittest.main()