Skip to content

Commit

Permalink
Merge pull request #191 from tomasbedrich/deleted_user
Browse files Browse the repository at this point in the history
Fix for deleted owners
  • Loading branch information
FriedrichFroebel authored Aug 23, 2022
2 parents b9df993 + f07d70d commit 1f81926
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pycaching/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ def author(self):

@author.setter
def author(self, author):
author = str(author).strip()
if author is not None:
author = str(author).strip()
self._author = author

@property
Expand Down Expand Up @@ -744,7 +745,13 @@ def load(self):
raise errors.LoadError()
self.name = cache_details.find(id="ctl00_ContentBody_CacheName").text

self.author = cache_details("a")[1].text
try:
self.author = cache_details("a")[1].text
except IndexError:
if "[DELETED_USER]" in cache_details.find("div", id="ctl00_ContentBody_mcd1").text:
self.author = None
else:
raise

D_and_T_img = root.find("div", "CacheStarLabels").find_all("img")
self.difficulty, self.terrain = [float(img.get("alt").split()[0]) for img in D_and_T_img]
Expand All @@ -762,7 +769,7 @@ def load(self):
if self.pm_only:
raise errors.PMOnlyException()

# details not avaliable for basic members for PM only caches ------------------------------
# details not available for basic members for PM only caches
pm_only_warning = root.find("p", "Warning NoBottomSpacing")
self.pm_only = pm_only_warning and ("Premium Member Only" in pm_only_warning.text) or False

Expand Down
168 changes: 168 additions & 0 deletions test/cassettes/cache_author_deleted.json

Large diffs are not rendered by default.

168 changes: 168 additions & 0 deletions test/cassettes/cache_author_normal.json

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions test/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,19 @@ def test_cache_types(self):
self.assertEqual(cache.type, Type.geocaching_hq)


class TestCacheIssues(LoggedInTest):
def test_author(self):
with self.subTest("normal"):
cache = Cache(self.gc, "GC4808G")
with self.recorder.use_cassette("cache_author_normal"):
self.assertEqual("Bifurkační tým", cache.author)

with self.subTest("deleted"):
cache = Cache(self.gc, "GC1MX0C")
with self.recorder.use_cassette("cache_author_deleted"):
self.assertIsNone(cache.author)


class TestWaypointProperties(unittest.TestCase):
def setUp(self):
self.w = Waypoint("id", "Parking", Point("N 56° 50.006′ E 13° 56.423′"), "This is a test")
Expand Down

0 comments on commit 1f81926

Please sign in to comment.