Skip to content

Commit 1f81926

Browse files
Merge pull request #191 from tomasbedrich/deleted_user
Fix for deleted owners
2 parents b9df993 + f07d70d commit 1f81926

File tree

4 files changed

+359
-3
lines changed

4 files changed

+359
-3
lines changed

pycaching/cache.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ def author(self):
506506

507507
@author.setter
508508
def author(self, author):
509-
author = str(author).strip()
509+
if author is not None:
510+
author = str(author).strip()
510511
self._author = author
511512

512513
@property
@@ -744,7 +745,13 @@ def load(self):
744745
raise errors.LoadError()
745746
self.name = cache_details.find(id="ctl00_ContentBody_CacheName").text
746747

747-
self.author = cache_details("a")[1].text
748+
try:
749+
self.author = cache_details("a")[1].text
750+
except IndexError:
751+
if "[DELETED_USER]" in cache_details.find("div", id="ctl00_ContentBody_mcd1").text:
752+
self.author = None
753+
else:
754+
raise
748755

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

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

test/cassettes/cache_author_deleted.json

Lines changed: 168 additions & 0 deletions
Large diffs are not rendered by default.

test/cassettes/cache_author_normal.json

Lines changed: 168 additions & 0 deletions
Large diffs are not rendered by default.

test/test_cache.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,19 @@ def test_cache_types(self):
407407
self.assertEqual(cache.type, Type.geocaching_hq)
408408

409409

410+
class TestCacheIssues(LoggedInTest):
411+
def test_author(self):
412+
with self.subTest("normal"):
413+
cache = Cache(self.gc, "GC4808G")
414+
with self.recorder.use_cassette("cache_author_normal"):
415+
self.assertEqual("Bifurkační tým", cache.author)
416+
417+
with self.subTest("deleted"):
418+
cache = Cache(self.gc, "GC1MX0C")
419+
with self.recorder.use_cassette("cache_author_deleted"):
420+
self.assertIsNone(cache.author)
421+
422+
410423
class TestWaypointProperties(unittest.TestCase):
411424
def setUp(self):
412425
self.w = Waypoint("id", "Parking", Point("N 56° 50.006′ E 13° 56.423′"), "This is a test")

0 commit comments

Comments
 (0)