From 977d05f0714afd192399956b3847aea82c3677fa Mon Sep 17 00:00:00 2001 From: Matin Tamizi Date: Thu, 12 Dec 2024 06:10:04 -0600 Subject: [PATCH] undo a breaking change --- garth/http.py | 18 +++--- garth/version.py | 2 +- tests/cassettes/test_profile_alias.yaml | 82 +++++++++++++++++++++++++ tests/test_http.py | 12 +++- uv.lock | 28 +++++++-- 5 files changed, 126 insertions(+), 16 deletions(-) create mode 100644 tests/cassettes/test_profile_alias.yaml diff --git a/garth/http.py b/garth/http.py index 957544f..d086d85 100644 --- a/garth/http.py +++ b/garth/http.py @@ -28,7 +28,7 @@ class Client: backoff_factor: float = 0.5 pool_connections: int = 10 pool_maxsize: int = 10 - _social_profile: Dict[str, Any] | None = None + _user_profile: Dict[str, Any] | None = None def __init__(self, session: Session | None = None, **kwargs): self.sess = session if session else Session() @@ -92,19 +92,23 @@ def configure( self.sess.mount("https://", adapter) @property - def social_profile(self): - if not self._social_profile: - self._social_profile = self.connectapi( + def user_profile(self): + if not self._user_profile: + self._user_profile = self.connectapi( "/userprofile-service/socialProfile" ) assert isinstance( - self._social_profile, dict + self._user_profile, dict ), "No profile from connectapi" - return self._social_profile + return self._user_profile + + @property + def profile(self): + return self.user_profile @property def username(self): - return self.social_profile["userName"] + return self.user_profile["userName"] def request( self, diff --git a/garth/version.py b/garth/version.py index dd9b22c..7225152 100644 --- a/garth/version.py +++ b/garth/version.py @@ -1 +1 @@ -__version__ = "0.5.1" +__version__ = "0.5.2" diff --git a/tests/cassettes/test_profile_alias.yaml b/tests/cassettes/test_profile_alias.yaml new file mode 100644 index 0000000..e935f67 --- /dev/null +++ b/tests/cassettes/test_profile_alias.yaml @@ -0,0 +1,82 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - Bearer SANITIZED + Connection: + - keep-alive + User-Agent: + - GCM-iOS-5.7.2.1 + referer: + - https://sso.garmin.com/sso/verifyMFA/loginEnterMfaCode?id=gauth-widget&embedWidget=true&gauthHost=https%3A%2F%2Fsso.garmin.com%2Fsso%2Fembed&service=https%3A%2F%2Fsso.garmin.com%2Fsso%2Fembed&source=https%3A%2F%2Fsso.garmin.com%2Fsso%2Fembed&redirectAfterAccountLoginUrl=https%3A%2F%2Fsso.garmin.com%2Fsso%2Fembed&redirectAfterAccountCreationUrl=https%3A%2F%2Fsso.garmin.com%2Fsso%2Fembed + method: GET + uri: https://connectapi.garmin.com/userprofile-service/socialProfile + response: + body: + string: '{"id": 3154645, "profileId": 2591602, "garminGUID": "0690cc1d-d23d-4412-b027-80fd4ed1c0f6", + "displayName": "mtamizi", "fullName": "Matin Tamizi", "userName": "mtamizi", + "profileImageType": "UPLOADED_PHOTO", "profileImageUrlLarge": "https://s3.amazonaws.com/garmin-connect-prod/profile_images/73240e81-6e4d-43fc-8af8-c8f6c51b3b8f-2591602.png", + "profileImageUrlMedium": "https://s3.amazonaws.com/garmin-connect-prod/profile_images/685a19e9-a7be-4a11-9bf9-faca0c5d1f1a-2591602.png", + "profileImageUrlSmall": "https://s3.amazonaws.com/garmin-connect-prod/profile_images/6302f021-0ec7-4dc9-b0c3-d5a19bc5a08c-2591602.png", + "location": "Ciudad de M\u00e9xico, CDMX", "facebookUrl": null, "twitterUrl": + null, "personalWebsite": null, "motivation": null, "bio": null, "primaryActivity": + null, "favoriteActivityTypes": [], "runningTrainingSpeed": 0.0, "cyclingTrainingSpeed": + 0.0, "favoriteCyclingActivityTypes": [], "cyclingClassification": null, "cyclingMaxAvgPower": + 0.0, "swimmingTrainingSpeed": 0.0, "profileVisibility": "private", "activityStartVisibility": + "private", "activityMapVisibility": "public", "courseVisibility": "public", + "activityHeartRateVisibility": "public", "activityPowerVisibility": "public", + "badgeVisibility": "private", "showAge": false, "showWeight": false, "showHeight": + false, "showWeightClass": false, "showAgeRange": false, "showGender": false, + "showActivityClass": false, "showVO2Max": false, "showPersonalRecords": false, + "showLast12Months": false, "showLifetimeTotals": false, "showUpcomingEvents": + false, "showRecentFavorites": false, "showRecentDevice": false, "showRecentGear": + false, "showBadges": true, "otherActivity": null, "otherPrimaryActivity": + null, "otherMotivation": null, "userRoles": ["SCOPE_ATP_READ", "SCOPE_ATP_WRITE", + "SCOPE_COMMUNITY_COURSE_READ", "SCOPE_COMMUNITY_COURSE_WRITE", "SCOPE_CONNECT_READ", + "SCOPE_CONNECT_WRITE", "SCOPE_DT_CLIENT_ANALYTICS_WRITE", "SCOPE_GARMINPAY_READ", + "SCOPE_GARMINPAY_WRITE", "SCOPE_GCOFFER_READ", "SCOPE_GCOFFER_WRITE", "SCOPE_GHS_SAMD", + "SCOPE_GHS_UPLOAD", "SCOPE_GOLF_API_READ", "SCOPE_GOLF_API_WRITE", "SCOPE_INSIGHTS_READ", + "SCOPE_INSIGHTS_WRITE", "SCOPE_OMT_CAMPAIGN_READ", "SCOPE_OMT_SUBSCRIPTION_READ", + "SCOPE_PRODUCT_SEARCH_READ", "ROLE_CONNECTUSER", "ROLE_FITNESS_USER", "ROLE_WELLNESS_USER", + "ROLE_OUTDOOR_USER", "ROLE_CONNECT_2_USER", "ROLE_TACX_APP_USER"], "nameApproved": + true, "userProfileFullName": "Matin Tamizi", "makeGolfScorecardsPrivate": + true, "allowGolfLiveScoring": false, "allowGolfScoringByConnections": true, + "userLevel": 4, "userPoint": 166, "levelUpdateDate": "2024-01-31T12:18:59.0", + "levelIsViewed": false, "levelPointThreshold": 300, "userPointOffset": 0, + "userPro": false}' + headers: + CF-Cache-Status: + - DYNAMIC + CF-RAY: + - 8f0d992ebcfb6c34-DFW + Cache-Control: + - no-cache, no-store, private + Connection: + - keep-alive + Content-Type: + - application/json;charset=UTF-8 + Date: + - Thu, 12 Dec 2024 12:08:11 GMT + NEL: + - '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}' + Report-To: + - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=niRDLu7E86gruuRnFLQL4RUQO9vMZyAA5NQ64mt7vW0Gmmsl2%2BCut6v2k9Pj6yXDDr42mqOH%2B%2BvYhVgRbnkLUTD3xXo3YREb7jiUYBGZhBKpRQafvfz0TvC63Co%2BVJCaehygZ%2B9HlA%3D%3D"}],"group":"cf-nel","max_age":604800}' + Server: + - cloudflare + Set-Cookie: + - _cfuvid=SANITIZED; path=SANITIZED; domain=SANITIZED; HttpOnly; Secure; SameSite=SANITIZED + Transfer-Encoding: + - chunked + alt-svc: + - h3=":443"; ma=86400 + pragma: + - no-cache + status: + code: 200 + message: OK +version: 1 diff --git a/tests/test_http.py b/tests/test_http.py index 7fe7b89..1e02e8d 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -144,9 +144,17 @@ def mock_input(_): @pytest.mark.vcr def test_username(authed_client: Client): - assert authed_client._social_profile is None + assert authed_client._user_profile is None assert authed_client.username - assert authed_client._social_profile + assert authed_client._user_profile + + +@pytest.mark.vcr +def test_profile_alias(authed_client: Client): + assert authed_client._user_profile is None + profile = authed_client.profile + assert profile == authed_client.user_profile + assert authed_client._user_profile is not None @pytest.mark.vcr diff --git a/uv.lock b/uv.lock index 21a6a82..a370ea4 100644 --- a/uv.lock +++ b/uv.lock @@ -324,11 +324,27 @@ wheels = [ [[package]] name = "debugpy" -version = "1.8.10" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/2e/3c/ef563dec9f7ea4c29bd26ed3c5eba5038f8d9d46ac41aacfc99dc77f0885/debugpy-1.8.10.tar.gz", hash = "sha256:ee4ed903cbeb14ee1839549f953af519ffa512598ec987b2051f9c868e2249a8", size = 1644028 } -wheels = [ - { url = "https://files.pythonhosted.org/packages/8d/cc/5f34d94234900a0165e0b86bc503ca97c2fdfb4a208e082fe6a1c491d6ea/debugpy-1.8.10-cp310-cp310-macosx_14_0_x86_64.whl", hash = "sha256:97aa00af95983887806e06f37e144909d35215d66db74f8b0e9799b4eef40cfd", size = 2080716 }, +version = "1.8.9" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/88/92/15b454c516c4c53cc8c03967e4be12b65a1ea36db3bb4513a7453f75c8d8/debugpy-1.8.9.zip", hash = "sha256:1339e14c7d980407248f09824d1b25ff5c5616651689f1e0f0e51bdead3ea13e", size = 4921695 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d0/2e/92fda96b1b773e454daae3e2962726dd9f7aedb1f26d7f2ca353d91a930b/debugpy-1.8.9-cp310-cp310-macosx_14_0_x86_64.whl", hash = "sha256:cfe1e6c6ad7178265f74981edf1154ffce97b69005212fbc90ca22ddfe3d017e", size = 2080529 }, + { url = "https://files.pythonhosted.org/packages/87/c0/d13cdbae394c7ae65ef93d7ccde2ff364445248e367bda93fc0650c08849/debugpy-1.8.9-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ada7fb65102a4d2c9ab62e8908e9e9f12aed9d76ef44880367bc9308ebe49a0f", size = 3565151 }, + { url = "https://files.pythonhosted.org/packages/23/40/237c0a7a68cb982dcced4a0199b7c464630f75b9280d6bebde32490135d1/debugpy-1.8.9-cp310-cp310-win32.whl", hash = "sha256:c36856343cbaa448171cba62a721531e10e7ffb0abff838004701454149bc037", size = 5117068 }, + { url = "https://files.pythonhosted.org/packages/00/89/e0be9f01ee461e3369dde418492244acb1b67adaf04cb5ea98f1380ab101/debugpy-1.8.9-cp310-cp310-win_amd64.whl", hash = "sha256:17c5e0297678442511cf00a745c9709e928ea4ca263d764e90d233208889a19e", size = 5149364 }, + { url = "https://files.pythonhosted.org/packages/f7/bf/c41b688ad490d644b3bcca505a87ea58ec0442234def9a641ba62dce9c11/debugpy-1.8.9-cp311-cp311-macosx_14_0_universal2.whl", hash = "sha256:b74a49753e21e33e7cf030883a92fa607bddc4ede1aa4145172debc637780040", size = 2179080 }, + { url = "https://files.pythonhosted.org/packages/f4/dd/e9de11423db7bde62469fbd932243c64f66d6d87924976f49ec336415522/debugpy-1.8.9-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:62d22dacdb0e296966d7d74a7141aaab4bec123fa43d1a35ddcb39bf9fd29d70", size = 3137893 }, + { url = "https://files.pythonhosted.org/packages/2c/bf/e1f2c81220591728f35585b4abd67e71e9b39b3cb983f428b23d4ca6c22e/debugpy-1.8.9-cp311-cp311-win32.whl", hash = "sha256:8138efff315cd09b8dcd14226a21afda4ca582284bf4215126d87342bba1cc66", size = 5042644 }, + { url = "https://files.pythonhosted.org/packages/96/20/a407252954fd2812771e4ea3ab523f73889fd5027e305dec5ee4f0af149a/debugpy-1.8.9-cp311-cp311-win_amd64.whl", hash = "sha256:ff54ef77ad9f5c425398efb150239f6fe8e20c53ae2f68367eba7ece1e96226d", size = 5066943 }, + { url = "https://files.pythonhosted.org/packages/da/ab/1420baf8404d2b499349a44de5037133e06d489009032ce016fedb66eea1/debugpy-1.8.9-cp312-cp312-macosx_14_0_universal2.whl", hash = "sha256:957363d9a7a6612a37458d9a15e72d03a635047f946e5fceee74b50d52a9c8e2", size = 2504180 }, + { url = "https://files.pythonhosted.org/packages/58/ec/e0f88c6764314bda7887274e0b980812709b3d6363dcae124a49a9ceaa3c/debugpy-1.8.9-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5e565fc54b680292b418bb809f1386f17081d1346dca9a871bf69a8ac4071afe", size = 4224563 }, + { url = "https://files.pythonhosted.org/packages/dd/49/d9ea004ee2e4531d2b528841689ee2ba01c6a4b58840efd15e57dd866a86/debugpy-1.8.9-cp312-cp312-win32.whl", hash = "sha256:3e59842d6c4569c65ceb3751075ff8d7e6a6ada209ceca6308c9bde932bcef11", size = 5163641 }, + { url = "https://files.pythonhosted.org/packages/b1/63/c8b0718024c1187a446316037680e1564bf063c6665c815f17b42c244aba/debugpy-1.8.9-cp312-cp312-win_amd64.whl", hash = "sha256:66eeae42f3137eb428ea3a86d4a55f28da9bd5a4a3d369ba95ecc3a92c1bba53", size = 5203862 }, + { url = "https://files.pythonhosted.org/packages/cc/8d/eb12dcb977a2d166aac6614e60daddd1eef72881a0343717d7deb0d4868c/debugpy-1.8.9-cp313-cp313-macosx_14_0_universal2.whl", hash = "sha256:957ecffff80d47cafa9b6545de9e016ae8c9547c98a538ee96ab5947115fb3dd", size = 2489077 }, + { url = "https://files.pythonhosted.org/packages/87/2b/3b7a00d8d2bb891cfa33240575c2d5fc3fa6e0bc75567f4ece59b9d3d6ea/debugpy-1.8.9-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1efbb3ff61487e2c16b3e033bc8595aea578222c08aaf3c4bf0f93fadbd662ee", size = 4219198 }, + { url = "https://files.pythonhosted.org/packages/5f/a1/f489026a65fabfff8c73bd51b880c130d636e02b1847564141fe3957d94f/debugpy-1.8.9-cp313-cp313-win32.whl", hash = "sha256:7c4d65d03bee875bcb211c76c1d8f10f600c305dbd734beaed4077e902606fee", size = 5163014 }, + { url = "https://files.pythonhosted.org/packages/e6/84/6070908dd163121358eb9d76fcc94f05bc99d2f89a85fe1b86167bc34ec6/debugpy-1.8.9-cp313-cp313-win_amd64.whl", hash = "sha256:e46b420dc1bea64e5bbedd678148be512442bc589b0111bd799367cde051e71a", size = 5203529 }, + { url = "https://files.pythonhosted.org/packages/2d/23/3f5804202da11c950dc0caae4a62d0c9aadabdb2daeb5f7aa09838647b5d/debugpy-1.8.9-py2.py3-none-any.whl", hash = "sha256:cc37a6c9987ad743d9c3a14fa1b1a14b7e4e6041f9dd0c8abf8895fe7a97b899", size = 5166094 }, ] [[package]] @@ -401,7 +417,7 @@ wheels = [ [[package]] name = "garth" -version = "0.5.1" +version = "0.5.2" source = { editable = "." } dependencies = [ { name = "pydantic" },