如何为Django Rest Framework编写一个简单的测试用例?

时间:2018-01-09 18:50:17

标签: django django-rest-framework

我将如何为此编写一个简单的单元测试:

http://server_ip:port_number/api/v1/package/

这是我的设置:

models.py

class Package(models.Model):
    name = models.CharField(max_length=255, unique=True)

    def __str__(self):
        return self.name

serializers.py

class PackageSerializer(serializers.ModelSerializer):
    class Meta:
        model = Package
        fields = ('name',)

views.py

class PackageViewSet(viewsets.ReadOnlyModelViewSet):
    serializer_class = PackageSerializer
    queryset = Package.objects.all()
    lookup_field = 'name'

urls.py

router = routers.DefaultRouter()
router.register(r'package', views.PackageViewSet)

urlpatterns = [
    url(r'^api/v1/', include(router.urls)),
]

0 个答案:

没有答案