-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added unit tests for methods in AutoInscribe Integration
- Loading branch information
1 parent
bd6110a
commit c8c7f15
Showing
1 changed file
with
28 additions
and
2 deletions.
There are no files selected for viewing
30 changes: 28 additions & 2 deletions
30
autoinscribe/autoinscribe/doctype/autoinscribe_integration/test_autoinscribe_integration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,35 @@ | ||
# Copyright (c) 2024, RedSoft Solutions Pvt. Ltd. and Contributors | ||
# See license.txt | ||
|
||
# import frappe | ||
import frappe | ||
from frappe.tests.utils import FrappeTestCase | ||
from autoinscribe.autoinscribe.doctype.autoinscribe_integration.autoinscribe_integration import extract_text_from_img, create_address | ||
|
||
|
||
class TestAutoInscribeIntegration(FrappeTestCase): | ||
pass | ||
'''Tests methods of AutoInscribe Integration. | ||
Note: Make sure AutoInscribe Settings is having correct values for all fields before testing''' | ||
|
||
def test_create_address_when_country_is_invalid(self): | ||
'''Test create_address method with an invalid value for country''' | ||
|
||
test_address = create_address("NULL") | ||
self.assertEqual(test_address, None) | ||
|
||
def test_create_address_when_country_is_valid(self): | ||
'''Test create_address method with a valid value for country''' | ||
|
||
test_address = create_address("26/C, Electronic City, Hosur Road, Bengaluru, India - 560 100") | ||
address_doc = frappe.get_doc("Address", test_address.name) | ||
self.assertEqual(address_doc.address_title, test_address.address_title) | ||
|
||
def test_extract_text_from_img(self): | ||
'''Test extract_text_from_img method with a dummy business card image''' | ||
|
||
extracted_text = extract_text_from_img('''https://gist.githubusercontent.com/deepak-redsoftware/91bce45c6034ab8f935017c91086dbc8/raw/35f2afb03bb677dc673b413c303881e7c58c76a7/bsc.jpg''') | ||
text_arr = extracted_text.split('\n') | ||
result_dict = {} | ||
for item in text_arr: | ||
key, value = item.split(':', 1) | ||
result_dict[key.lower()] = value.strip() | ||
self.assertEqual(result_dict['first_name'].lower(), 'alex') |