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.

46 lines
1.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 LasLabs Inc.
  3. import mock
  4. from odoo.tests import common
  5. ADAPTER = ('odoo.addons.base_external_dbsource_odbc.models'
  6. '.base_external_dbsource.pyodbc')
  7. class TestBaseExternalDbsource(common.TransactionCase):
  8. def setUp(self):
  9. super(TestBaseExternalDbsource, self).setUp()
  10. self.dbsource = self.env.ref(
  11. 'base_external_dbsource_odbc.demo_odbc',
  12. )
  13. def test_connection_close_pyodbc(self):
  14. """ It should close the connection """
  15. connection = mock.MagicMock()
  16. res = self.dbsource.connection_close_pyodbc(connection)
  17. self.assertEqual(res, connection.close())
  18. @mock.patch(ADAPTER)
  19. def test_connection_open_pyodbc(self, pyodbc):
  20. """ It should open the connection with the full conn string """
  21. self.dbsource.connection_open_pyodbc()
  22. pyodbc.connect.assert_called_once_with(
  23. self.dbsource.conn_string_full,
  24. )
  25. @mock.patch(ADAPTER)
  26. def test_connection_open_pyodbc_return(self, pyodbc):
  27. """ It should return the newly opened connection """
  28. res = self.dbsource.connection_open_pyodbc()
  29. self.assertEqual(res, pyodbc.connect())
  30. def test_execute_pyodbc(self):
  31. """ It should call the generic execute method w/ proper args """
  32. expect = 'sqlquery', 'sqlparams', 'metadata'
  33. with mock.patch.object(self.dbsource, '_execute_generic') as execute:
  34. self.dbsource.execute_pyodbc(*expect)
  35. execute.assert_called_once_with(*expect)