Skip to content

Commit

Permalink
bug fix: minor fix for string replacement (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
NileshPant1999 authored May 31, 2023
1 parent bafb51a commit 3b02232
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion netsuitesdk/errors/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@


def replace_numbers(string , replacement1, replacement2, number1, number2):
replaced_string = re.sub(r'\b({}|{})\b'.format(number1, number2), lambda m: replacement1 if m.group() == number1 else replacement2, string)
pattern = r"\b({0}|{1})\b".format(number1, number2)
replaced_string = re.sub(pattern, lambda match: replacement1 if match.group() == str(number1) else replacement2, string)
return replaced_string


Expand Down
1 change: 0 additions & 1 deletion netsuitesdk/errors/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ def export_error_parser(self, error_dict, message):
object_1, object_2 = self.get_entity_values(error_dict)
entity_keys = list(error_dict)
parsed_message = replace_numbers(message, object_1, object_2, error_dict[entity_keys[0]], error_dict[entity_keys[1]])

return parsed_message
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='netsuitesdk',
version='2.18.0',
version='2.18.1',
author='Siva Narayanan',
author_email='[email protected]',
description='Python SDK for accessing the NetSuite SOAP webservice',
Expand Down
6 changes: 3 additions & 3 deletions test/internal/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ def test_export_error_parser(mocker, ns):

mocker.patch(
'netsuitesdk.errors.parser.ErrorParser.get_entity_values',
return_value={'Travel', 'John Doe'}
return_value={ 'Travel', '[email protected]'}
)

parser = ErrorParser(ns)
result = parser.export_error_parser({'expense_category': '1', 'employee': '12'}, 'An error occured in a upsert request: Invalid category reference key 1 for entity 12')
assert result == "An error occured in a upsert request: Invalid category reference key Travel for entity John Doe"
result = parser.export_error_parser({'test': '1', 'employee': '22'}, 'An error occured in a upsert request: Invalid wiered reference key 1 for entity 22')
assert result == "An error occured in a upsert request: Invalid wiered reference key 1 for entity 22"
2 changes: 1 addition & 1 deletion test/internal/test_upsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_failed_expense_report(ns):
record_ref = ns.upsert(expense_report, record_type='expense_report')
logger.debug('record_ref = %s', record_ref)
except NetSuiteRequestError as e:
assert e.message == 'An error occured in a upsert request: Invalid location reference key Honeycomb Mfg. for subsidiary Honeycomb Mfg..'
assert e.message == 'An error occured in a upsert request: Invalid location reference key UK Location for subsidiary Honeycomb Mfg..'
assert e.code == 'INVALID_KEY_OR_REF'

def test_upsert_expense_report(ns):
Expand Down

0 comments on commit 3b02232

Please sign in to comment.