-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] connector_carepoint: Abstract address on physician
* Implement abstract address import logic on `medical.physician`
- Loading branch information
Showing
3 changed files
with
177 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
connector_carepoint/tests/models/test_address_physician.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2015-2016 LasLabs Inc. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import mock | ||
|
||
from openerp.addons.connector_carepoint.models import address_physician | ||
|
||
from ...unit.backend_adapter import CarepointCRUDAdapter | ||
|
||
from ..common import SetUpCarepointBase | ||
|
||
|
||
_file = 'openerp.addons.connector_carepoint.models.address_physician' | ||
|
||
|
||
class EndTestException(Exception): | ||
pass | ||
|
||
|
||
class AddressPhysicianTestBase(SetUpCarepointBase): | ||
|
||
def setUp(self): | ||
super(AddressPhysicianTestBase, self).setUp() | ||
self.model = 'carepoint.address.physician' | ||
self.mock_env = self.get_carepoint_helper( | ||
self.model | ||
) | ||
self.record = { | ||
'md_id': 1, | ||
'addr_id': 2, | ||
} | ||
|
||
|
||
class TestAddressPhysicianImportMapper(AddressPhysicianTestBase): | ||
|
||
def setUp(self): | ||
super(TestAddressPhysicianImportMapper, self).setUp() | ||
self.Unit = address_physician.CarepointAddressPhysicianImportMapper | ||
self.unit = self.Unit(self.mock_env) | ||
|
||
def test_partner_id_get_binder(self): | ||
""" It should get binder for physician """ | ||
with mock.patch.object(self.unit, 'binder_for'): | ||
self.unit.binder_for.side_effect = EndTestException | ||
with self.assertRaises(EndTestException): | ||
self.unit.partner_id(self.record) | ||
self.unit.binder_for.assert_called_once_with( | ||
'carepoint.medical.physician' | ||
) | ||
|
||
def test_partner_id_to_odoo(self): | ||
""" It should get Odoo record for physician """ | ||
with mock.patch.object(self.unit, 'binder_for'): | ||
self.unit.binder_for().to_odoo.side_effect = EndTestException | ||
with self.assertRaises(EndTestException): | ||
self.unit.partner_id(self.record) | ||
self.unit.binder_for().to_odoo.assert_called_once_with( | ||
self.record['md_id'], browse=True, | ||
) | ||
|
||
def test_carepoint_id(self): | ||
""" It should return correct attribute """ | ||
res = self.unit.carepoint_id(self.record) | ||
expect = { | ||
'carepoint_id': '%d,%d' % ( | ||
self.record['md_id'], | ||
self.record['addr_id'], | ||
), | ||
} | ||
self.assertDictEqual(expect, res) | ||
|
||
|
||
class TestAddressPhysicianImporter(AddressPhysicianTestBase): | ||
|
||
def setUp(self): | ||
super(TestAddressPhysicianImporter, self).setUp() | ||
self.Unit = address_physician.CarepointAddressPhysicianImporter | ||
self.unit = self.Unit(self.mock_env) | ||
self.unit.carepoint_record = self.record | ||
|
||
@mock.patch('%s.CarepointAddressAbstractImporter' % _file, | ||
spec=address_physician.CarepointAddressAbstractImporter, | ||
) | ||
def test_import_dependencies_super(self, _super): | ||
""" It should call the super """ | ||
_super()._import_dependencies.side_effect = EndTestException | ||
with self.assertRaises(EndTestException): | ||
self.unit._import_dependencies() | ||
|
||
@mock.patch('%s.CarepointAddressAbstractImporter' % _file, | ||
spec=address_physician.CarepointAddressAbstractImporter, | ||
) | ||
def test_import_dependencies_super(self, _super): | ||
""" It should import all dependencies """ | ||
with mock.patch.object(self.unit, '_import_dependency') as mk: | ||
self.unit._import_dependencies() | ||
mk.assert_has_calls([ | ||
mock.call( | ||
self.record['md_id'], | ||
'carepoint.medical.physician', | ||
), | ||
]) | ||
|
||
|
||
class TestCarepointAddressPhysicianUnit(AddressPhysicianTestBase): | ||
|
||
def setUp(self): | ||
super(TestCarepointAddressPhysicianUnit, self).setUp() | ||
self.Unit = address_physician.CarepointAddressPhysicianUnit | ||
self.unit = self.Unit(self.mock_env) | ||
|
||
def test_import_addresses_unit(self): | ||
""" It should get units for adapter and importer """ | ||
with mock.patch.object(self.unit, 'unit_for') as mk: | ||
mk.side_effect = [None, EndTestException] | ||
with self.assertRaises(EndTestException): | ||
self.unit._import_addresses(None, None) | ||
mk.assert_has_calls([ | ||
mock.call(CarepointCRUDAdapter), | ||
mock.call( | ||
address_physician.CarepointAddressPhysicianImporter, | ||
), | ||
]) | ||
|
||
def test_import_addresses_search(self): | ||
""" It should search adapter for filters """ | ||
physician = mock.MagicMock() | ||
with mock.patch.object(self.unit, 'unit_for') as mk: | ||
self.unit._import_addresses(physician, None) | ||
mk().search.assert_called_once_with( | ||
md_id=physician, | ||
) | ||
|
||
def test_import_addresses_import(self): | ||
""" It should run importer on search results """ | ||
expect = mock.MagicMock() | ||
with mock.patch.object(self.unit, 'unit_for') as mk: | ||
mk().search.return_value = [expect] | ||
self.unit._import_addresses(1, None) | ||
mk().run.assert_called_once_with(expect) |