Skip to content

Allow the string to be used as a sort_by parameter in Geocaching.sort() method #228

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 2 commits into from
Nov 29, 2023
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
3 changes: 3 additions & 0 deletions pycaching/geocaching.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ def search(
:return: A generator that yields :class:`.Cache` objects.
"""

if not isinstance(sort_by, SortOrder):
sort_by = SortOrder(sort_by)

return self.advanced_search(
{
"origin": "{},{}".format(point.latitude, point.longitude),
Expand Down
10 changes: 10 additions & 0 deletions test/test_geocaching.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ def test_search(self):
caches = list(self.gc.search(Point(49.733867, 13.397091), 100, per_query=50))
self.assertNotEqual(caches[0], caches[50])

with self.subTest("sort_str"):
with self.recorder.use_cassette("geocaching_search"):
caches = list(self.gc.search(Point(49.733867, 13.397091), 20, sort_by="datelastvisited"))
self.assertGreater(len(expected & found), len(expected) - tolerance)

with self.subTest("sort"):
with self.recorder.use_cassette("geocaching_search"):
caches = list(self.gc.search(Point(49.733867, 13.397091), 20, sort_by=SortOrder.date_last_visited))
self.assertGreater(len(expected & found), len(expected) - tolerance)

def test_search_quick(self):
"""Perform quick search and check found caches"""
rect = Rectangle(Point(49.73, 13.38), Point(49.74, 13.40))
Expand Down