diff --git a/hscp.py b/hscp.py index ada1620..f141ef9 100644 --- a/hscp.py +++ b/hscp.py @@ -35,17 +35,10 @@ def __init__( self.timeout = max(timeout, 0) self.app = app - self.user_agent = user_agent - self._token = None - - @property - def user_agent(self): - return self._user_agent + if user_agent: + self.session.headers["user-agent"] = user_agent - @user_agent.setter - def user_agent(self, val: str): - self._user_agent = val - self.session.headers.update({"user-agent": self._user_agent}) + self._token = None @property def token(self): diff --git a/tests/test_hscp.py b/tests/test_hscp.py index aa7c70c..b25467a 100644 --- a/tests/test_hscp.py +++ b/tests/test_hscp.py @@ -22,6 +22,21 @@ def authorized_client(client): client.token = token return client +def test_client(): + client = hscp.HyScoresClient( + url=url, + app=app, + ) + assert client.url == url + assert client.app == app + + user_agent = "pytest_client" + client = hscp.HyScoresClient( + url=url, + app=app, + user_agent=user_agent + ) + assert client.session.headers["user-agent"] == user_agent def test_token_fail(client): with pytest.raises(hscp.TokenUnavailable): @@ -36,6 +51,7 @@ def test_register(requests_mock, client): def test_login(requests_mock, client): requests_mock.post(url + "/login", json={"result": {"token": token}}) client.login(login, pw) + assert client.token is not None def test_scores(requests_mock, authorized_client): @@ -58,7 +74,6 @@ def test_score_uploader(requests_mock, authorized_client): requests_mock.post(url + "/score", json={"result": True}) assert authorized_client.post_score("sadam", 69) is True - def test_logout(authorized_client): authorized_client.logout() assert authorized_client.token is None