Fixed updating username in settings view

The timestamps used by the 'last viewed' property of the video progress
feature were converted to strings when sending to the frontend, but never
changed back to timestamps when PUTting via the SDK. I solved it by not
PUTing the user at all, but using PATCH to set the username instead.
This commit is contained in:
2019-05-29 18:37:01 +02:00
parent 23f8c1a446
commit 0f0a4be412
5 changed files with 95 additions and 4 deletions

View File

@@ -0,0 +1,37 @@
import flask
import flask_login
from pillar.tests import AbstractPillarTest
class UsernameTest(AbstractPillarTest):
def setUp(self, **kwargs) -> None:
super().setUp(**kwargs)
self.user_id = self.create_user()
def test_update_via_web(self) -> None:
from pillar.auth import current_user
import pillar.web.settings.routes
with self.app.app_context():
url = flask.url_for('settings.profile')
with self.app.test_request_context(
path=url,
data={'username': 'je.moeder'},
method='POST',
):
self.login_api_as(self.user_id)
flask_login.login_user(current_user)
pillar.web.settings.routes.profile()
db_user = self.fetch_user_from_db(self.user_id)
self.assertEqual('je.moeder', db_user['username'])
def test_update_via_patch(self) -> None:
self.create_valid_auth_token(self.user_id, 'user-token')
self.patch(f'/api/users/{self.user_id}',
json={'op': 'set-username', 'username': 'je.moeder'},
auth_token='user-token')
db_user = self.fetch_user_from_db(self.user_id)
self.assertEqual('je.moeder', db_user['username'])