extensions-website/users/tests/util.py
Anna Sirota 9dec441f02 Blender ID: update username and avatar using webhook payload
Instead of calling Blender ID to get current username and avatar,
just read webhook's `nickname` and `avatar_url` to update the profile.
2024-05-31 17:09:52 +02:00

51 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.conf import settings
from django.contrib.auth import get_user_model
import responses
User = get_user_model()
def mock_blender_id_responses() -> None:
"""Set up mock responses of Blender ID service."""
base_url = settings.BLENDER_ID['BASE_URL']
responses.add(
responses.GET,
f'{base_url}api/badges/2',
status=200,
json={
'user_id': 2,
'badges': {
'cloud_demo': {
'label': 'Blender Studio',
'description': 'Blender Studio free account',
'image': f'{base_url}media/badges/badge_cloud.png',
'image_width': 256,
'image_height': 256,
},
},
},
)
responses.add(
responses.GET,
f'{base_url}api/me',
json={
'id': 2,
'full_name': 'ane oe',
'email': 'jane@example.com',
'nickname': 'anedoe',
# N.B.: roles format here differs from one in user-modified webhook payload.
'roles': {
'dev_core': True,
'cloud_has_subscription': True,
'cloud_subscriber': True,
},
},
)
with open('common/static/common/images/blank-profile-pic.png', 'rb') as out:
responses.add(
responses.GET,
f'{base_url}media/avatar/fo/ob/foobar_128x128.jpg',
body=out,
stream=True,
)