When creating user from BlenderID, full_name defaults to username.

This commit is contained in:
Sybren A. Stüvel 2016-07-05 12:36:32 +02:00
parent 8a0fa8afd6
commit dda0e2c868
3 changed files with 29 additions and 7 deletions

View File

@ -209,8 +209,12 @@ def find_user_in_db(blender_id_user_id, user_info):
db_user['email'] = user_info['email']
else:
log.debug('User %r not yet in our database, create a new one.', blender_id_user_id)
db_user = authentication.create_new_user_document(user_info['email'], blender_id_user_id,
user_info['full_name'])
db_user = authentication.create_new_user_document(
email=user_info['email'],
user_id=blender_id_user_id,
username=user_info['full_name'])
db_user['username'] = authentication.make_unique_username(user_info['email'])
if not db_user['full_name']:
db_user['full_name'] = db_user['username']
return db_user

View File

@ -44,7 +44,7 @@ _activity_object_type = {
users_schema = {
'full_name': {
'type': 'string',
'minlength': 3,
'minlength': 1,
'maxlength': 128,
'required': True,
},

View File

@ -7,7 +7,7 @@ from bson import ObjectId
from flask import g
from common_test_class import (AbstractPillarTest, TEST_EMAIL_ADDRESS, BLENDER_ID_TEST_USERID,
TEST_SUBCLIENT_TOKEN, BLENDER_ID_USER_RESPONSE, TEST_FULL_NAME)
TEST_SUBCLIENT_TOKEN, TEST_EMAIL_USER, TEST_FULL_NAME)
class BlenderIdSubclientTest(AbstractPillarTest):
@ -15,6 +15,22 @@ class BlenderIdSubclientTest(AbstractPillarTest):
def test_store_scst_new_user(self):
self._common_user_test(201)
@responses.activate
def test_store_scst_new_user_without_full_name(self):
responses.add(responses.POST,
'%s/u/validate_token' % self.app.config['BLENDER_ID_ENDPOINT'],
json={'status': 'success',
'user': {'email': TEST_EMAIL_ADDRESS,
'full_name': None,
'id': BLENDER_ID_TEST_USERID},
'token_expires': 'Mon, 1 Jan 2218 01:02:03 GMT'},
status=200)
self._common_user_test(201,
expected_full_name=TEST_EMAIL_USER,
mock_happy_blender_id=False)
@responses.activate
def test_store_scst_existing_user(self):
# Make sure the user exists in our database.
@ -58,15 +74,17 @@ class BlenderIdSubclientTest(AbstractPillarTest):
self.assertEqual(db_user['_id'], g.current_user['user_id'])
def _common_user_test(self, expected_status_code, scst=TEST_SUBCLIENT_TOKEN,
expected_full_name=TEST_FULL_NAME):
self.mock_blenderid_validate_happy()
expected_full_name=TEST_FULL_NAME,
mock_happy_blender_id=True):
if mock_happy_blender_id:
self.mock_blenderid_validate_happy()
subclient_id = self.app.config['BLENDER_ID_SUBCLIENT_ID']
resp = self.client.post('/blender_id/store_scst',
data={'user_id': BLENDER_ID_TEST_USERID,
'subclient_id': subclient_id,
'token': scst})
self.assertEqual(expected_status_code, resp.status_code)
self.assertEqual(expected_status_code, resp.status_code, resp.data)
user_info = json.loads(resp.data) # {'status': 'success', 'subclient_user_id': '...'}
self.assertEqual('success', user_info['status'])