Skip to content

Commit

Permalink
Package search failure handling (#1213)
Browse files Browse the repository at this point in the history
* Drop Python36 tests

Python36 support was dropped in 837a47. This removes py36 tests
from tox.

* (fix)[wizard]: Search Error Update

Fixed an issue where searching for PoGo would fail
and cause a traceback in the wizard.
  • Loading branch information
Expl0dingBanana authored Oct 8, 2021
1 parent ea1b08e commit b3a4355
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
26 changes: 21 additions & 5 deletions mapadroid/mad_apk/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class InvalidFile(WizardError):
pass


class SearchError(WizardError):
pass


class APKWizard(object):
""" The wizard will allow for simplified APK management for the required packages
Expand Down Expand Up @@ -69,8 +73,12 @@ def apk_all_download(self) -> NoReturn:

def apk_all_search(self) -> NoReturn:
"Search for updates for any required package"
self.find_latest_pogo(APKArch.armeabi_v7a)
self.find_latest_pogo(APKArch.arm64_v8a)
try:
self.find_latest_pogo(APKArch.armeabi_v7a)
self.find_latest_pogo(APKArch.arm64_v8a)
except SearchError:
# The error has already been logged as a warning
pass
self.find_latest_rgc(APKArch.noarch)
self.find_latest_pd(APKArch.noarch)

Expand Down Expand Up @@ -110,7 +118,11 @@ def apk_search(self, package: APKType, architecture: APKArch) -> NoReturn:
architecture (APKArch): Architecture of the package to search
"""
if package == APKType.pogo:
self.find_latest_pogo(architecture)
try:
self.find_latest_pogo(architecture)
except SearchError:
# The error has already been logged as a warning
pass
elif package == APKType.rgc:
self.find_latest_rgc(architecture)
elif package == APKType.pd:
Expand All @@ -132,7 +144,11 @@ def download_pogo(self, architecture: APKArch) -> NoReturn:
" Please configure this to use the wizard for downloading PokemonGo."
)
return None
latest_pogo_info = self.find_latest_pogo(architecture)
try:
latest_pogo_info = self.find_latest_pogo(architecture)
except SearchError:
# The error has already been logged as a warning
return None
if latest_pogo_info[0] is None:
logger.warning('Unable to find latest data for PoGo. Try again later')
return None
Expand Down Expand Up @@ -485,7 +501,7 @@ def get_available_versions() -> Dict[str, PackageVersion]:
"Unable to query APKMirror. There is probably a recaptcha that needs to be solved and that "
"functionality is not currently implemented. Please manually download and upload to the wizard"
)
return {}
raise SearchError
else:
logger.info("Successfully queried APKMirror to get the latest releases")
return available["Pokemon GO"]
3 changes: 2 additions & 1 deletion tests/mad_apk/test_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,6 @@ def test_ensure_cache_for_download(psearch):
def test_parsing_error(psearch, caplog):
wizard.get_available_versions.cache_clear()
psearch.side_effect = mock.Mock(side_effect=IndexError)
wizard.get_available_versions()
with pytest.raises(wizard.SearchError):
wizard.get_available_versions()
assert "Unable to query APKMirror" in caplog.text
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
envlist=
lint
py{36,37,38}
py{37,38}
PYTHONPATH = {toxinidir}:/usr/src/app

[testenv]
Expand Down

0 comments on commit b3a4355

Please sign in to comment.