Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
d0ed01ce
Kaydet (Commit)
d0ed01ce
authored
Eyl 20, 2015
tarafından
Anton Baklanov
Kaydeden (comit)
Tim Graham
Eyl 23, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #25407 -- Removed network dependency in GeoIP tests.
üst
b1f60460
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
7 deletions
+34
-7
test_geoip.py
tests/gis_tests/test_geoip.py
+24
-4
test_geoip2.py
tests/gis_tests/test_geoip2.py
+10
-3
No files found.
tests/gis_tests/test_geoip.py
Dosyayı görüntüle @
d0ed01ce
...
...
@@ -2,6 +2,7 @@
from
__future__
import
unicode_literals
import
os
import
socket
import
unittest
import
warnings
from
unittest
import
skipUnless
...
...
@@ -32,6 +33,17 @@ class GeoIPTest(unittest.TestCase):
addr
=
'128.249.1.1'
fqdn
=
'tmc.edu'
def
_is_dns_available
(
self
,
domain
):
# Naive check to see if there is DNS available to use.
# Used to conditionally skip fqdn geoip checks.
# See #25407 for details.
ErrClass
=
socket
.
error
if
six
.
PY2
else
OSError
try
:
socket
.
gethostbyname
(
domain
)
return
True
except
ErrClass
:
return
False
def
test01_init
(
self
):
"Testing GeoIP initialization."
g1
=
GeoIP
()
# Everything inferred from GeoIP path
...
...
@@ -76,7 +88,10 @@ class GeoIPTest(unittest.TestCase):
"Testing GeoIP country querying methods."
g
=
GeoIP
(
city
=
'<foo>'
)
for
query
in
(
self
.
fqdn
,
self
.
addr
):
queries
=
[
self
.
addr
]
if
self
.
_is_dns_available
(
self
.
fqdn
):
queries
.
append
(
self
.
fqdn
)
for
query
in
queries
:
for
func
in
(
g
.
country_code
,
g
.
country_code_by_addr
,
g
.
country_code_by_name
):
self
.
assertEqual
(
'US'
,
func
(
query
),
'Failed for func
%
s and query
%
s'
%
(
func
,
query
))
for
func
in
(
g
.
country_name
,
g
.
country_name_by_addr
,
g
.
country_name_by_name
):
...
...
@@ -89,7 +104,10 @@ class GeoIPTest(unittest.TestCase):
"Testing GeoIP city querying methods."
g
=
GeoIP
(
country
=
'<foo>'
)
for
query
in
(
self
.
fqdn
,
self
.
addr
):
queries
=
[
self
.
addr
]
if
self
.
_is_dns_available
(
self
.
fqdn
):
queries
.
append
(
self
.
fqdn
)
for
query
in
queries
:
# Country queries should still work.
for
func
in
(
g
.
country_code
,
g
.
country_code_by_addr
,
g
.
country_code_by_name
):
self
.
assertEqual
(
'US'
,
func
(
query
))
...
...
@@ -116,8 +134,10 @@ class GeoIPTest(unittest.TestCase):
def
test05_unicode_response
(
self
):
"Testing that GeoIP strings are properly encoded, see #16553."
g
=
GeoIP
()
d
=
g
.
city
(
"duesseldorf.de"
)
self
.
assertEqual
(
'Düsseldorf'
,
d
[
'city'
])
fqdn
=
"duesseldorf.de"
if
self
.
_is_dns_available
(
fqdn
):
d
=
g
.
city
(
fqdn
)
self
.
assertEqual
(
'Düsseldorf'
,
d
[
'city'
])
d
=
g
.
country
(
'200.26.205.1'
)
# Some databases have only unaccented countries
self
.
assertIn
(
d
[
'country_name'
],
(
'Curaçao'
,
'Curacao'
))
...
...
tests/gis_tests/test_geoip2.py
Dosyayı görüntüle @
d0ed01ce
...
...
@@ -8,6 +8,7 @@ from unittest import skipUnless
from
django.conf
import
settings
from
django.contrib.gis.geoip2
import
HAS_GEOIP2
from
django.contrib.gis.geos
import
HAS_GEOS
,
GEOSGeometry
from
django.test
import
mock
from
django.utils
import
six
if
HAS_GEOIP2
:
...
...
@@ -64,8 +65,10 @@ class GeoIPTest(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
cntry_g
.
country_code
,
17
)
self
.
assertRaises
(
TypeError
,
cntry_g
.
country_name
,
GeoIP2
)
def
test03_country
(
self
):
@mock.patch
(
'socket.gethostbyname'
)
def
test03_country
(
self
,
gethostbyname
):
"GeoIP country querying methods."
gethostbyname
.
return_value
=
'128.249.1.1'
g
=
GeoIP2
(
city
=
'<foo>'
)
for
query
in
(
self
.
fqdn
,
self
.
addr
):
...
...
@@ -85,8 +88,10 @@ class GeoIPTest(unittest.TestCase):
)
@skipUnless
(
HAS_GEOS
,
"Geos is required"
)
def
test04_city
(
self
):
@mock.patch
(
'socket.gethostbyname'
)
def
test04_city
(
self
,
gethostbyname
):
"GeoIP city querying methods."
gethostbyname
.
return_value
=
'128.249.1.1'
g
=
GeoIP2
(
country
=
'<foo>'
)
for
query
in
(
self
.
fqdn
,
self
.
addr
):
...
...
@@ -121,8 +126,10 @@ class GeoIPTest(unittest.TestCase):
self
.
assertAlmostEqual
(
lon
,
tup
[
0
],
4
)
self
.
assertAlmostEqual
(
lat
,
tup
[
1
],
4
)
def
test05_unicode_response
(
self
):
@mock.patch
(
'socket.gethostbyname'
)
def
test05_unicode_response
(
self
,
gethostbyname
):
"GeoIP strings should be properly encoded (#16553)."
gethostbyname
.
return_value
=
'194.27.42.76'
g
=
GeoIP2
()
d
=
g
.
city
(
"nigde.edu.tr"
)
self
.
assertEqual
(
'Niğde'
,
d
[
'city'
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment