Skip to content

Commit

Permalink
Merge pull request #637 from praekeltfoundation/YAL-941-yal-whatsapp-…
Browse files Browse the repository at this point in the history
…bot-prd-2-d-value-error

Yal 941 yal whatsapp bot prd 2 d value error
  • Loading branch information
Buhle79 authored Jul 10, 2023
2 parents 04d2aff + d606128 commit ec2fc41
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
30 changes: 30 additions & 0 deletions yal/tests/test_pleasecallme.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,3 +921,33 @@ async def state_call_not_helpful_try_again_declined_to_update(tester: AppTester)
tester.setup_state("state_call_not_helpful_try_again_declined")
await tester.user_input("Update your info")
tester.assert_state("state_display_preferences")


@pytest.mark.asyncio
async def state_state_specify_msisdn_string_input(tester: AppTester):
tester.setup_state("state_specify_msisdn")
await tester.user_input("277812frog")
tester.assert_state("state_specify_msisdn")
tester.assert_message(
"\n".join(["⚠️ Please type a valid cell phone number.", "Example _081234567_"])
)


@pytest.mark.asyncio
async def state_state_specify_msisdn_invalid_input_with_plus(tester: AppTester):
tester.setup_state("state_specify_msisdn")
await tester.user_input("+2778123456")
tester.assert_state("state_specify_msisdn")
tester.assert_message(
"\n".join(["⚠️ Please type a valid cell phone number.", "Example _081234567_"])
)


@pytest.mark.asyncio
async def state_state_specify_msisdn_empty_input(tester: AppTester):
tester.setup_state("state_specify_msisdn")
await tester.user_input(None)
tester.assert_state("state_specify_msisdn")
tester.assert_message(
"\n".join(["⚠️ Please type a valid cell phone number.", "Example _081234567_"])
)
19 changes: 19 additions & 0 deletions yal/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import unittest
from datetime import datetime
from unittest import TestCase

Expand Down Expand Up @@ -122,3 +123,21 @@ def test_is_integer():

obj = 1234
assert utils.is_integer(obj)


class PhoneNumberTest(unittest.TestCase):
def test_normalise_phone_number_is_valid(self):
res = utils.normalise_phonenumber("0781234567")
self.assertEqual(res, "+27781234567")

def test_normalise_phone_number_with_plus(self):
res = utils.normalise_phonenumber("+27781234567")
self.assertEqual(res, "+27781234567")

def test_normalise_phone_number_without_plus(self):
res = utils.normalise_phonenumber("27781234567")
self.assertEqual(res, "+27781234567")

def test_normalise_phone_number_invalid(self):
with self.assertRaises(ValueError):
utils.normalise_phonenumber("2778123456")
11 changes: 7 additions & 4 deletions yal/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ async def validator(value):

def phone_number_validator(error_text):
async def validator(value):
try:
normalise_phonenumber(value)
except ValueError as e:
print(e)
if value:
try:
normalise_phonenumber(value)
except ValueError as e:
print(e)
raise ErrorMessage(error_text)
else:
raise ErrorMessage(error_text)

return validator
Expand Down

0 comments on commit ec2fc41

Please sign in to comment.