Commit a255821a by William Tisäter

Increase test coverage

parent aa3f4ce4
...@@ -8,9 +8,9 @@ from pygeoip import const ...@@ -8,9 +8,9 @@ from pygeoip import const
from tests.config import COUNTRY_DB_PATH, CORRUPT_DB_PATH from tests.config import COUNTRY_DB_PATH, CORRUPT_DB_PATH
class TestGenerals(unittest.TestCase): class TestGenerals(unittest.TestCase):
def testContructing(self): def setUp(self):
gi = pygeoip.GeoIP(filename=COUNTRY_DB_PATH) self.gi = pygeoip.GeoIP(filename=COUNTRY_DB_PATH)
self.assertEqual(gi._type, 'STANDARD') self.assertEqual(self.gi._type, 'STANDARD')
def testConstLengths(self): def testConstLengths(self):
assert len(const.COUNTRY_CODES) == len(const.COUNTRY_CODES3) assert len(const.COUNTRY_CODES) == len(const.COUNTRY_CODES3)
...@@ -24,10 +24,11 @@ class TestGenerals(unittest.TestCase): ...@@ -24,10 +24,11 @@ class TestGenerals(unittest.TestCase):
@raises(socket.gaierror) @raises(socket.gaierror)
def testFailedLookup(self): def testFailedLookup(self):
gi = pygeoip.GeoIP(filename=COUNTRY_DB_PATH) self.gi.country_code_by_name('google')
gi.country_code_by_name('google')
@raises(socket.error) @raises(socket.error)
def testInvalidAddress(self): def testInvalidAddress(self):
gi = pygeoip.GeoIP(filename=COUNTRY_DB_PATH) self.gi.country_code_by_addr('google.com')
gi.country_code_by_addr('google.com')
def testGetEmptyRecord(self):
self.gi._get_record(0)
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import socket
import unittest import unittest
from nose.tools import raises from nose.tools import raises
...@@ -43,7 +44,7 @@ class TestGeoIPCountryFunctions(unittest.TestCase): ...@@ -43,7 +44,7 @@ class TestGeoIPCountryFunctions(unittest.TestCase):
us_code = self.gi.country_code_by_addr(self.us_ip) us_code = self.gi.country_code_by_addr(self.us_ip)
gb_code = self.gi.country_code_by_addr(self.gb_ip) gb_code = self.gi.country_code_by_addr(self.gb_ip)
ie6_code = self.gi6.country_code_by_addr(self.ie6_ip) ie6_code = self.gi6.country_code_by_addr(self.ie6_ip)
self.assertEqual(us_code, self.us_code) self.assertEqual(us_code, self.us_code)
self.assertEqual(gb_code, self.gb_code) self.assertEqual(gb_code, self.gb_code)
self.assertEqual(ie6_code, self.ie_code) self.assertEqual(ie6_code, self.ie_code)
...@@ -66,6 +67,11 @@ class TestGeoIPCountryFunctions(unittest.TestCase): ...@@ -66,6 +67,11 @@ class TestGeoIPCountryFunctions(unittest.TestCase):
self.assertEqual(gb_name, self.gb_name) self.assertEqual(gb_name, self.gb_name)
self.assertEqual(ie6_name, self.ie_name) self.assertEqual(ie6_name, self.ie_name)
@raises(socket.gaierror)
def testFailedIPv6Lookup(self):
data = self.gi6.country_code_by_name('google')
raise ValueError(data)
@raises(pygeoip.GeoIPError) @raises(pygeoip.GeoIPError)
def testOpen4With6(self): def testOpen4With6(self):
data = self.gi.country_code_by_addr(self.ie6_ip) data = self.gi.country_code_by_addr(self.ie6_ip)
......
...@@ -5,7 +5,11 @@ import pygeoip ...@@ -5,7 +5,11 @@ import pygeoip
from pygeoip import const from pygeoip import const
from tests.config import COUNTRY_DB_PATH from tests.config import COUNTRY_DB_PATH
class TestMemoryCache(unittest.TestCase): class TestMemoryCache(unittest.TestCase):
def testMemoryCache(self): def testMemoryCache(self):
gi = pygeoip.GeoIP(COUNTRY_DB_PATH, flags=const.MEMORY_CACHE, cache=False) gi = pygeoip.GeoIP(COUNTRY_DB_PATH, flags=const.MEMORY_CACHE, cache=False)
self.assertEqual(gi._type, 'MEMORY_CACHE') self.assertEqual(gi._type, 'MEMORY_CACHE')
code = gi.country_code_by_name('dn.se')
self.assertEqual(code, 'SE')
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