|
|
@@ -3,8 +3,10 @@ |
|
|
|
from __future__ import unicode_literals |
|
|
|
|
|
|
|
import unittest |
|
|
|
import frappe |
|
|
|
|
|
|
|
from frappe.utils import evaluate_filters, money_in_words, scrub_urls, get_url |
|
|
|
from frappe.utils import validate_url, validate_email_address |
|
|
|
from frappe.utils import ceil, floor |
|
|
|
|
|
|
|
from PIL import Image |
|
|
@@ -54,14 +56,15 @@ class TestMoney(unittest.TestCase): |
|
|
|
|
|
|
|
for num in nums_bhd: |
|
|
|
self.assertEqual( |
|
|
|
money_in_words(num[0], "BHD"), num[1], "{0} is not the same as {1}". |
|
|
|
format(money_in_words(num[0], "BHD"), num[1]) |
|
|
|
money_in_words(num[0], "BHD"), |
|
|
|
num[1], |
|
|
|
"{0} is not the same as {1}".format(money_in_words(num[0], "BHD"), num[1]) |
|
|
|
) |
|
|
|
|
|
|
|
for num in nums_ngn: |
|
|
|
self.assertEqual( |
|
|
|
money_in_words(num[0], "NGN"), num[1], "{0} is not the same as {1}". |
|
|
|
format(money_in_words(num[0], "NGN"), num[1]) |
|
|
|
money_in_words(num[0], "NGN"), num[1], |
|
|
|
"{0} is not the same as {1}".format(money_in_words(num[0], "NGN"), num[1]) |
|
|
|
) |
|
|
|
|
|
|
|
class TestDataManipulation(unittest.TestCase): |
|
|
@@ -93,7 +96,7 @@ class TestDataManipulation(unittest.TestCase): |
|
|
|
class TestMathUtils(unittest.TestCase): |
|
|
|
def test_floor(self): |
|
|
|
from decimal import Decimal |
|
|
|
self.assertEqual(floor(2), 2 ) |
|
|
|
self.assertEqual(floor(2), 2) |
|
|
|
self.assertEqual(floor(12.32904), 12) |
|
|
|
self.assertEqual(floor(22.7330), 22) |
|
|
|
self.assertEqual(floor('24.7'), 24) |
|
|
@@ -102,7 +105,7 @@ class TestMathUtils(unittest.TestCase): |
|
|
|
|
|
|
|
def test_ceil(self): |
|
|
|
from decimal import Decimal |
|
|
|
self.assertEqual(ceil(2), 2 ) |
|
|
|
self.assertEqual(ceil(2), 2) |
|
|
|
self.assertEqual(ceil(12.32904), 13) |
|
|
|
self.assertEqual(ceil(22.7330), 23) |
|
|
|
self.assertEqual(ceil('24.7'), 25) |
|
|
@@ -127,6 +130,44 @@ class TestHTMLUtils(unittest.TestCase): |
|
|
|
self.assertTrue('<h1>Hello</h1>' in clean) |
|
|
|
self.assertTrue('<a href="http://test.com">text</a>' in clean) |
|
|
|
|
|
|
|
class TestValidationUtils(unittest.TestCase): |
|
|
|
def test_valid_url(self): |
|
|
|
# Edge cases |
|
|
|
self.assertFalse(validate_url('')) |
|
|
|
self.assertFalse(validate_url(None)) |
|
|
|
|
|
|
|
# Valid URLs |
|
|
|
self.assertTrue(validate_url('https://google.com')) |
|
|
|
self.assertTrue(validate_url('https://frappe.io', throw=True)) |
|
|
|
|
|
|
|
# Invalid URLs without throw |
|
|
|
self.assertFalse(validate_url('google.io')) |
|
|
|
self.assertFalse(validate_url('google.io')) |
|
|
|
|
|
|
|
# Invalid URL with throw |
|
|
|
self.assertRaises(frappe.ValidationError, validate_url, 'frappe', throw=True) |
|
|
|
|
|
|
|
def test_valid_email(self): |
|
|
|
# Edge cases |
|
|
|
self.assertFalse(validate_email_address('')) |
|
|
|
self.assertFalse(validate_email_address(None)) |
|
|
|
|
|
|
|
# Valid addresses |
|
|
|
self.assertTrue(validate_email_address('someone@frappe.com')) |
|
|
|
self.assertTrue(validate_email_address('someone@frappe.com, anyone@frappe.io')) |
|
|
|
|
|
|
|
# Invalid address |
|
|
|
self.assertFalse(validate_email_address('someone')) |
|
|
|
self.assertFalse(validate_email_address('someone@----.com')) |
|
|
|
|
|
|
|
# Invalid with throw |
|
|
|
self.assertRaises( |
|
|
|
frappe.InvalidEmailAddressError, |
|
|
|
validate_email_address, |
|
|
|
'someone.com', |
|
|
|
throw=True |
|
|
|
) |
|
|
|
|
|
|
|
class TestImage(unittest.TestCase): |
|
|
|
def test_strip_exif_data(self): |
|
|
|
original_image = Image.open("../apps/frappe/frappe/tests/data/exif_sample_image.jpg") |
|
|
|