updated workflow
This commit is contained in:
10 files changed
+97
-90
No files matched your search
@@ -1,8 +1,8 @@
|
||||
"""
|
||||
Tests for django-nepkit model fields.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from django.db import models
|
||||
from django.core.exceptions import ValidationError
|
||||
from nepali.datetime import nepalidate, nepalidatetime
|
||||
|
||||
@@ -23,7 +23,7 @@ class TestNepaliDateField:
|
||||
"""Test that dates are stored as YYYY-MM-DD strings."""
|
||||
field = NepaliDateField()
|
||||
date_obj = nepalidate(2081, 1, 15)
|
||||
|
||||
|
||||
# get_prep_value should return string format
|
||||
result = field.get_prep_value(date_obj)
|
||||
assert result == "2081-01-15"
|
||||
@@ -32,7 +32,7 @@ class TestNepaliDateField:
|
||||
def test_field_retrieval_as_object(self, nepali_date_sample):
|
||||
"""Test that stored strings are converted to nepalidate objects."""
|
||||
field = NepaliDateField()
|
||||
|
||||
|
||||
# from_db_value should return nepalidate object
|
||||
result = field.from_db_value("2081-01-15", None, None)
|
||||
assert isinstance(result, nepalidate)
|
||||
@@ -43,7 +43,7 @@ class TestNepaliDateField:
|
||||
def test_null_handling(self):
|
||||
"""Test that null values are handled correctly."""
|
||||
field = NepaliDateField(null=True, blank=True)
|
||||
|
||||
|
||||
assert field.get_prep_value(None) is None
|
||||
assert field.from_db_value(None, None, None) is None
|
||||
|
||||
@@ -67,7 +67,7 @@ class TestNepaliDateTimeField:
|
||||
"""Test that datetimes are stored as YYYY-MM-DD HH:MM:SS strings."""
|
||||
field = NepaliDateTimeField()
|
||||
dt_obj = nepalidatetime(2081, 1, 15, 14, 30, 0)
|
||||
|
||||
|
||||
result = field.get_prep_value(dt_obj)
|
||||
assert result == "2081-01-15 14:30:00"
|
||||
assert isinstance(result, str)
|
||||
@@ -75,7 +75,7 @@ class TestNepaliDateTimeField:
|
||||
def test_datetime_retrieval(self):
|
||||
"""Test that stored strings are converted to nepalidatetime objects."""
|
||||
field = NepaliDateTimeField()
|
||||
|
||||
|
||||
result = field.from_db_value("2081-01-15 14:30:00", None, None)
|
||||
assert isinstance(result, nepalidatetime)
|
||||
assert result.year == 2081
|
||||
@@ -89,13 +89,13 @@ class TestNepaliPhoneNumberField:
|
||||
def test_valid_phone_numbers(self):
|
||||
"""Test that valid phone numbers pass validation."""
|
||||
field = NepaliPhoneNumberField()
|
||||
|
||||
|
||||
valid_numbers = [
|
||||
"9841234567", # Mobile
|
||||
"9801234567", # Mobile
|
||||
"014123456", # Landline
|
||||
"014123456", # Landline
|
||||
]
|
||||
|
||||
|
||||
for number in valid_numbers:
|
||||
# Should not raise ValidationError
|
||||
field.run_validators(number)
|
||||
@@ -104,13 +104,13 @@ class TestNepaliPhoneNumberField:
|
||||
def test_invalid_phone_numbers(self):
|
||||
"""Test that invalid phone numbers fail validation."""
|
||||
field = NepaliPhoneNumberField()
|
||||
|
||||
|
||||
invalid_numbers = [
|
||||
"123456789", # Too short
|
||||
"12345678901", # Too long
|
||||
"123456789", # Too short
|
||||
"12345678901", # Too long
|
||||
"abcdefghij", # Non-numeric
|
||||
]
|
||||
|
||||
|
||||
for number in invalid_numbers:
|
||||
with pytest.raises(ValidationError):
|
||||
field.run_validators(number)
|
||||
@@ -122,11 +122,11 @@ class TestLocationFields:
|
||||
def test_province_field_choices(self):
|
||||
"""Test that ProvinceField has correct choices."""
|
||||
field = ProvinceField()
|
||||
|
||||
|
||||
# Should have choices from nepali.locations.provinces
|
||||
assert field.choices is not None
|
||||
assert len(field.choices) > 0
|
||||
|
||||
|
||||
# Check that Koshi Province mapping works
|
||||
choice_names = [choice[0] for choice in field.choices]
|
||||
assert "Koshi Province" in choice_names
|
||||
@@ -134,21 +134,21 @@ class TestLocationFields:
|
||||
def test_district_field_choices(self):
|
||||
"""Test that DistrictField has correct choices."""
|
||||
field = DistrictField()
|
||||
|
||||
|
||||
assert field.choices is not None
|
||||
assert len(field.choices) > 0
|
||||
|
||||
def test_municipality_field_choices(self):
|
||||
"""Test that MunicipalityField has correct choices."""
|
||||
field = MunicipalityField()
|
||||
|
||||
|
||||
assert field.choices is not None
|
||||
assert len(field.choices) > 0
|
||||
|
||||
def test_location_field_language_ne(self):
|
||||
"""Test that location fields respect ne=True for Devanagari."""
|
||||
field = ProvinceField(ne=True)
|
||||
|
||||
|
||||
assert field.ne is True
|
||||
# Choices should include Devanagari names
|
||||
choice_names = [choice[0] for choice in field.choices]
|
||||
@@ -158,5 +158,5 @@ class TestLocationFields:
|
||||
def test_htmx_configuration(self):
|
||||
"""Test that HTMX mode can be enabled."""
|
||||
field = DistrictField(htmx=True)
|
||||
|
||||
|
||||
assert field.htmx is True
|
||||
Reference in new issue
Block a user