def test_user_info_with_custom_user(django_elasticapm_client, client):
with override_settings(AUTH_USER_MODEL='testapp.MyUser'):
from django.contrib.auth import get_user_model
MyUser = get_user_model()
user = MyUser(my_username='admin')
user.set_password('admin')
user.save()
assert client.login(username='admin', password='admin')
with pytest.raises(Exception):
client.get(reverse('elasticapm-raise-exc'))
assert len(django_elasticapm_client.events) == 1
event = django_elasticapm_client.events.pop(0)['errors'][0]
assert 'user' in event['context']
user_info = event['context']['user']
assert 'is_authenticated' in user_info
assert user_info['is_authenticated']
assert 'username' in user_info
assert user_info['username'] == 'admin'
assert 'email' not in user_info
评论列表
文章目录