extensions-website/users/tests/util.py

57 lines
1.7 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/user/2/avatar',
status=302,
headers={'Location': f'{base_url}media/cache/1c/da/1cda54d605799b1f4b0dc080.jpg'},
)
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,
'http://id.local:8000/media/cache/1c/da/1cda54d605799b1f4b0dc080.jpg',
body=out,
stream=True,
)