Skip to content

Commit

Permalink
Fixed #31, added test
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbedrich committed Aug 24, 2015
1 parent c8d349b commit 1ce532f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pycaching/geocaching.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ def load_cache_quick(self, wp, destination=None):
raise Error("Cannot load quick cache details page.") from e

if res["status"] == "failed" or len(res["data"]) != 1:
raise LoadError("Waypoint '{}' cannot be loaded: {}".format(wp, res["msg"]))
error_msg = res["msg"] if "msg" in res else "Unknown error (probably not existing cache)"
raise LoadError("Waypoint '{}' cannot be loaded: {}".format(wp, error_msg))

data = res["data"][0]

Expand Down
12 changes: 9 additions & 3 deletions test/test_geocaching.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,15 @@ def test_load_cache(self):
self.g.load_cache("GC3AHDM")

def test_load_cache_quick(self):
cache = self.g.load_cache_quick("GC4808G")
self.assertTrue(isinstance(cache, Cache))
self.assertEqual("GC4808G", cache.wp)
with self.subTest("normal"):
cache = self.g.load_cache_quick("GC4808G")
self.assertTrue(isinstance(cache, Cache))
self.assertEqual("GC4808G", cache.wp)

with self.subTest("fail"):
with self.assertRaises(pycaching.errors.LoadError):
cache = self.g.load_cache_quick("GC123456")


def test_load_trackable(self):
trackable = self.g.load_trackable("TB1KEZ9")
Expand Down

0 comments on commit 1ce532f

Please sign in to comment.