This commit adds a complete test suite for django-nepkit with 62 test cases covering all major components. Test Suite: - 8 test modules covering models, forms, widgets, serializers, filters, validators, and utilities - 62 total test cases with 50 passing and 12 expected failures (xfail) - 67% overall code coverage with 85-100% on core components Test Files Added: - django_nepkit/tests/conftest.py - pytest configuration and shared fixtures - django_nepkit/tests/settings.py - Django settings for test environment - django_nepkit/tests/test_models.py - 15 tests for model fields - django_nepkit/tests/test_forms.py - 6 tests for form validation - django_nepkit/tests/test_validators.py - 7 tests for phone validation - django_nepkit/tests/test_utils.py - 10 tests for date/datetime parsing - django_nepkit/tests/test_serializers.py - 10 tests for DRF serializers - django_nepkit/tests/test_filters.py - 4 tests for DRF filters - django_nepkit/tests/test_widgets.py - 11 tests for widget rendering - django_nepkit/tests/README.md - test documentation Configuration: - pytest.ini - pytest configuration with Django settings module - Makefile - convenience commands for running tests - pyproject.toml - moved pytest and pytest-cov to dev dependencies Coverage Highlights: - validators.py: 100% - forms.py: 91% - conf.py: 93% - serializers.py: 89% - widgets.py: 90% - models.py: 60% Running Tests: DJANGO_SETTINGS_MODULE=django_nepkit.tests.settings uv run pytest django_nepkit/tests/ -v With Coverage: DJANGO_SETTINGS_MODULE=django_nepkit.tests.settings uv run pytest django_nepkit/tests/ --cov=django_nepkit --cov-report=html
63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
"""
|
|
Tests for django-nepkit validators.
|
|
"""
|
|
import pytest
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from django_nepkit.validators import validate_nepali_phone_number
|
|
|
|
|
|
class TestPhoneNumberValidator:
|
|
"""Tests for Nepali phone number validation."""
|
|
|
|
def test_valid_mobile_numbers(self):
|
|
"""Test that valid mobile numbers pass validation."""
|
|
valid_mobiles = [
|
|
"9841234567",
|
|
"9801234567",
|
|
"9851234567",
|
|
"9861234567",
|
|
"9741234567",
|
|
]
|
|
|
|
for number in valid_mobiles:
|
|
# Should not raise ValidationError
|
|
validate_nepali_phone_number(number)
|
|
|
|
def test_valid_landline_numbers(self):
|
|
"""Test that valid landline numbers pass validation."""
|
|
valid_landlines = [
|
|
"014123456",
|
|
"015123456",
|
|
"016123456",
|
|
]
|
|
|
|
for number in valid_landlines:
|
|
# Should not raise ValidationError
|
|
validate_nepali_phone_number(number)
|
|
|
|
def test_invalid_too_short(self):
|
|
"""Test that too short numbers fail validation."""
|
|
with pytest.raises(ValidationError):
|
|
validate_nepali_phone_number("12345")
|
|
|
|
def test_invalid_too_long(self):
|
|
"""Test that too long numbers fail validation."""
|
|
with pytest.raises(ValidationError):
|
|
validate_nepali_phone_number("12345678901")
|
|
|
|
def test_invalid_non_numeric(self):
|
|
"""Test that non-numeric strings fail validation."""
|
|
with pytest.raises(ValidationError):
|
|
validate_nepali_phone_number("abcdefghij")
|
|
|
|
def test_invalid_wrong_prefix(self):
|
|
"""Test that numbers with wrong prefix fail validation."""
|
|
with pytest.raises(ValidationError):
|
|
validate_nepali_phone_number("1234567890")
|
|
|
|
def test_invalid_empty_string(self):
|
|
"""Test that empty string fails validation."""
|
|
with pytest.raises(ValidationError):
|
|
validate_nepali_phone_number("")
|