Skip to content
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

Test oauth token refresh and fix related bugs #40

Merged
merged 4 commits into from
Nov 13, 2023
Merged

Conversation

caarmen
Copy link
Owner

@caarmen caarmen commented Nov 13, 2023

  • Create unit tests to test refreshing the oauth token after receiving a fitbit or withings notification webhook.
  • Fix bugs found by the new tests.

Fix this bug:

```
2023-10-15 01:53:07,364 [uvicorn.access] INFO:     [23b1dbb1-cdc0-4172-baf7-16965b05a831] 172.17.0.1:36156 - "POST /fitbit-notification-webhook/ HTTP/1.0" 500
2023-10-15 01:53:07,366 [uvicorn.error ] ERROR:    Exception in ASGI application
Traceback (most recent call last):
...
    raise exc.MissingGreenlet(
sqlalchemy.exc.MissingGreenlet: greenlet_spawn has not been called; can't call await_only() here. Was IO attempted in an unexpected place? (Background on this error at: https://sqlalche.me/e/20/xd2s)

...

    | During handling of the above exception, another exception occurred:
    |
...
    |   File "/app/slackhealthbot/main.py", line 179, in fitbit_notification_webhook
    |     activity_history = await fitbit_service.get_activity(
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/app/slackhealthbot/services/fitbit/service.py", line 101, in get_activity
    |     if not _is_new_valid_activity(user, activity):
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/app/slackhealthbot/services/fitbit/service.py", line 57, in _is_new_valid_activity
    |     x for x in user.fitbit.latest_activities if x.log_id == activity.log_id
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
We were missing an `await` in the requests post wrapper.
```
        response = await requests.post(
            db,
            user=user,
            url=f"{settings.withings_base_url}measure",
            data={
                "action": "getmeas",
                "meastype": 1,  # weight
                "category": 1,  # real measures, not objectives
                "startdate": startdate,
                "enddate": enddate,
            },
        )
>       response_data = response.json()["body"]
E       AttributeError: 'coroutine' object has no attribute 'json'
```
@caarmen caarmen changed the title Improve oauth token refresh Test oauth token refresh and fix related bugs Nov 13, 2023
@caarmen caarmen marked this pull request as ready for review November 13, 2023 17:58
@caarmen caarmen merged commit c67e059 into main Nov 13, 2023
@caarmen caarmen deleted the improve-retries branch November 13, 2023 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant