Skip to content

Commit

Permalink
[FIX] connector_carepoint: Fix days unit handling
Browse files Browse the repository at this point in the history
* Parse day units to correct pint format
* Add test case specific to reported error
  • Loading branch information
lasley committed Aug 28, 2016
1 parent 76d0126 commit df29314
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
22 changes: 18 additions & 4 deletions connector_carepoint/models/fdb_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ def _uom_category_id(self, unit_root_str):
@only_create
def uom_id(self, record):

str60 = record['str60'].strip()
match = re.search(r'(?P<unit>\d+)cc', str60, re.IGNORECASE)
if match:
str60 = '%s cc' % match.group('unit')
str60 = self._parse_str60(record['str60'])

unit_base = ureg(str60)
unit_base_str = str(unit_base.u)
Expand Down Expand Up @@ -150,6 +147,23 @@ def uom_id(self, record):
})
return vals

def _parse_str60(self, str60):
""" It parses the str60 to fix edge cases """

str60 = str60.strip()

# Handle CCs
match = re.search(r'(?P<unit>\d+)cc', str60, re.IGNORECASE)
if match:
return '%s cc' % match.group('unit')

# Handle daysx
match = re.search(r'daysx(?P<unit>\d+)', str60, re.IGNORECASE)
if match:
return 'days ** %s' % match.group('unit')

return str60

# @mapping
# @only_create
# def unit_id(self, record):
Expand Down
12 changes: 12 additions & 0 deletions connector_carepoint/tests/models/test_fdb_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ def test_uom_id_ureg_cc(self):
'1 cc'
)

def test_uom_id_ureg_days(self):
""" It should have identified and split the days for ureg parse """
record = self.record
record['str60'] = 'daysx3'
with self.mock_pint() as mk:
mk['ureg'].side_effect = EndTestException
with self.assertRaises(EndTestException):
self.unit.uom_id(record)
mk['ureg'].assert_called_once_with(
'days ** 3'
)

def test_uom_id_infer_base_unit(self):
""" It should attempt to infer base of unit """
with self.mock_pint() as mk:
Expand Down

0 comments on commit df29314

Please sign in to comment.