|
|
|
|
@@ -15,6 +15,12 @@ from corelibs.check_handling.regex_constants import (
|
|
|
|
|
DOMAIN_WITH_LOCALHOST_REGEX,
|
|
|
|
|
DOMAIN_WITH_LOCALHOST_PORT_REGEX,
|
|
|
|
|
DOMAIN_REGEX,
|
|
|
|
|
COMPILED_EMAIL_BASIC_REGEX,
|
|
|
|
|
COMPILED_NAME_EMAIL_SIMPLE_REGEX,
|
|
|
|
|
COMPILED_NAME_EMAIL_BASIC_REGEX,
|
|
|
|
|
COMPILED_DOMAIN_WITH_LOCALHOST_REGEX,
|
|
|
|
|
COMPILED_DOMAIN_WITH_LOCALHOST_PORT_REGEX,
|
|
|
|
|
COMPILED_DOMAIN_REGEX,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -51,7 +57,7 @@ class TestEmailBasicRegex:
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def email_pattern(self) -> re.Pattern[str]:
|
|
|
|
|
"""Fixture that returns compiled email regex pattern."""
|
|
|
|
|
return compile_re(EMAIL_BASIC_REGEX)
|
|
|
|
|
return COMPILED_EMAIL_BASIC_REGEX
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("valid_email", [
|
|
|
|
|
"user@example.com",
|
|
|
|
|
@@ -192,7 +198,7 @@ class TestNameEmailSimpleRegex:
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def name_email_simple_pattern(self) -> re.Pattern[str]:
|
|
|
|
|
"""Fixture that returns compiled name+email simple regex pattern."""
|
|
|
|
|
return compile_re(NAME_EMAIL_SIMPLE_REGEX)
|
|
|
|
|
return COMPILED_NAME_EMAIL_SIMPLE_REGEX
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("test_input,expected_groups", [
|
|
|
|
|
('"John Doe" <john@example.com>', {'name1': 'John Doe', 'email1': 'john@example.com'}),
|
|
|
|
|
@@ -284,7 +290,7 @@ class TestNameEmailBasicRegex:
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def name_email_basic_pattern(self) -> re.Pattern[str]:
|
|
|
|
|
"""Fixture that returns compiled name+email basic regex pattern."""
|
|
|
|
|
return compile_re(NAME_EMAIL_BASIC_REGEX)
|
|
|
|
|
return COMPILED_NAME_EMAIL_BASIC_REGEX
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("test_input,expected_name,expected_email", [
|
|
|
|
|
('"John Doe" <john@example.com>', 'John Doe', 'john@example.com'),
|
|
|
|
|
@@ -391,7 +397,7 @@ class TestDomainWithLocalhostRegex:
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def domain_localhost_pattern(self) -> re.Pattern[str]:
|
|
|
|
|
"""Fixture that returns compiled domain with localhost regex pattern."""
|
|
|
|
|
return compile_re(DOMAIN_WITH_LOCALHOST_REGEX)
|
|
|
|
|
return COMPILED_DOMAIN_WITH_LOCALHOST_REGEX
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("valid_domain", [
|
|
|
|
|
"localhost",
|
|
|
|
|
@@ -443,7 +449,7 @@ class TestDomainWithLocalhostPortRegex:
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def domain_localhost_port_pattern(self) -> re.Pattern[str]:
|
|
|
|
|
"""Fixture that returns compiled domain and localhost with port pattern."""
|
|
|
|
|
return compile_re(DOMAIN_WITH_LOCALHOST_PORT_REGEX)
|
|
|
|
|
return COMPILED_DOMAIN_WITH_LOCALHOST_PORT_REGEX
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("valid_domain", [
|
|
|
|
|
"localhost",
|
|
|
|
|
@@ -509,7 +515,7 @@ class TestDomainRegex:
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def domain_pattern(self) -> re.Pattern[str]:
|
|
|
|
|
"""Fixture that returns compiled domain regex pattern."""
|
|
|
|
|
return compile_re(DOMAIN_REGEX)
|
|
|
|
|
return COMPILED_DOMAIN_REGEX
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("valid_domain", [
|
|
|
|
|
"example.com",
|
|
|
|
|
@@ -568,6 +574,8 @@ class TestRegexPatternConsistency:
|
|
|
|
|
"""Test that all regex patterns can be compiled without errors."""
|
|
|
|
|
patterns = [
|
|
|
|
|
EMAIL_BASIC_REGEX,
|
|
|
|
|
NAME_EMAIL_SIMPLE_REGEX,
|
|
|
|
|
NAME_EMAIL_BASIC_REGEX,
|
|
|
|
|
DOMAIN_WITH_LOCALHOST_REGEX,
|
|
|
|
|
DOMAIN_WITH_LOCALHOST_PORT_REGEX,
|
|
|
|
|
DOMAIN_REGEX,
|
|
|
|
|
@@ -576,9 +584,24 @@ class TestRegexPatternConsistency:
|
|
|
|
|
compiled = compile_re(pattern)
|
|
|
|
|
assert isinstance(compiled, re.Pattern)
|
|
|
|
|
|
|
|
|
|
def test_compiled_patterns_are_patterns(self) -> None:
|
|
|
|
|
"""Test that all COMPILED_ constants are Pattern objects."""
|
|
|
|
|
compiled_patterns = [
|
|
|
|
|
COMPILED_EMAIL_BASIC_REGEX,
|
|
|
|
|
COMPILED_NAME_EMAIL_SIMPLE_REGEX,
|
|
|
|
|
COMPILED_NAME_EMAIL_BASIC_REGEX,
|
|
|
|
|
COMPILED_DOMAIN_WITH_LOCALHOST_REGEX,
|
|
|
|
|
COMPILED_DOMAIN_WITH_LOCALHOST_PORT_REGEX,
|
|
|
|
|
COMPILED_DOMAIN_REGEX,
|
|
|
|
|
]
|
|
|
|
|
for pattern in compiled_patterns:
|
|
|
|
|
assert isinstance(pattern, re.Pattern)
|
|
|
|
|
|
|
|
|
|
def test_domain_patterns_are_strings(self) -> None:
|
|
|
|
|
"""Test that all regex constants are strings."""
|
|
|
|
|
assert isinstance(EMAIL_BASIC_REGEX, str)
|
|
|
|
|
assert isinstance(NAME_EMAIL_SIMPLE_REGEX, str)
|
|
|
|
|
assert isinstance(NAME_EMAIL_BASIC_REGEX, str)
|
|
|
|
|
assert isinstance(DOMAIN_WITH_LOCALHOST_REGEX, str)
|
|
|
|
|
assert isinstance(DOMAIN_WITH_LOCALHOST_PORT_REGEX, str)
|
|
|
|
|
assert isinstance(DOMAIN_REGEX, str)
|
|
|
|
|
@@ -587,8 +610,8 @@ class TestRegexPatternConsistency:
|
|
|
|
|
"""Test that domain patterns follow expected hierarchy."""
|
|
|
|
|
# DOMAIN_WITH_LOCALHOST_PORT_REGEX should accept everything
|
|
|
|
|
# DOMAIN_WITH_LOCALHOST_REGEX accepts
|
|
|
|
|
domain_localhost = compile_re(DOMAIN_WITH_LOCALHOST_REGEX)
|
|
|
|
|
domain_localhost_port = compile_re(DOMAIN_WITH_LOCALHOST_PORT_REGEX)
|
|
|
|
|
domain_localhost = COMPILED_DOMAIN_WITH_LOCALHOST_REGEX
|
|
|
|
|
domain_localhost_port = COMPILED_DOMAIN_WITH_LOCALHOST_PORT_REGEX
|
|
|
|
|
|
|
|
|
|
test_cases = ["example.com", "subdomain.example.com", "localhost"]
|
|
|
|
|
for test_case in test_cases:
|
|
|
|
|
|