我正在使用Django Rest Framework,我正在尝试在views.py文件中编写api方法的单元测试。这是http://www.django-rest-framework.org/api-guide/testing/#example给出一个例子但我不知道为api视图编写单元测试获取和删除 以下是我的api观点:
views.py
@api_view(['GET'])
def getAllCustomers(request):
if request.method == 'GET':
k = Customer.objects.all()
serializer = CustomerSerializer(k, many=True)
return Response(serializer.data)
@api_view(['DELETE'])
def deleteCustomer(request, pk):
try:
k = Customer.objects.get(pk=pk)
except Customer.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'DELETE':
k.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
URLS.PY
url(r'^Customer/$', getAllCustomers, name='getAllCustomers'),
url(r'^Customer/del/(?P<pk>[0-9]+)$', deleteCustomer, name='deleteCustomer'),
感谢所有人!