Skip to content

Commit

Permalink
[FIX] connector_carepoint: Fix account sequencing
Browse files Browse the repository at this point in the history
* PK for cp_acct is `ID`, but sequence is `acct_id`. Overload create and inject
  • Loading branch information
lasley committed Oct 28, 2016
1 parent 34bd1e4 commit 4902f81
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
10 changes: 10 additions & 0 deletions connector_carepoint/models/carepoint_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ def _get_by_patient(self, patient, create=True, recurse=False):
class CarepointAccountAdapter(CarepointCRUDAdapter):
_model_name = 'carepoint.carepoint.account'

def create(self, data):
""" Wrapper to create a record on the external system
Params:
data: ``dict`` of Data to create record with
Returns:
``str`` of external carepoint_id
"""
data['ID'] = self.carepoint.get_next_sequence('acct_id')
return super(CarepointAccountAdapter, self).create(data)


@carepoint
class CarepointAccountUnit(ConnectorUnit):
Expand Down
23 changes: 22 additions & 1 deletion connector_carepoint/tests/models/test_carepoint_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AccountTestBase(SetUpCarepointBase):

def setUp(self):
super(AccountTestBase, self).setUp()
self.model = 'carepoint.address.abstract'
self.model = 'carepoint.account'
self.mock_env = self.get_carepoint_helper(
self.model
)
Expand Down Expand Up @@ -72,6 +72,27 @@ def test_get_by_patient_recurse(self):
self.assertTrue(len(account))


class TestAccountAdapter(AccountTestBase):

def setUp(self):
super(TestAccountAdapter, self).setUp()
self.Unit = carepoint_account.CarepointAccountAdapter

def _init_model(self):
self.unit = self.Unit(self.mock_env)
self.unit.carepoint_record = self.record
self.unit.connector_env.model._cp_lib = 'account'

def test_create_gets_sequence(self):
""" It should get the sequence for acct_id instead of PK """
with self.mock_api(True) as api:
self._init_model()
self.unit.create({})
api.get_next_sequence.assert_called_once_with(
'acct_id',
)


class TestAccountImportMapper(AccountTestBase):

def setUp(self):
Expand Down

0 comments on commit 4902f81

Please sign in to comment.