django_tests.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:apm-agent-python 作者: elastic 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号