cic-internal-integration/apps/cic-ussd/tests/cic_ussd/test_validator.py

45 lines
1.2 KiB
Python
Raw Normal View History

2021-08-06 18:29:01 +02:00
# standard imports
# external imports
2021-02-06 16:13:47 +01:00
import pytest
# local imports
from cic_ussd.validator import (check_ip,
check_request_content_length,
check_request_method,
2021-08-06 18:29:01 +02:00
is_valid_response,
validate_phone_number)
2021-02-06 16:13:47 +01:00
def test_check_ip(load_config, uwsgi_env):
assert check_ip(config=load_config, env=uwsgi_env) is True
def test_check_request_content_length(load_config, uwsgi_env):
assert check_request_content_length(config=load_config, env=uwsgi_env) is True
def test_check_request_method(uwsgi_env):
assert check_request_method(env=uwsgi_env) is True
@pytest.mark.parametrize('phone, expected_value', [
('653', False),
('+654', False),
('+254112233445', True),
('+254712345678', True)
])
def test_validate_phone_number(phone, expected_value):
assert validate_phone_number(phone=phone) is expected_value
@pytest.mark.parametrize('response, expected_value', [
('CON some random text', True),
('END some more random tests', True),
('Testing', False),
('BIO testing', False)
])
def test_validate_response_type(response, expected_value):
2021-08-06 18:29:01 +02:00
assert is_valid_response(response) is expected_value
2021-02-06 16:13:47 +01:00