Skip to content
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
44 changes: 29 additions & 15 deletions pycaching/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,37 +1195,48 @@ def note(self, note):
class Type(enum.Enum):
"""Enum of possible cache types.

Values are cache image filenames - http://www.geocaching.com/images/WptTypes/[VALUE].gif
according to
* https://www.geocaching.com/app/ui-icons/sprites/cache-types.svg
* https://www.geocaching.com/about/cache_types.aspx
"""

# TODO cleanup according to https://www.geocaching.com/app/ui-icons/sprites/cache-types.svg
traditional = "2"
multicache = "3"
mystery = unknown = "8"
mystery = unknown = puzzle = "8"
letterbox = "5"
event = "6"
mega_event = "453"
giga_event = "giga"
giga_event = "7005"
earthcache = "137"
cito = cache_in_trash_out_event = "13"
webcam = "11"
virtual = "4"
wherigo = "1858"
lost_and_found_event = "10Years_32"
project_ape = "ape_32"
groundspeak_hq = "HQ_32"
gps_adventures_exhibit = "1304"
lost_and_found_event = community_celebration = "3653"
project_ape = "9"
geocaching_hq = groundspeak_hq = "3773"
gps_adventures_exhibit = gps_maze = "1304"
groundspeak_block_party = "4738"
locationless = reverse = "12"
hq_celebration = "3774"

@classmethod
def from_filename(cls, filename):
"""Return a cache type from its image filename."""
"""Return a cache type from its image filename.

Values are cache image filenames - http://www.geocaching.com/images/WptTypes/[VALUE].gif
"""
# fuck Groundspeak, they sometimes use 2 exactly same icons with 2 different names
if filename == "earthcache":
filename = "137"
if filename == "mega":
filename = "453"
name_mapping = {
"ape_32": "9",
"earthcache": "137",
"mega": "453",
"10Years_32": "3653",
"HQ_32": "3773",
"giga": "7005"
}
if filename in name_mapping:
filename = name_mapping[filename]
return cls(filename)

@classmethod
Expand Down Expand Up @@ -1253,12 +1264,15 @@ def from_string(cls, name):
"webcam": cls.webcam,
"virtual": cls.virtual,
"wherigo": cls.wherigo,
"lost and found event": cls.lost_and_found_event,
"lost and found event": cls.community_celebration,
"project ape": cls.project_ape,
"groundspeak hq": cls.groundspeak_hq,
"geocaching hq": cls.geocaching_hq,
"groundspeak hq": cls.geocaching_hq,
"gps adventures exhibit": cls.gps_adventures_exhibit,
"groundspeak block party": cls.groundspeak_block_party,
"locationless (reverse)": cls.locationless,
"geocaching hq celebration": cls.hq_celebration,
"community celebration event": cls.community_celebration
}

try:
Expand Down
179 changes: 179 additions & 0 deletions test/cassettes/cache_type_community_celebration.json

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions test/cassettes/cache_type_gigaevent.json

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions test/cassettes/cache_type_headquarters.json

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions test/cassettes/cache_type_hq_celebration.json

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions test/cassettes/cache_type_locationless.json

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions test/cassettes/cache_type_projectape.json

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions test/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,44 @@ def test_post_log(self, mock_request, mock_load_log_page):
}
mock_request.assert_called_with(self.c._get_log_page_url(), method="POST", data=expected_post_data)

def test_cache_types(self):
with self.subTest("Locationless"):
with self.recorder.use_cassette('cache_type_locationless'):
cache = self.gc.get_cache('GC8FR0G')
cache.load()
self.assertEqual(cache.type, Type.locationless)

with self.subTest("Project A.P.E."):
with self.recorder.use_cassette('cache_type_projectape'):
cache = self.gc.get_cache('GC1169')
cache.load()
self.assertEqual(cache.type, Type.project_ape)

with self.subTest("Giga Event"):
with self.recorder.use_cassette('cache_type_gigaevent'):
cache = self.gc.get_cache('GC7WWWW')
cache.load()
self.assertEqual(cache.type, Type.giga_event)

with self.subTest("Geocaching HQ Celebration"):
with self.recorder.use_cassette('cache_type_hq_celebration'):
cache = self.gc.get_cache('GC896PK')
cache.load()
self.assertEqual(cache.type, Type.hq_celebration)

with self.subTest("Community Celebration Event"):
with self.recorder.use_cassette('cache_type_community_celebration'):
cache = self.gc.get_cache('GC8K09M')
cache.load()
self.assertEqual(cache.type, Type.community_celebration)

with self.subTest("Geocaching Headquarters"):
with self.recorder.use_cassette('cache_type_headquarters'):
cache = self.gc.get_cache('GCK25B')
cache.load()
print(cache.type)
self.assertEqual(cache.type, Type.geocaching_hq)


class TestWaypointProperties(unittest.TestCase):
def setUp(self):
Expand Down