Skip to content

Commit

Permalink
Fix signup_by_email (#320)
Browse files Browse the repository at this point in the history
* fix signup_by_email

* update test_signup

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Anthony Hivert <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 349fee9 commit 91c7c3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
27 changes: 21 additions & 6 deletions tests/test_signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,38 @@
import pytest
import responses

from tgtg import BASE_URL, SIGNUP_BY_EMAIL_ENDPOINT, TgtgClient
from tgtg import AUTH_POLLING_ENDPOINT, BASE_URL, SIGNUP_BY_EMAIL_ENDPOINT, TgtgClient
from tgtg.exceptions import TgtgAPIError


def test_signup_ok():
responses.add(
responses.POST,
urljoin(BASE_URL, AUTH_POLLING_ENDPOINT),
json={
"access_token": "an_access_token",
"refresh_token": "a_refresh_token",
"startup_data": {"user": {"user_id": 1234}},
},
status=200,
adding_headers={"set-cookie": "sweet sweet cookie"},
)
responses.add(
responses.POST,
urljoin(BASE_URL, AUTH_POLLING_ENDPOINT),
status=202,
)
responses.add(
responses.POST,
urljoin(BASE_URL, SIGNUP_BY_EMAIL_ENDPOINT),
json={
"login_response": {
"access_token": "an_access_token",
"refresh_token": "a_refresh_token",
}
"state": "WAIT",
"polling_id": "a_polling_id",
},
status=200,
)
client = TgtgClient().signup_by_email(email="[email protected]")
client = TgtgClient()
client.signup_by_email(email="[email protected]")
assert client.access_token == "an_access_token"
assert client.refresh_token == "a_refresh_token"

Expand Down
10 changes: 5 additions & 5 deletions tgtg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ def signup_by_email(
timeout=self.timeout,
)
if response.status_code == HTTPStatus.OK:
self.access_token = response.json()["login_response"]["access_token"]
self.refresh_token = response.json()["login_response"]["refresh_token"]
self.last_time_token_refreshed = datetime.datetime.now()

return self
first_signup_response = response.json()
if first_signup_response["state"] == "WAIT":
self.start_polling(first_signup_response["polling_id"])
else:
raise TgtgAPIError(response.status_code, response.content)
else:
raise TgtgAPIError(response.status_code, response.content)

Expand Down

0 comments on commit 91c7c3c

Please sign in to comment.