Add test for #340

master
Cristi Vijdea 2019-04-01 02:57:45 +03:00
parent 7bb4700003
commit 4014c69689
5 changed files with 114 additions and 4 deletions

View File

@ -1,3 +1,5 @@
from decimal import Decimal
from django.db import models
@ -18,3 +20,19 @@ class TodoYetAnother(models.Model):
class TodoTree(models.Model):
parent = models.ForeignKey('self', on_delete=models.CASCADE, related_name='children', null=True)
title = models.CharField(max_length=50)
class Pack(models.Model):
SIZE_10x20 = Decimal(200.000)
SIZE_10x10 = Decimal(100.000)
SIZE_5x10 = Decimal(50.000)
size_code_choices = (
(SIZE_5x10, '5x10'),
(SIZE_10x10, '10x10'),
(SIZE_10x20, '10x20'),
)
size_code = models.DecimalField(max_digits=7,
decimal_places=3,
choices=size_code_choices,
default=SIZE_10x20)

View File

@ -4,7 +4,7 @@ from django.utils import timezone
from rest_framework import serializers
from rest_framework_recursive.fields import RecursiveField
from .models import Todo, TodoAnother, TodoTree, TodoYetAnother
from .models import Pack, Todo, TodoAnother, TodoTree, TodoYetAnother
class TodoSerializer(serializers.ModelSerializer):
@ -57,3 +57,14 @@ class TodoRecursiveSerializer(serializers.ModelSerializer):
class Meta:
model = TodoTree
fields = ('id', 'title', 'parent', 'parent_id')
class HarvestSerializer(serializers.ModelSerializer):
class Meta:
model = Pack
fields = (
'size_code',
)
read_only_fields = (
'size_code',
)

View File

@ -9,6 +9,7 @@ router.register(r'another', views.TodoAnotherViewSet)
router.register(r'yetanother', views.TodoYetAnotherViewSet)
router.register(r'tree', views.TodoTreeView)
router.register(r'recursive', views.TodoRecursiveView)
router.register(r'harvest', views.HarvestViewSet)
urlpatterns = router.urls

View File

@ -1,11 +1,13 @@
from rest_framework import viewsets
from rest_framework import mixins, permissions, viewsets
from rest_framework.authentication import TokenAuthentication
from rest_framework.generics import RetrieveAPIView
from drf_yasg.utils import swagger_auto_schema
from .models import Todo, TodoAnother, TodoTree, TodoYetAnother
from .models import Pack, Todo, TodoAnother, TodoTree, TodoYetAnother
from .serializer import (
TodoAnotherSerializer, TodoRecursiveSerializer, TodoSerializer, TodoTreeSerializer, TodoYetAnotherSerializer
HarvestSerializer, TodoAnotherSerializer, TodoRecursiveSerializer, TodoSerializer, TodoTreeSerializer,
TodoYetAnotherSerializer
)
@ -75,3 +77,16 @@ class TodoRecursiveView(viewsets.ModelViewSet):
@swagger_auto_schema(responses={200: TodoRecursiveSerializer(many=True)})
def list(self, request, *args, **kwargs):
return super(TodoRecursiveView, self).list(request, *args, **kwargs)
class HarvestViewSet(mixins.ListModelMixin,
mixins.UpdateModelMixin,
viewsets.GenericViewSet):
queryset = Pack.objects.all()
serializer_class = HarvestSerializer
permission_classes = [permissions.IsAuthenticated]
authentication_classes = [TokenAuthentication]
def perform_update(self, serializer):
pass

View File

@ -592,6 +592,60 @@ paths:
description: A unique integer value identifying this todo another.
required: true
type: integer
/todo/harvest/:
get:
operationId: todo_harvest_list
description: ''
parameters: []
responses:
'200':
description: ''
schema:
type: array
items:
$ref: '#/definitions/Harvest'
tags:
- todo
parameters: []
/todo/harvest/{id}/:
put:
operationId: todo_harvest_update
description: ''
parameters:
- name: data
in: body
required: true
schema:
$ref: '#/definitions/Harvest'
responses:
'200':
description: ''
schema:
$ref: '#/definitions/Harvest'
tags:
- todo
patch:
operationId: todo_harvest_partial_update
description: ''
parameters:
- name: data
in: body
required: true
schema:
$ref: '#/definitions/Harvest'
responses:
'200':
description: ''
schema:
$ref: '#/definitions/Harvest'
tags:
- todo
parameters:
- name: id
in: path
description: A unique integer value identifying this pack.
required: true
type: integer
/todo/recursive/:
get:
operationId: todo_recursive_list
@ -1669,6 +1723,17 @@ definitions:
minLength: 1
todo:
$ref: '#/definitions/Todo'
Harvest:
type: object
properties:
size_code:
title: Size code
type: string
enum:
- '50'
- '100'
- '200'
readOnly: true
TodoRecursive:
required:
- title