From 87e9e2196269f96a5829f0b580ff1345449b40a5 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Thu, 27 Oct 2016 17:06:57 -0700 Subject: [PATCH] [FIX] connector_carepoint: Fix account sequencing * PK for cp_acct is `ID`, but sequence is `acct_id`. Overload create and inject --- connector_carepoint/models/carepoint_account.py | 10 ++++++++++ .../tests/models/test_carepoint_account.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/connector_carepoint/models/carepoint_account.py b/connector_carepoint/models/carepoint_account.py index 0d22818..3f98255 100644 --- a/connector_carepoint/models/carepoint_account.py +++ b/connector_carepoint/models/carepoint_account.py @@ -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): diff --git a/connector_carepoint/tests/models/test_carepoint_account.py b/connector_carepoint/tests/models/test_carepoint_account.py index 207e9f7..5ff3cb8 100644 --- a/connector_carepoint/tests/models/test_carepoint_account.py +++ b/connector_carepoint/tests/models/test_carepoint_account.py @@ -72,6 +72,23 @@ 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 + self.unit = self.Unit(self.mock_env) + self.unit.carepoint_record = self.record + + def create_gets_sequence(self): + """ It should get the sequence for acct_id instead of PK """ + with self.mock_api(True) as api: + self.unit.create({}) + api.get_next_sequence.assert_called_once_with( + 'acct_id', + ) + + class TestAccountImportMapper(AccountTestBase): def setUp(self):