Add # pragma: no cover to defensive code sections in validators and CRUD operations

- Mark unreachable code paths in `validators.py` and `base.py` with `# pragma: no cover` for coverage accuracy.
- Add comments to clarify defensive code's purpose and usage across methods.
This commit is contained in:
2025-11-02 07:42:24 +01:00
parent 30dca45097
commit ccd535cf0e
2 changed files with 15 additions and 8 deletions

View File

@@ -111,11 +111,12 @@ def validate_phone_number(phone: str | None) -> str | None:
raise ValueError('Phone number must start with + or 0 followed by 8-14 digits')
# Additional validation to catch specific invalid cases
if cleaned.count('+') > 1:
# NOTE: These checks are defensive code - the regex pattern above already catches these cases
if cleaned.count('+') > 1: # pragma: no cover
raise ValueError('Phone number can only contain one + symbol at the start')
# Check for any non-digit characters (except the leading +)
if not all(c.isdigit() for c in cleaned[1:]):
if not all(c.isdigit() for c in cleaned[1:]): # pragma: no cover
raise ValueError('Phone number can only contain digits after the prefix')
return cleaned