[973924]: / qiita_pet / test / test_upload.py

Download this file

84 lines (66 with data), 3.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -----------------------------------------------------------------------------
# Copyright (c) 2014--, The Qiita Development Team.
#
# Distributed under the terms of the BSD 3-clause License.
#
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------
from unittest import main
from requests import Request
from six import StringIO
from time import sleep
from qiita_pet.test.tornado_test_base import TestHandlerBase
class TestStudyUploadFileHandler(TestHandlerBase):
def test_get_exists(self):
response = self.get('/study/upload/1')
self.assertEqual(response.code, 200)
def test_get_no_exists(self):
response = self.get('/study/upload/245')
self.assertEqual(response.code, 404)
class TestUploadFileHandler(TestHandlerBase):
def test_get(self):
response = self.get('/upload/')
self.assertEqual(response.code, 400)
class TestStudyUploadViaRemote(TestHandlerBase):
def _setup_request(self, data):
# setting up things to test by sending POST variables and a file
# taken from: https://bit.ly/2CpZiZn
prepare = Request(
url='https://localhost/',
files={'ssh-key': StringIO('Test key.')}, data=data).prepare()
headers = {"Content-Type": prepare.headers.get('Content-Type')}
body = prepare.body
return headers, body
def test_post(self):
data = {'remote-request-type': 'list', 'inputURL': 'scp-url'}
headers, body = self._setup_request(data)
# study doesn't exist
response = self.post(
'/study/upload/remote/100', data=body, headers=headers)
self.assertEqual(response.code, 404)
# create a successful list job
response = self.post(
'/study/upload/remote/1', data=body, headers=headers)
self.assertEqual(response.code, 200)
self.assertEqual(response.body.decode('ascii'),
'{"status": "success", "message": ""}')
# create a successful list job
data = {'remote-request-type': 'transfer', 'inputURL': 'scp-url'}
headers, body = self._setup_request(data)
response = self.post(
'/study/upload/remote/1', data=body, headers=headers)
self.assertEqual(response.code, 200)
self.assertEqual(response.body.decode('ascii'),
'{"status": "success", "message": ""}')
# sleep to wait for jobs to finish, no need to check for it's status
sleep(5)
# jobs with bad Parameters
data = {'remote-request-type': 'error', 'inputURL': 'scp-url'}
headers, body = self._setup_request(data)
response = self.post(
'/study/upload/remote/1', data=body, headers=headers)
self.assertEqual(response.code, 200)
self.assertEqual(response.body.decode('ascii'), '{"status": "error", '
'"message": "Not a valid method"}')
if __name__ == "__main__":
main()