Skip to content

Commit a320011

Browse files
Merge pull request #146 from CachingFoX/bugfix-cache-types
Bugfix cache types
2 parents de9b48e + 0217e30 commit a320011

File tree

8 files changed

+1141
-15
lines changed

8 files changed

+1141
-15
lines changed

pycaching/cache.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,37 +1195,48 @@ def note(self, note):
11951195
class Type(enum.Enum):
11961196
"""Enum of possible cache types.
11971197
1198-
Values are cache image filenames - http://www.geocaching.com/images/WptTypes/[VALUE].gif
1198+
according to
1199+
* https://www.geocaching.com/app/ui-icons/sprites/cache-types.svg
1200+
* https://www.geocaching.com/about/cache_types.aspx
11991201
"""
12001202

1201-
# TODO cleanup according to https://www.geocaching.com/app/ui-icons/sprites/cache-types.svg
12021203
traditional = "2"
12031204
multicache = "3"
1204-
mystery = unknown = "8"
1205+
mystery = unknown = puzzle = "8"
12051206
letterbox = "5"
12061207
event = "6"
12071208
mega_event = "453"
1208-
giga_event = "giga"
1209+
giga_event = "7005"
12091210
earthcache = "137"
12101211
cito = cache_in_trash_out_event = "13"
12111212
webcam = "11"
12121213
virtual = "4"
12131214
wherigo = "1858"
1214-
lost_and_found_event = "10Years_32"
1215-
project_ape = "ape_32"
1216-
groundspeak_hq = "HQ_32"
1217-
gps_adventures_exhibit = "1304"
1215+
lost_and_found_event = community_celebration = "3653"
1216+
project_ape = "9"
1217+
geocaching_hq = groundspeak_hq = "3773"
1218+
gps_adventures_exhibit = gps_maze = "1304"
12181219
groundspeak_block_party = "4738"
12191220
locationless = reverse = "12"
1221+
hq_celebration = "3774"
12201222

12211223
@classmethod
12221224
def from_filename(cls, filename):
1223-
"""Return a cache type from its image filename."""
1225+
"""Return a cache type from its image filename.
1226+
1227+
Values are cache image filenames - http://www.geocaching.com/images/WptTypes/[VALUE].gif
1228+
"""
12241229
# fuck Groundspeak, they sometimes use 2 exactly same icons with 2 different names
1225-
if filename == "earthcache":
1226-
filename = "137"
1227-
if filename == "mega":
1228-
filename = "453"
1230+
name_mapping = {
1231+
"ape_32": "9",
1232+
"earthcache": "137",
1233+
"mega": "453",
1234+
"10Years_32": "3653",
1235+
"HQ_32": "3773",
1236+
"giga": "7005"
1237+
}
1238+
if filename in name_mapping:
1239+
filename = name_mapping[filename]
12291240
return cls(filename)
12301241

12311242
@classmethod
@@ -1253,12 +1264,15 @@ def from_string(cls, name):
12531264
"webcam": cls.webcam,
12541265
"virtual": cls.virtual,
12551266
"wherigo": cls.wherigo,
1256-
"lost and found event": cls.lost_and_found_event,
1267+
"lost and found event": cls.community_celebration,
12571268
"project ape": cls.project_ape,
1258-
"groundspeak hq": cls.groundspeak_hq,
1269+
"geocaching hq": cls.geocaching_hq,
1270+
"groundspeak hq": cls.geocaching_hq,
12591271
"gps adventures exhibit": cls.gps_adventures_exhibit,
12601272
"groundspeak block party": cls.groundspeak_block_party,
12611273
"locationless (reverse)": cls.locationless,
1274+
"geocaching hq celebration": cls.hq_celebration,
1275+
"community celebration event": cls.community_celebration
12621276
}
12631277

12641278
try:

test/cassettes/cache_type_community_celebration.json

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

test/cassettes/cache_type_gigaevent.json

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

test/cassettes/cache_type_headquarters.json

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

test/cassettes/cache_type_hq_celebration.json

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

test/cassettes/cache_type_locationless.json

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

test/cassettes/cache_type_projectape.json

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

test/test_cache.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,44 @@ def test_post_log(self, mock_request, mock_load_log_page):
337337
}
338338
mock_request.assert_called_with(self.c._get_log_page_url(), method="POST", data=expected_post_data)
339339

340+
def test_cache_types(self):
341+
with self.subTest("Locationless"):
342+
with self.recorder.use_cassette('cache_type_locationless'):
343+
cache = self.gc.get_cache('GC8FR0G')
344+
cache.load()
345+
self.assertEqual(cache.type, Type.locationless)
346+
347+
with self.subTest("Project A.P.E."):
348+
with self.recorder.use_cassette('cache_type_projectape'):
349+
cache = self.gc.get_cache('GC1169')
350+
cache.load()
351+
self.assertEqual(cache.type, Type.project_ape)
352+
353+
with self.subTest("Giga Event"):
354+
with self.recorder.use_cassette('cache_type_gigaevent'):
355+
cache = self.gc.get_cache('GC7WWWW')
356+
cache.load()
357+
self.assertEqual(cache.type, Type.giga_event)
358+
359+
with self.subTest("Geocaching HQ Celebration"):
360+
with self.recorder.use_cassette('cache_type_hq_celebration'):
361+
cache = self.gc.get_cache('GC896PK')
362+
cache.load()
363+
self.assertEqual(cache.type, Type.hq_celebration)
364+
365+
with self.subTest("Community Celebration Event"):
366+
with self.recorder.use_cassette('cache_type_community_celebration'):
367+
cache = self.gc.get_cache('GC8K09M')
368+
cache.load()
369+
self.assertEqual(cache.type, Type.community_celebration)
370+
371+
with self.subTest("Geocaching Headquarters"):
372+
with self.recorder.use_cassette('cache_type_headquarters'):
373+
cache = self.gc.get_cache('GCK25B')
374+
cache.load()
375+
print(cache.type)
376+
self.assertEqual(cache.type, Type.geocaching_hq)
377+
340378

341379
class TestWaypointProperties(unittest.TestCase):
342380
def setUp(self):

0 commit comments

Comments
 (0)