Commit a255821a by William Tisäter

Increase test coverage

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