-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
189 lines (140 loc) · 8.51 KB
/
tests.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import unittest
import os
from isarest import app
class BaseConverterTestCase(unittest.TestCase):
"""Base test case for testing the converters"""
def setUp(self):
self.app = app.test_client()
self.test_data_zip = open(os.path.join(os.path.dirname(__file__), 'testdata/BII-S-3.zip'), 'rb').read()
self.test_data_json = open(os.path.join(os.path.dirname(__file__), 'testdata/BII-S-3.json'), 'rb').read()
self.test_data_json_zip = open(os.path.join(os.path.dirname(__file__), 'testdata/BII-S-3_json.zip'), 'rb').read()
self.test_sampletab = open(os.path.join(os.path.dirname(__file__), 'testdata/GSB-3.txt'), 'rb').read()
self.test_magetab_zip = open(os.path.join(os.path.dirname(__file__), 'testdata/E-MEXP-31.zip'), 'rb').read()
def tearDown(self):
pass
class TabToJsonConverterTests(BaseConverterTestCase):
def test_convert(self):
response = self.app.post(path='/api/v1/convert/tab-to-json', data=self.test_data_zip,
headers={'Content-Type': 'application/zip'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'application/json')
def test_unsupported_content(self):
response = self.app.post(path='/api/v1/convert/tab-to-json', data=self.test_data_json,
headers={'Content-Type': 'application/json'})
self.assertEqual(response.status_code, 415)
class JsonToTabConverterTests(BaseConverterTestCase):
def test_convert(self):
response = self.app.post(path='/api/v1/convert/json-to-tab', data=self.test_data_json,
headers={'Content-Type': 'application/json'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'application/zip')
def test_unsupported_mimetype(self):
response = self.app.post(path='/api/v1/convert/json-to-tab', data=self.test_data_zip,
headers={'Content-Type': 'application/zip'})
self.assertEqual(response.status_code, 415)
class TabToSraXmlConverterTests(BaseConverterTestCase):
def test_convert(self):
response = self.app.post(path='/api/v1/convert/tab-to-sra', data=self.test_data_zip,
headers={'Content-Type': 'application/zip'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'application/zip')
def test_unsupported_content(self):
response = self.app.post(path='/api/v1/convert/tab-to-sra', data=self.test_data_json,
headers={'Content-Type': 'application/json'})
self.assertEqual(response.status_code, 415)
class JsonToSraXmlConverterTests(BaseConverterTestCase):
def test_convert(self):
response = self.app.post(path='/api/v1/convert/json-to-sra', data=self.test_data_json_zip,
headers={'Content-Type': 'application/zip'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'application/zip')
def test_unsupported_content(self):
response = self.app.post(path='/api/v1/convert/json-to-sra', data=self.test_data_json,
headers={'Content-Type': 'application/json'})
self.assertEqual(response.status_code, 415)
class TabToCedarConverterTests(BaseConverterTestCase):
def test_convert(self):
response = self.app.post(path='/api/v1/convert/tab-to-cedar', data=self.test_data_zip,
headers={'Content-Type': 'application/zip'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'application/json')
def test_unsupported_content(self):
response = self.app.post(path='/api/v1/convert/tab-to-cedar', data=self.test_data_json,
headers={'Content-Type': 'application/json'})
self.assertEqual(response.status_code, 415)
class IsaJsonValidatorTests(BaseConverterTestCase):
def test_validate(self):
response = self.app.post(path='/api/v1/validate/json', data=self.test_data_json,
headers={'Content-Type': 'application/json'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'application/json')
def test_unsupported_content(self):
response = self.app.post(path='/api/v1/validate/json', data=self.test_data_json_zip,
headers={'Content-Type': 'application/zip'})
self.assertEqual(response.status_code, 415)
class IsaTabValidatorTests(BaseConverterTestCase):
def test_validate(self):
response = self.app.post(path='/api/v1/validate/isatab', data=self.test_data_zip,
headers={'Content-Type': 'application/zip'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'application/json')
def test_unsupported_content(self):
response = self.app.post(path='/api/v1/validate/isatab', data=self.test_data_zip,
headers={'Content-Type': 'application/json'})
self.assertEqual(response.status_code, 415)
class ImportMWTests(BaseConverterTestCase):
def test_import_mw2isatab(self):
response = self.app.get(path='/api/v1/import/mw/ST000367')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'application/zip')
def test_unknown_resource(self):
response = self.app.post(path='/api/v1/import/mw/ST0001')
self.assertEqual(response.status_code, 405)
class SampleTabTests(BaseConverterTestCase):
def test_convert_sampletab2isatab(self):
response = self.app.post(path='/api/v1/convert/sampletab-to-isatab', data=self.test_sampletab,
headers={'Content-Type': 'text/tab-separated-values'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'application/zip')
def test_convert_sampletab2json(self):
response = self.app.post(path='/api/v1/convert/sampletab-to-json', data=self.test_sampletab,
headers={'Content-Type': 'text/tab-separated-values'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'application/json')
def test_convert_isatab2sampletab(self):
response = self.app.post(path='/api/v1/convert/isatab-to-sampletab', data=self.test_data_zip,
headers={'Content-Type': 'application/zip'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'text/tab-separated-values')
def test_convert_json2sampletab(self):
response = self.app.post(path='/api/v1/convert/json-to-sampletab', data=self.test_data_json,
headers={'Content-Type': 'application/json'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'text/tab-separated-values')
class MageTabTests(BaseConverterTestCase):
# Comment out teste because of not yet implemented services
#
# def test_convert_magetab2isatab(self):
# response = self.app.post(path='/api/v1/convert/magetab-to-isatab', data=self.test_magetab_zip,
# headers={'Content-Type': 'application/zip'})
# self.assertEqual(response.status_code, 200)
# self.assertEqual(response.mimetype, 'application/zip')
#
def test_convert_magetab2json(self):
response = self.app.post(path='/api/v1/convert/magetab-to-json', data=self.test_magetab_zip,
headers={'Content-Type': 'application/zip'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.mimetype, 'application/json')
#
# def test_convert_isatab2magetab(self):
# response = self.app.post(path='/api/v1/convert/isatab-to-magetab', data=self.test_data_zip,
# headers={'Content-Type': 'application/zip'})
# self.assertEqual(response.status_code, 200)
# self.assertEqual(response.mimetype, 'application/zip')
# def test_convert_json2magetab(self):
# response = self.app.post(path='/api/v1/convert/json-to-magetab', data=self.test_data_json,
# headers={'Content-Type': 'application/json'})
# self.assertEqual(response.status_code, 200)
# self.assertEqual(response.mimetype, 'application/zip')
if __name__ == '__main__':
unittest.main()