how to get request object in django unit testing?

前端 未结 5 763
悲&欢浪女
悲&欢浪女 2020-12-12 22:15

I have a function as

def getEvents(eid, request):
    ......

Now I want to write unit test for the above function separately (without calli

5条回答
  •  鱼传尺愫
    2020-12-12 22:37

    You can use django test client

    from django.test import Client
    c = Client()
    response = c.post('/login/', {'username': 'john', 'password': 'smith'})
    response.status_code
    response = c.get('/customer/details/')
    response.content
    

    for more details
    https://docs.djangoproject.com/en/1.11/topics/testing/tools/#overview-and-a-quick-example

提交回复
热议问题