Commit b6d171c6 by William Tisäter

100% test coverage

parent 35c88861
...@@ -6,3 +6,5 @@ tests/data/* ...@@ -6,3 +6,5 @@ tests/data/*
build build
dist dist
pygeoip-* pygeoip-*
cover
.coverage
...@@ -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)
# -*- 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')
# -*- 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')
# -*- 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')
...@@ -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)
......
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