신은섭(Shin Eun Seop)

add file object_key upload

1 +#!/bin/bash
2 +rm -f db.sqlite3
3 +rm -r restful/migrations
4 +python manage.py makemigrations restful
5 +python manage.py migrate
...@@ -4,13 +4,11 @@ from django.db import models ...@@ -4,13 +4,11 @@ from django.db import models
4 # Create your models here. 4 # Create your models here.
5 class File(models.Model): 5 class File(models.Model):
6 created = models.DateTimeField(auto_now_add=True) 6 created = models.DateTimeField(auto_now_add=True)
7 - modified = models.DateTimeField(auto_now=True) 7 + updated = models.DateTimeField(auto_now=True)
8 - title = models.CharField(max_length=100)
9 object_key = models.CharField(max_length=1025) 8 object_key = models.CharField(max_length=1025)
10 - size = models.IntegerField()
11 # owner = models.ForeignKey('auth.User', related_name='snippets', on_delete=models.CASCADE) 9 # owner = models.ForeignKey('auth.User', related_name='snippets', on_delete=models.CASCADE)
12 10
13 class Meta: 11 class Meta:
14 - ordering = ('title',) 12 + ordering = ('pk',)
15 13
16 14
......
...@@ -3,30 +3,8 @@ from rest_framework import serializers ...@@ -3,30 +3,8 @@ from rest_framework import serializers
3 from restful.models import File 3 from restful.models import File
4 4
5 5
6 -class FileSerializer(serializers.Serializer): 6 +class FileSerializer(serializers.ModelSerializer):
7 - pk = serializers.IntegerField(read_only=True)
8 - created = serializers.DateTimeField(read_only=True)
9 - modified = serializers.DateTimeField(read_only=True)
10 - title = serializers.CharField(max_length=100)
11 - object_key = serializers.CharField(max_length=1025)
12 - size = serializers.IntegerField()
13 7
14 - 8 + class Meta:
15 - def create(self, validated_data): 9 + model = File
16 - """ 10 + fields = ('created', 'updated', 'object_key')
17 - Create and Return new `File` instance. Using validated_data.
18 - """
19 - return File.objects.create(**validated_data)
20 -
21 -
22 - def update(self, instance, validated_data):
23 - """
24 - Update and Return existing `File` instance. Using validated_data.
25 - """
26 - instance.title = validated_data.get('title', instance.title)
27 - instance.object_key = validated_data.get('object_key', instance.object_key)
28 - instance.size = validated_data.get('size', instance.size)
29 - instance.language = validated_data.get('language', instance.language)
30 - instance.style = validated_data.get('style', instance.style)
31 - instance.save()
32 - return instance
......
1 -from django.test import TestCase 1 +from rest_framework.test import APITestCase
2 +from django.urls import reverse
3 +from rest_framework import status
4 +
5 +
6 +class UploadFileTestCase(APITestCase):
7 + def setup(self):
8 + self.tearDown()
9 +
10 + def tearDown(self):
11 + pass
12 +
13 + def test_upload(self):
14 + url = reverse('file-list')
15 + data = {'object_key': 'test_object_key'}
16 + response = self.client.post(url, data)
17 + self.assertEqual(response.status_code, status.HTTP_201_CREATED)
2 18
3 -# Create your tests here.
......
...@@ -3,8 +3,8 @@ from rest_framework.urlpatterns import format_suffix_patterns ...@@ -3,8 +3,8 @@ from rest_framework.urlpatterns import format_suffix_patterns
3 from restful import views 3 from restful import views
4 4
5 urlpatterns = [ 5 urlpatterns = [
6 - url(r'^files/$', views.FileList.as_view()), 6 + url(r'^files/$', views.FileList.as_view(), name='file-list'),
7 - url(r'^files/(?P<pk>[0-9]+)/$', views.FileDetail.as_view()), 7 + url(r'^files/(?P<pk>[0-9]+)/$', views.FileDetail.as_view(), name='file-detail'),
8 ] 8 ]
9 9
10 urlpatterns = format_suffix_patterns(urlpatterns) 10 urlpatterns = format_suffix_patterns(urlpatterns)
...\ No newline at end of file ...\ No newline at end of file
......