Refactor test utilities and enhance ASGI settings

- Cleaned up and standardized assertions in ApiTestMixin for API response validation.
- Updated ASGI settings to use os.environ for setting the DJANGO_SETTINGS_MODULE.
- Removed unused imports and improved formatting in settings.py.
- Refactored URL patterns in urls.py for better readability and organization.
- Enhanced view functions in views.py for consistency and clarity.
- Added .flake8 configuration for linting and style enforcement.
- Introduced type stubs for django-environ to improve type checking with Pylance.
This commit is contained in:
pacnpal
2025-08-20 19:51:59 -04:00
parent 69c07d1381
commit 66ed4347a9
230 changed files with 15094 additions and 11578 deletions

View File

@@ -6,12 +6,12 @@ def normalize_coordinate(value, max_digits, decimal_places):
try:
if value is None:
return None
# Convert to Decimal for precise handling
value = Decimal(str(value))
# Round to exactly 6 decimal places
value = value.quantize(Decimal('0.000001'), rounding=ROUND_DOWN)
value = value.quantize(Decimal("0.000001"), rounding=ROUND_DOWN)
return float(value)
except (TypeError, ValueError, InvalidOperation):
return None
@@ -20,36 +20,36 @@ def normalize_coordinate(value, max_digits, decimal_places):
def get_english_name(tags):
"""Extract English name from OSM tags, falling back to default name"""
# Try name:en first
if 'name:en' in tags:
return tags['name:en']
if "name:en" in tags:
return tags["name:en"]
# Then try int_name (international name)
if 'int_name' in tags:
return tags['int_name']
if "int_name" in tags:
return tags["int_name"]
# Fall back to default name
return tags.get('name')
return tags.get("name")
def normalize_osm_result(result):
"""Normalize OpenStreetMap result to use English names and normalized coordinates"""
# Normalize coordinates
result['lat'] = normalize_coordinate(float(result['lat']), 9, 6)
result['lon'] = normalize_coordinate(float(result['lon']), 10, 6)
result["lat"] = normalize_coordinate(float(result["lat"]), 9, 6)
result["lon"] = normalize_coordinate(float(result["lon"]), 10, 6)
# Get address details
address = result.get('address', {})
address = result.get("address", {})
# Normalize place names to English where possible
if 'namedetails' in result:
if "namedetails" in result:
# For main display name
result['display_name'] = get_english_name(result['namedetails'])
# For address components
if 'city' in address and 'city_tags' in result:
address['city'] = get_english_name(result['city_tags'])
if 'state' in address and 'state_tags' in result:
address['state'] = get_english_name(result['state_tags'])
if 'country' in address and 'country_tags' in result:
address['country'] = get_english_name(result['country_tags'])
result["display_name"] = get_english_name(result["namedetails"])
result['address'] = address
# For address components
if "city" in address and "city_tags" in result:
address["city"] = get_english_name(result["city_tags"])
if "state" in address and "state_tags" in result:
address["state"] = get_english_name(result["state_tags"])
if "country" in address and "country_tags" in result:
address["country"] = get_english_name(result["country_tags"])
result["address"] = address
return result