Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신은섭(Shin Eun Seop)
/
2018-1-d.cloud
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
10
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
신은섭(Shin Eun Seop)
2018-05-10 13:56:50 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ab23721d1bcbddc4fdd21019139d42596c47a07f
ab23721d
1 parent
b6bfe00a
fix test code
kairos03/2018-1-d.cloud#8 kairos03/2018-1-d.cloud#10
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
4 deletions
dcloud/restful/tests.py
dcloud/restful/views.py
dcloud/restful/tests.py
View file @
ab23721
from
rest_framework.test
import
APITestCase
from
django.urls
import
reverse
from
rest_framework
import
status
from
restful.models
import
File
class
UploadFileTestCase
(
APITestCase
):
def
setup
(
self
):
class
FileListTestCase
(
APITestCase
):
def
setUp
(
self
):
self
.
tearDown
()
def
tearDown
(
self
):
...
...
@@ -15,4 +17,37 @@ class UploadFileTestCase(APITestCase):
data
=
{
'object_key'
:
'test_object_key'
}
response
=
self
.
client
.
post
(
url
,
data
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
self
.
assertEqual
(
File
.
objects
.
count
(),
1
)
def
test_list
(
self
):
url
=
reverse
(
'file-list'
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
class
FileDetailTestCase
(
APITestCase
):
def
setUp
(
self
):
self
.
tearDown
()
File
.
objects
.
create
(
object_key
=
'test_object'
)
def
tearDown
(
self
):
File
.
objects
.
all
()
.
delete
()
def
test_delete
(
self
):
url
=
reverse
(
'file-detail'
,
kwargs
=
{
'pk'
:
1
})
response
=
self
.
client
.
delete
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_204_NO_CONTENT
)
def
test_update
(
self
):
url
=
reverse
(
'file-detail'
,
kwargs
=
{
'pk'
:
1
})
response
=
self
.
client
.
put
(
url
,
{
"object_key"
:
"test_update"
})
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_204_NO_CONTENT
)
def
test_retrieve
(
self
):
url
=
reverse
(
'file-detail'
,
kwargs
=
{
'pk'
:
1
})
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
\ No newline at end of file
...
...
dcloud/restful/views.py
View file @
ab23721
...
...
@@ -38,14 +38,14 @@ class FileDetail(APIView):
def
get
(
self
,
request
,
pk
,
format
=
None
):
file
=
self
.
get_object
(
pk
)
serializer
=
FileSerializer
(
file
)
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
def
put
(
self
,
request
,
pk
,
format
=
None
):
file
=
self
.
get_object
(
pk
)
serializer
=
FileSerializer
(
file
,
data
=
request
.
data
)
if
serializer
.
is_valid
():
serializer
.
save
()
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_204_NO_CONTENT
)
return
Response
(
serializer
.
errors
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
def
delete
(
self
,
request
,
pk
,
format
=
None
):
...
...
Please
register
or
login
to post a comment