Skip to content

Fix for deleted owners #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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