tests fail because client's request.user is SimpleLazyObject

时间:2019-01-15 18:30:22

标签: python django django-views

The following test code fails because in view_report, request.user is a SimpleLazyObject. How to I prepare the calling client properly to test my views?

class Test_views(TestCase):
    def test_case(self):
        c = Client()
        c.login(username=username,password='password')
        url = reverse('coach:view_report', kwargs={'report_id':13})
        c.get(url,follow=True)

def view_report(request, report_id):    
    current_user = Coach.objects.get(id=request.user.id)

0 个答案:

没有答案