신은섭(Shin Eun Seop)

add file object_key upload

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