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

Fix signup_by_email #320

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 22 additions & 7 deletions tests/test_signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,42 @@
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",
"startup_data": {"user": {"user_id": 1234}},
}
"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"
assert client.user_id == 1234
assert client.cookie == "sweet sweet cookie"


def test_signup_fail():
Expand Down
12 changes: 5 additions & 7 deletions tgtg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,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()
self.user_id = response.json()["login_response"]["startup_data"]["user"][
"user_id"
]
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