Skip to content

Commit

Permalink
Move error checking to outer function
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaholic committed Jan 11, 2020
1 parent 8c2c835 commit 40d8c17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 6 additions & 5 deletions server/geoip_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ async def check_update_geoip_db(self) -> None:
"""
Check if the geoip database is old and update it if so.
"""
if not config.GEO_IP_LICENSE_KEY:
self._logger.warning(
"GEO_IP_LICENSE_KEY not set! Unable to download GeoIP database!"
)
return

self._logger.debug("Checking if geoip database needs updating")
try:
Expand Down Expand Up @@ -71,11 +76,7 @@ async def download_geoip_db(self) -> None:
Download the geoip database to a file. If the downloaded file is not
a valid gzip file, then it does NOT overwrite the old file.
"""
if not config.GEO_IP_LICENSE_KEY:
self._logger.warning(
"GEO_IP_LICENSE_KEY not set! Unable to download GeoIP database!"
)
return
assert config.GEO_IP_LICENSE_KEY is not None

self._logger.info("Downloading new geoip database")

Expand Down
3 changes: 3 additions & 0 deletions tests/unit_tests/test_geoip_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ async def test_check_update(fake_geoip_service, fake_geoip_path):
# Set the modified time to unixtime 0
with open(fake_geoip_path, 'a'):
os.utime(fake_geoip_path, (0, 0))

server.config.GEO_IP_DATABASE_MAX_AGE_DAYS = 32
server.config.GEO_IP_LICENSE_KEY = "Anything"

fake_geoip_service.load_db = Mock()
fake_geoip_service.download_geoip_db.reset_mock()

Expand Down

0 comments on commit 40d8c17

Please sign in to comment.