Skip to content

Commit

Permalink
Revert "Fix signup_by_email (#320)"
Browse files Browse the repository at this point in the history
This reverts commit 91c7c3c.
  • Loading branch information
ahivert committed Nov 22, 2024
1 parent 7419787 commit dd472a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
27 changes: 6 additions & 21 deletions tests/test_signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,23 @@
import pytest
import responses

from tgtg import AUTH_POLLING_ENDPOINT, BASE_URL, SIGNUP_BY_EMAIL_ENDPOINT, TgtgClient
from tgtg import 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={
"state": "WAIT",
"polling_id": "a_polling_id",
"login_response": {
"access_token": "an_access_token",
"refresh_token": "a_refresh_token",
}
},
status=200,
)
client = TgtgClient()
client.signup_by_email(email="[email protected]")
client = TgtgClient().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:
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)
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
else:
raise TgtgAPIError(response.status_code, response.content)

Expand Down

0 comments on commit dd472a5

Please sign in to comment.