File: test.py

package info (click to toggle)
pygeoip 0.3.2-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 240 kB
  • sloc: python: 1,835; makefile: 3
file content (30 lines) | stat: -rwxr-xr-x 940 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: utf-8 -*-
import socket
import unittest
from nose.tools import raises

import pygeoip
from pygeoip import const
from tests.config import COUNTRY_DB_PATH, CORRUPT_DB_PATH

class TestGenerals(unittest.TestCase):
    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)
        assert len(const.COUNTRY_CODES) == len(const.COUNTRY_NAMES)
        assert len(const.COUNTRY_CODES) == len(const.CONTINENT_NAMES)

    @raises(pygeoip.GeoIPError)
    def testCorruptDatabase(self):
        gi = pygeoip.GeoIP(filename=CORRUPT_DB_PATH)
        gi.country_code_by_name('google.com')

    @raises(socket.error)
    def testInvalidAddress(self):
        self.gi.country_code_by_addr('google.com')

    def testGetEmptyRecord(self):
        self.gi._get_record(0)