You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp.exceptions import Warning as UserError
  3. from openerp.tests import common
  4. import logging
  5. class TestCreateDbsource(common.TransactionCase):
  6. """Test class for base_external_dbsource."""
  7. def test_create_dbsource(self):
  8. """source creation should succeed."""
  9. dbsource = self.env.ref('base_external_dbsource.demo_postgre')
  10. try:
  11. dbsource.connection_test()
  12. except UserError as e:
  13. logging.warning("Log = " + str(e))
  14. self.assertTrue(u'Everything seems properly set up!' in str(e))
  15. def test_create_dbsource_failed(self):
  16. """source creation without connection string should failed."""
  17. dbsource = self.env.ref('base_external_dbsource.demo_postgre')
  18. # Connection without connection_string
  19. dbsource.conn_string = ""
  20. try:
  21. dbsource.connection_test()
  22. except UserError as e:
  23. logging.warning("Log = " + str(e))
  24. self.assertTrue(u'Here is what we got instead:' in str(e))
  25. def test_create_dbsource_without_connector_failed(self):
  26. """source creation with other connector should failed."""
  27. dbsource = self.env.ref('base_external_dbsource.demo_postgre')
  28. # Connection to mysql
  29. try:
  30. dbsource.connector = "mysql"
  31. dbsource.connection_test()
  32. except ValueError as e:
  33. logging.warning("Log = " + str(e))
  34. self.assertTrue(u'Wrong value for' in str(e))
  35. # Connection to mysql
  36. try:
  37. dbsource.connector = "pyodbc"
  38. dbsource.connection_test()
  39. except ValueError as e:
  40. logging.warning("Log = " + str(e))
  41. self.assertTrue(u'Wrong value for' in str(e))
  42. # Connection to oracle
  43. try:
  44. dbsource.connector = "cx_Oracle"
  45. dbsource.connection_test()
  46. except ValueError as e:
  47. logging.warning("Log = " + str(e))
  48. self.assertTrue(u'Wrong value for' in str(e))