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
b6d171c6
Commit
b6d171c6
authored
Jul 22, 2013
by
William Tisäter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
100% test coverage
parent
35c88861
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
8 deletions
+61
-8
.gitignore
+2
-0
pygeoip/timezone.py
+4
-7
tests/test.py
+22
-1
tests/test_memory.py
+11
-0
tests/test_mmap.py
+11
-0
tests/test_tz.py
+11
-0
No files found.
.gitignore
View file @
b6d171c6
...
@@ -6,3 +6,5 @@ tests/data/*
...
@@ -6,3 +6,5 @@ tests/data/*
build
build
dist
dist
pygeoip-*
pygeoip-*
cover
.coverage
pygeoip/timezone.py
View file @
b6d171c6
...
@@ -744,17 +744,14 @@ _country = {
...
@@ -744,17 +744,14 @@ _country = {
def
time_zone_by_country_and_region
(
country_code
,
region_name
=
None
):
def
time_zone_by_country_and_region
(
country_code
,
region_name
=
None
):
if
country_code
not
in
_country
:
timezones
=
_country
.
get
(
country_code
)
return
''
if
not
timezones
:
return
None
if
not
region_name
or
region_name
==
'00'
:
region_name
=
None
timezones
=
_country
[
country_code
]
if
isinstance
(
timezones
,
str
):
if
isinstance
(
timezones
,
str
):
return
timezones
return
timezones
if
not
region_name
:
if
not
region_name
:
return
''
return
None
return
timezones
.
get
(
region_name
)
return
timezones
.
get
(
region_name
)
tests/test.py
View file @
b6d171c6
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
socket
import
unittest
import
unittest
from
nose.tools
import
raises
import
pygeoip
from
pygeoip
import
const
from
pygeoip
import
const
from
tests.config
import
COUNTRY_DB_PATH
class
TestGenerals
(
unittest
.
TestCase
):
def
testContructing
(
self
):
gi
=
pygeoip
.
GeoIP
()
self
.
assertEqual
(
gi
,
None
)
gi
=
pygeoip
.
GeoIP
(
filename
=
COUNTRY_DB_PATH
)
self
.
assertEqual
(
gi
.
_type
,
'STANDARD'
)
class
TestSanity
(
unittest
.
TestCase
):
def
testConstLengths
(
self
):
def
testConstLengths
(
self
):
assert
len
(
const
.
COUNTRY_CODES
)
==
len
(
const
.
COUNTRY_CODES3
)
assert
len
(
const
.
COUNTRY_CODES
)
==
len
(
const
.
COUNTRY_CODES3
)
assert
len
(
const
.
COUNTRY_CODES
)
==
len
(
const
.
COUNTRY_NAMES
)
assert
len
(
const
.
COUNTRY_CODES
)
==
len
(
const
.
COUNTRY_NAMES
)
assert
len
(
const
.
COUNTRY_CODES
)
==
len
(
const
.
CONTINENT_NAMES
)
assert
len
(
const
.
COUNTRY_CODES
)
==
len
(
const
.
CONTINENT_NAMES
)
@raises
(
socket
.
gaierror
)
def
testFailedLookup
(
self
):
gi
=
pygeoip
.
GeoIP
(
filename
=
COUNTRY_DB_PATH
)
gi
.
country_code_by_name
(
'google'
)
@raises
(
socket
.
error
)
def
testInvalidAddress
(
self
):
gi
=
pygeoip
.
GeoIP
(
filename
=
COUNTRY_DB_PATH
)
gi
.
country_code_by_addr
(
'google.com'
)
tests/test_memory.py
0 → 100644
View file @
b6d171c6
# -*- coding: utf-8 -*-
import
unittest
import
pygeoip
from
pygeoip
import
const
from
tests.config
import
COUNTRY_DB_PATH
class
TestMemoryCache
(
unittest
.
TestCase
):
def
testMemoryCache
(
self
):
gi
=
pygeoip
.
GeoIP
(
COUNTRY_DB_PATH
,
flags
=
const
.
MEMORY_CACHE
,
cache
=
False
)
self
.
assertEqual
(
gi
.
_type
,
'MEMORY_CACHE'
)
tests/test_mmap.py
0 → 100644
View file @
b6d171c6
# -*- coding: utf-8 -*-
import
unittest
import
pygeoip
from
pygeoip
import
const
from
tests.config
import
COUNTRY_DB_PATH
class
TestMmapCache
(
unittest
.
TestCase
):
def
testMmapCache
(
self
):
gi
=
pygeoip
.
GeoIP
(
COUNTRY_DB_PATH
,
flags
=
const
.
MMAP_CACHE
,
cache
=
False
)
self
.
assertEqual
(
gi
.
_type
,
'MMAP_CACHE'
)
tests/test_tz.py
View file @
b6d171c6
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
import
unittest
import
unittest
import
pygeoip
import
pygeoip
import
pygeoip.timezone
from
tests.config
import
CITY_DB_PATH
from
tests.config
import
CITY_DB_PATH
...
@@ -15,6 +16,16 @@ class TestGeoIPTimeZoneFunctions(unittest.TestCase):
...
@@ -15,6 +16,16 @@ class TestGeoIPTimeZoneFunctions(unittest.TestCase):
self
.
gic
=
pygeoip
.
GeoIP
(
CITY_DB_PATH
)
self
.
gic
=
pygeoip
.
GeoIP
(
CITY_DB_PATH
)
def
testTimeZoneInternals
(
self
):
tz
=
pygeoip
.
timezone
.
time_zone_by_country_and_region
(
'XX'
)
self
.
assertEquals
(
tz
,
None
)
tz
=
pygeoip
.
timezone
.
time_zone_by_country_and_region
(
'US'
,
'NY'
)
self
.
assertEquals
(
tz
,
'America/New_York'
)
tz
=
pygeoip
.
timezone
.
time_zone_by_country_and_region
(
'US'
,
'XX'
)
self
.
assertEquals
(
tz
,
None
)
def
testTimeZoneByAddr
(
self
):
def
testTimeZoneByAddr
(
self
):
us_time_zone
=
self
.
gic
.
time_zone_by_addr
(
self
.
us_ip
)
us_time_zone
=
self
.
gic
.
time_zone_by_addr
(
self
.
us_ip
)
gb_time_zone
=
self
.
gic
.
time_zone_by_addr
(
self
.
gb_ip
)
gb_time_zone
=
self
.
gic
.
time_zone_by_addr
(
self
.
gb_ip
)
...
...
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