Kaydet (Commit) d171843f authored tarafından Alex Stovbur's avatar Alex Stovbur Kaydeden (comit) Tim Graham

Fixed #28981 -- Added an exception if GeoIP database can't be loaded from the path.

üst 84398897
......@@ -92,6 +92,9 @@ class GeoIP2:
if os.path.isfile(city_db):
self._city = geoip2.database.Reader(city_db, mode=cache)
self._city_file = city_db
if not self._reader:
raise GeoIP2Exception('Could not load a database from %s.' % path)
elif os.path.isfile(path):
# Otherwise, some detective work will be needed to figure out
# whether the given database path is for the GeoIP country or city
......
import os
import unittest
from unittest import mock, skipUnless
from django.conf import settings
from django.contrib.gis.geoip2 import HAS_GEOIP2
from django.contrib.gis.geos import GEOSGeometry
from django.test import SimpleTestCase
if HAS_GEOIP2:
from django.contrib.gis.geoip2 import GeoIP2, GeoIP2Exception
......@@ -18,7 +18,7 @@ if HAS_GEOIP2:
HAS_GEOIP2 and getattr(settings, "GEOIP_PATH", None),
"GeoIP is required along with the GEOIP_PATH setting."
)
class GeoIPTest(unittest.TestCase):
class GeoIPTest(SimpleTestCase):
addr = '128.249.1.1'
fqdn = 'tmc.edu'
......@@ -53,6 +53,12 @@ class GeoIPTest(unittest.TestCase):
with self.assertRaises(e):
GeoIP2(bad, 0)
def test_no_database_file(self):
invalid_path = os.path.join(os.path.dirname(__file__), 'data')
msg = 'Could not load a database from %s.' % invalid_path
with self.assertRaisesMessage(GeoIP2Exception, msg):
GeoIP2(invalid_path)
def test02_bad_query(self):
"GeoIP query parameter checking."
cntry_g = GeoIP2(city='<foo>')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment