Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pygeoip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pygeoip
Commits
5adde2b8
Commit
5adde2b8
authored
Aug 30, 2012
by
William Tisäter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for IPv6 address to code lookup
parent
e25f8b81
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletions
+15
-1
tests/config.py
+1
-0
tests/test_pygeoip.py
+14
-1
No files found.
tests/config.py
View file @
5adde2b8
...
@@ -3,6 +3,7 @@ import os.path
...
@@ -3,6 +3,7 @@ import os.path
_data_dir
=
"/Users/jennifere/projects/pygeoip/data"
_data_dir
=
"/Users/jennifere/projects/pygeoip/data"
COUNTRY_DB_PATH
=
os
.
path
.
join
(
os
.
path
.
abspath
(
_data_dir
),
'GeoIP.dat'
)
COUNTRY_DB_PATH
=
os
.
path
.
join
(
os
.
path
.
abspath
(
_data_dir
),
'GeoIP.dat'
)
COUNTRY_V6_DB_PATH
=
os
.
path
.
join
(
os
.
path
.
abspath
(
_data_dir
),
'GeoIPv6.dat'
)
ISP_DB_PATH
=
os
.
path
.
join
(
os
.
path
.
abspath
(
_data_dir
),
'GeoIPISP.dat'
)
ISP_DB_PATH
=
os
.
path
.
join
(
os
.
path
.
abspath
(
_data_dir
),
'GeoIPISP.dat'
)
ORG_DB_PATH
=
os
.
path
.
join
(
os
.
path
.
abspath
(
_data_dir
),
'GeoIPOrg.dat'
)
ORG_DB_PATH
=
os
.
path
.
join
(
os
.
path
.
abspath
(
_data_dir
),
'GeoIPOrg.dat'
)
CITY_DB_PATH
=
os
.
path
.
join
(
os
.
path
.
abspath
(
_data_dir
),
'GeoLiteCity.dat'
)
CITY_DB_PATH
=
os
.
path
.
join
(
os
.
path
.
abspath
(
_data_dir
),
'GeoLiteCity.dat'
)
...
...
tests/test_pygeoip.py
View file @
5adde2b8
...
@@ -3,7 +3,7 @@ import unittest
...
@@ -3,7 +3,7 @@ import unittest
import
pygeoip
import
pygeoip
from
.config
import
(
CITY_DB_PATH
,
COUNTRY_DB_PATH
,
ISP_DB_PATH
,
ORG_DB_PATH
,
REGION_DB_PATH
,
_data_dir
)
from
.config
import
(
CITY_DB_PATH
,
COUNTRY_DB_PATH
,
COUNTRY_V6_DB_PATH
,
ISP_DB_PATH
,
ORG_DB_PATH
,
REGION_DB_PATH
,
_data_dir
)
class
BaseGeoIPTestCase
(
unittest
.
TestCase
):
class
BaseGeoIPTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -24,6 +24,13 @@ class BaseGeoIPTestCase(unittest.TestCase):
...
@@ -24,6 +24,13 @@ class BaseGeoIPTestCase(unittest.TestCase):
self
.
us_code3
=
'USA'
self
.
us_code3
=
'USA'
self
.
gb_code3
=
'GBR'
self
.
gb_code3
=
'GBR'
self
.
jp_ipv6
=
'2001:298:ffff:ffff:ffff:ffff:ffff:ffff'
self
.
jp_code
=
'JP'
self
.
ca_ipv6
=
'2620:0:f0::'
self
.
ca_code
=
'CA'
self
.
fr_ipv6
=
'2a02:20f0:abcd::'
self
.
fr_code
=
'FR'
self
.
google_record_data
=
{
'city'
:
'Mountain View'
,
self
.
google_record_data
=
{
'city'
:
'Mountain View'
,
'region_name'
:
'CA'
,
'region_name'
:
'CA'
,
'area_code'
:
650
,
'area_code'
:
650
,
...
@@ -70,6 +77,7 @@ class TestGeoIPCountryFunctions(BaseGeoIPTestCase):
...
@@ -70,6 +77,7 @@ class TestGeoIPCountryFunctions(BaseGeoIPTestCase):
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestGeoIPCountryFunctions
,
self
)
.
setUp
()
super
(
TestGeoIPCountryFunctions
,
self
)
.
setUp
()
self
.
gi
=
pygeoip
.
GeoIP
(
COUNTRY_DB_PATH
)
self
.
gi
=
pygeoip
.
GeoIP
(
COUNTRY_DB_PATH
)
self
.
gi6
=
pygeoip
.
GeoIP
(
COUNTRY_V6_DB_PATH
)
self
.
gic
=
pygeoip
.
GeoIP
(
CITY_DB_PATH
)
self
.
gic
=
pygeoip
.
GeoIP
(
CITY_DB_PATH
)
self
.
gir
=
pygeoip
.
GeoIP
(
REGION_DB_PATH
)
self
.
gir
=
pygeoip
.
GeoIP
(
REGION_DB_PATH
)
...
@@ -87,6 +95,11 @@ class TestGeoIPCountryFunctions(BaseGeoIPTestCase):
...
@@ -87,6 +95,11 @@ class TestGeoIPCountryFunctions(BaseGeoIPTestCase):
self
.
assertEqual
(
self
.
gic
.
country_code_by_addr
(
self
.
gb_ip
),
self
.
gb_code
)
self
.
assertEqual
(
self
.
gic
.
country_code_by_addr
(
self
.
gb_ip
),
self
.
gb_code
)
self
.
assertEqual
(
self
.
gir
.
country_code_by_addr
(
self
.
yahoo_ip
),
self
.
us_code
)
self
.
assertEqual
(
self
.
gir
.
country_code_by_addr
(
self
.
yahoo_ip
),
self
.
us_code
)
def
testCountryCodeByAddrIPv6
(
self
):
self
.
assertEqual
(
self
.
gi6
.
country_code_by_addr
(
self
.
fr_ipv6
),
self
.
fr_code
)
self
.
assertEqual
(
self
.
gi6
.
country_code_by_addr
(
self
.
jp_ipv6
),
self
.
jp_code
)
self
.
assertEqual
(
self
.
gi6
.
country_code_by_addr
(
self
.
ca_ipv6
),
self
.
ca_code
)
def
testCountryNameByName
(
self
):
def
testCountryNameByName
(
self
):
self
.
assertEqual
(
self
.
gi
.
country_name_by_name
(
self
.
us_hostname
),
self
.
us_name
)
self
.
assertEqual
(
self
.
gi
.
country_name_by_name
(
self
.
us_hostname
),
self
.
us_name
)
self
.
assertTrue
(
self
.
gi
.
country_name_by_name
(
self
.
gb_hostname
)
.
startswith
(
self
.
gb_name
))
self
.
assertTrue
(
self
.
gi
.
country_name_by_name
(
self
.
gb_hostname
)
.
startswith
(
self
.
gb_name
))
...
...
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