Skip to content

Commit

Permalink
feat: added two new tests to test extract_img method with nad url & n…
Browse files Browse the repository at this point in the history
…o text
  • Loading branch information
deepak-redsoftware committed Jan 11, 2024
1 parent 5250765 commit ad20287
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ def create_address(self, address):
if country_exists:
doc = frappe.get_doc({
"doctype": "Address",
"address_title": address,
"address_title": address.strip(),
"address_type": "Office",
"address_line1": address,
"address_line1": address.strip(),
"city": city if city != "NULL" else None,
"state": state if state != "NULL" else None,
"country": country,
"pincode": postal_code if postal_code != "NULL" else None,
"is_your_company_address": 0
})
doc.insert()
doc.insert(ignore_permissions=True)
return doc
else:
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,18 @@ def test_extract_text_from_img(self):
for item in text_arr:
key, value = item.split(':', 1)
result_dict[key.lower()] = value.strip()
self.assertEqual(result_dict['first_name'].lower(), 'alex')
self.assertEqual(result_dict['first_name'].lower(), 'alex')

def test_extract_text_from_img_with_wrong_url(self):
'''Test extract_text_from_img method with a wrong image url'''

with self.assertRaises(Exception) as context:
extract_text_from_img("http://example.com/nonexistent.jpg")
self.assertEqual("Failed to fetch image from URL", str(context.exception))

def test_extract_text_from_img__with_no_text(self):
'''Test extract_text_from_img method with an image having no text'''

with self.assertRaises(Exception) as context:
extract_text_from_img('''https://gist.githubusercontent.com/deepak-redsoftware/91bce45c6034ab8f935017c91086dbc8/raw/6b15c7300c19ef7866202045f6d0f8c5d9b9a080/no_text.png''')
self.assertEqual("No information extracted from image. Please try again with a different image", str(context.exception))

0 comments on commit ad20287

Please sign in to comment.