Skip to content

Fix for loading trackables without a type #190

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 3 commits into from
Aug 22, 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
4 changes: 2 additions & 2 deletions pycaching/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def from_tile(cls, tile, tile_point=None):
else:
dx, dy = 0, 0

n = 2.0 ** tile.z
n = 2.0**tile.z
lon_deg = (tile.x + dx) / n * 360.0 - 180.0
lat_rad = math.atan(math.sinh(math.pi * (1 - 2 * (tile.y + dy) / n)))
lat_deg = math.degrees(lat_rad)
Expand All @@ -132,7 +132,7 @@ def to_tile(self, geocaching, zoom):
lat_deg = self.latitude
lon_deg = self.longitude
lat_rad = math.radians(lat_deg)
n = 2.0 ** zoom
n = 2.0**zoom
x = int((lon_deg + 180.0) / 360.0 * n)
y = int((1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n)
return Tile(geocaching, x, y, zoom)
Expand Down
2 changes: 1 addition & 1 deletion pycaching/geocaching.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def login(self, username=None, password=None):
post = {"UsernameOrEmail": username, "Password": password, token_field_name: token_value}

# login to the site
logging.debug("Submiting login form.")
logging.debug("Submitting login form.")
after_login_page = self._request(self._urls["login_page"], method="POST", data=post, login_check=False)

logging.debug("Checking the result.")
Expand Down
8 changes: 5 additions & 3 deletions pycaching/trackable.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ def type(self):
return self._type

@type.setter
def type(self, type):
self._type = type.strip()
def type(self, type_):
if type_ is not None:
type_ = type_.strip()
self._type = type_

def get_KML(self):
"""Return the KML route of the trackable.
Expand All @@ -171,7 +173,7 @@ def load(self):
This method is called automatically when you access a property which isn't yet filled in
(so-called "lazy loading"). You don't have to call it explicitly.

:raise .LoadError: If trackable loading fails (probably because of not existing cache).
:raise .LoadError: If trackable loading fails (probably because of not existing trackable).
"""
# pick url based on what info we have right now
if hasattr(self, "url"):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dev = [
"pytest-cov ~= 3.0",
"betamax ~= 0.8",
"betamax-serializers ~= 0.2",
"black ~= 21.10b0",
"black ~= 22.6.0",
"flake8 ~= 4.0",
"isort ~= 5.10"
]
Expand Down
77 changes: 77 additions & 0 deletions test/cassettes/trackable_load__existing_type.json

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions test/cassettes/trackable_load__missing_type.json

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions test/test_trackable.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,16 @@ def test_get_KML(self):
self.assertTrue("#tbTravelStyle" in kml)
self.assertTrue("<visibility>1</visibility>" in kml)
self.assertTrue("</Placemark></Document></kml>" in kml)


class TestIssues(LoggedInTest):
def test_load__type(self):
with self.subTest("existing"):
trackable = Trackable(self.gc, "TB1KEZ9")
with self.recorder.use_cassette("trackable_load__existing_type"):
self.assertEqual("SwedenHawk Geocoin", trackable.type)

with self.subTest("missing"):
trackable = Trackable(self.gc, "TB7WZD9")
with self.recorder.use_cassette("trackable_load__missing_type"):
self.assertEqual(None, trackable.type)