diff --git a/.travis.yml b/.travis.yml index 054055cb..2907c8c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,8 @@ addons: apt: packages: - clamav-daemon + - geoip-database + - libgeoip-dev install: - pip install tox-travis coveralls before_script: diff --git a/tests/__init__.py b/tests/__init__.py index cf8a2945..ecb12f18 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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.""" diff --git a/tests/test_locationinfo.py b/tests/test_locationinfo.py new file mode 100644 index 00000000..6d2f990c --- /dev/null +++ b/tests/test_locationinfo.py @@ -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") diff --git a/tox.ini b/tox.ini index 6c36f827..f9a2fd6d 100644 --- a/tox.ini +++ b/tox.ini @@ -11,6 +11,7 @@ deps = pytest-cov miniboa >= 1.0.8 biplist + GeoIP [testenv] usedevelop = true