When creating user from BlenderID, full_name defaults to username.
This commit is contained in:
parent
8a0fa8afd6
commit
dda0e2c868
@ -209,8 +209,12 @@ def find_user_in_db(blender_id_user_id, user_info):
|
|||||||
db_user['email'] = user_info['email']
|
db_user['email'] = user_info['email']
|
||||||
else:
|
else:
|
||||||
log.debug('User %r not yet in our database, create a new one.', blender_id_user_id)
|
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,
|
db_user = authentication.create_new_user_document(
|
||||||
user_info['full_name'])
|
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'])
|
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
|
return db_user
|
||||||
|
@ -44,7 +44,7 @@ _activity_object_type = {
|
|||||||
users_schema = {
|
users_schema = {
|
||||||
'full_name': {
|
'full_name': {
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
'minlength': 3,
|
'minlength': 1,
|
||||||
'maxlength': 128,
|
'maxlength': 128,
|
||||||
'required': True,
|
'required': True,
|
||||||
},
|
},
|
||||||
|
@ -7,7 +7,7 @@ from bson import ObjectId
|
|||||||
from flask import g
|
from flask import g
|
||||||
|
|
||||||
from common_test_class import (AbstractPillarTest, TEST_EMAIL_ADDRESS, BLENDER_ID_TEST_USERID,
|
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):
|
class BlenderIdSubclientTest(AbstractPillarTest):
|
||||||
@ -15,6 +15,22 @@ class BlenderIdSubclientTest(AbstractPillarTest):
|
|||||||
def test_store_scst_new_user(self):
|
def test_store_scst_new_user(self):
|
||||||
self._common_user_test(201)
|
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
|
@responses.activate
|
||||||
def test_store_scst_existing_user(self):
|
def test_store_scst_existing_user(self):
|
||||||
# Make sure the user exists in our database.
|
# 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'])
|
self.assertEqual(db_user['_id'], g.current_user['user_id'])
|
||||||
|
|
||||||
def _common_user_test(self, expected_status_code, scst=TEST_SUBCLIENT_TOKEN,
|
def _common_user_test(self, expected_status_code, scst=TEST_SUBCLIENT_TOKEN,
|
||||||
expected_full_name=TEST_FULL_NAME):
|
expected_full_name=TEST_FULL_NAME,
|
||||||
self.mock_blenderid_validate_happy()
|
mock_happy_blender_id=True):
|
||||||
|
if mock_happy_blender_id:
|
||||||
|
self.mock_blenderid_validate_happy()
|
||||||
|
|
||||||
subclient_id = self.app.config['BLENDER_ID_SUBCLIENT_ID']
|
subclient_id = self.app.config['BLENDER_ID_SUBCLIENT_ID']
|
||||||
resp = self.client.post('/blender_id/store_scst',
|
resp = self.client.post('/blender_id/store_scst',
|
||||||
data={'user_id': BLENDER_ID_TEST_USERID,
|
data={'user_id': BLENDER_ID_TEST_USERID,
|
||||||
'subclient_id': subclient_id,
|
'subclient_id': subclient_id,
|
||||||
'token': scst})
|
'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': '...'}
|
user_info = json.loads(resp.data) # {'status': 'success', 'subclient_user_id': '...'}
|
||||||
self.assertEqual('success', user_info['status'])
|
self.assertEqual('success', user_info['status'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user