Add a test for the LocationInfo plugin

Because the GeoIP database now requires registration to download the
result of the lookup using geoip-database is not going to change.
This commit is contained in:
Chris Mayo 2020-07-07 17:25:28 +01:00
parent b328520f08
commit 10170b2966
4 changed files with 45 additions and 0 deletions

View file

@ -21,6 +21,8 @@ addons:
apt:
packages:
- clamav-daemon
- geoip-database
- libgeoip-dev
install:
- pip install tox-travis coveralls
before_script:

View file

@ -220,6 +220,16 @@ def has_x11():
need_x11 = _need_func(has_x11, "X11")
@lru_cache(1)
def has_geoip():
from linkcheck.plugins import locationinfo
return locationinfo.geoip is not None
need_geoip = _need_func(has_geoip, "geoip")
@lru_cache(1)
def has_word():
"""Test if Word is available."""

View file

@ -0,0 +1,32 @@
# Copyright (C) 2020 Chris Mayo
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
Test LocationInfo plugin.
Requires GeoIP (libgeoip-dev to build) and geoip-database
"""
import unittest
from linkcheck.plugins import locationinfo
from tests import need_geoip
class TestLocationInfo(unittest.TestCase):
@need_geoip
def test_get_location(self):
location = locationinfo.get_location("8.8.8.8")
self.assertEqual(location, "United States")

View file

@ -11,6 +11,7 @@ deps =
pytest-cov
miniboa >= 1.0.8
biplist
GeoIP
[testenv]
usedevelop = true