[IMP] base_external_dbsource: Refactor & Split by source

* Heavily refactor code for reusability
* Split all sources into independent modules
* Add more test coverage
* Add CRUD methods
* Add iterator execute return to roadmap
This commit is contained in:
Dave Lasley
2016-12-07 18:28:41 -08:00
committed by Sergio Teruel
parent c6a9bd39f7
commit fff4e0f1bd
15 changed files with 391 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# -*- encoding: utf-8 -*-
from . import test_base_external_dbsource

View File

@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
import mock
from odoo.tests import common
ADAPTER = ('odoo.addons.base_external_dbsource_sqlite.models'
'.base_external_dbsource.sqlalchemy')
class TestBaseExternalDbsource(common.TransactionCase):
def setUp(self):
super(TestBaseExternalDbsource, self).setUp()
self.dbsource = self.env.ref(
'base_external_dbsource_sqlite.demo_sqlite',
)
def test_connection_close_sqlite(self):
""" It should close the connection """
connection = mock.MagicMock()
res = self.dbsource.connection_close_sqlite(connection)
self.assertEqual(res, connection.close())
def test_connection_open_sqlite(self):
""" It should call SQLAlchemy open """
with mock.patch.object(
self.dbsource, '_connection_open_sqlalchemy'
) as parent_method:
self.dbsource.connection_open_sqlite()
parent_method.assert_called_once_with()
def test_excecute_sqlite(self):
""" It should pass args to SQLAlchemy execute """
expect = 'sqlquery', 'sqlparams', 'metadata'
with mock.patch.object(
self.dbsource, '_execute_sqlalchemy'
) as parent_method:
self.dbsource.execute_sqlite(*expect)
parent_method.assert_called_once_with(*expect)