Skip to content

Commit 17d662d

Browse files
Ashutosh619-sudoAshutosh619-sudo
andcommitted
Fix: Check none value before length of vendor (#895)
* Fix: Check none value before length of vendor * added test * fixed test --------- Co-authored-by: Ashutosh619-sudo <[email protected]>
1 parent cd7e3ac commit 17d662d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

apps/sage_intacct/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,8 @@ def get_or_create_vendor(self, vendor_name: str, email: str = None, create: bool
11801180
try:
11811181
if create:
11821182
vendor_id = self.sanitize_vendor_name(vendor_name)
1183+
if not vendor_id:
1184+
return None
11831185
if len(vendor_id) > 20:
11841186
vendor_id = vendor_id[:17] + str(random.randint(100, 999))
11851187
created_vendor = self.post_vendor(vendor_id, vendor_name, email)

tests/test_sageintacct/test_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,24 @@ def test_get_or_create_vendor(mocker, db):
13981398
assert vendor.destination_id == 'non exiSting VENDOR iN intacct UsE aLl CaSeS'
13991399

14001400

1401+
def test_get_or_create_vendor_with_none_sanitized_name(mocker, db):
1402+
"""
1403+
Test get or create vendor returns None when sanitize_vendor_name returns None
1404+
"""
1405+
workspace_id = 1
1406+
mocker.patch(
1407+
'sageintacctsdk.apis.Vendors.get',
1408+
return_value={}
1409+
)
1410+
1411+
intacct_credentials = SageIntacctCredential.objects.get(workspace_id=workspace_id)
1412+
sage_intacct_connection = SageIntacctConnector(credentials_object=intacct_credentials, workspace_id=workspace_id)
1413+
1414+
# Test with vendor name that becomes empty after sanitization (only special chars)
1415+
vendor = sage_intacct_connection.get_or_create_vendor('!@#$%^&*()', create=True)
1416+
assert vendor is None
1417+
1418+
14011419
def test_get_or_create_employee(mocker, db):
14021420
"""
14031421
Test get or create employee

0 commit comments

Comments
 (0)