forked from RedhawkSDR/rest-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.py
More file actions
127 lines (102 loc) · 4.22 KB
/
application.py
File metadata and controls
127 lines (102 loc) · 4.22 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
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
#
# This file is protected by Copyright. Please refer to the COPYRIGHT file
# distributed with this source distribution.
#
# This file is part of REDHAWK rest-python.
#
# REDHAWK rest-python is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# REDHAWK rest-python is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
"""
Tornado tests for the /domain/{NAME}/applications portion of the REST API
"""
import tornado
from base import JsonTests
from defaults import Default
from model.redhawk import Redhawk
class ApplicationTests(JsonTests):
def setUp(self):
super(ApplicationTests, self).setUp();
self.redhawk = Redhawk()
def tearDown(self):
# kill SigTest waveforms
dom = self.redhawk._get_domain(Default.DOMAIN_NAME)
apps = dom.find_app()
for app in apps:
if app.name.startswith(Default.WAVEFORM):
app.releaseObject()
super(ApplicationTests, self).tearDown();
@tornado.gen.coroutine
def _get_applications(self):
url = '/domains/'+Default.DOMAIN_NAME
json, resp = yield self._async_json_request(url, 200)
self.assertTrue('applications' in json)
raise tornado.gen.Return((url, json['applications']))
@tornado.gen.coroutine
def _launch(self, name):
json, resp = yield self._async_json_request(
'/domains/'+Default.DOMAIN_NAME+'/applications',
200,
'POST',
{'name': name}
)
self.assertTrue('launched' in json)
self.assertTrue('applications' in json)
self.assertTrue(json['launched'] in [x['id'] for x in json['applications']])
raise tornado.gen.Return(json['launched'])
@tornado.gen.coroutine
def _release(self, wf_id):
json, resp = yield self._async_json_request(
'/domains/'+Default.DOMAIN_NAME+'/applications/'+wf_id,
200,
'DELETE'
)
self.assertAttr(json, 'released', wf_id)
self.assertTrue('applications' in json)
self.assertFalse(json['released'] in json['applications'])
raise tornado.gen.Return(resp)
@tornado.testing.gen_test
def test_launch_release(self):
'''
This test checks that a launched waveform does in-fact exist in the
applications endpoint as well as is removed once released.
'''
wf_id = yield self._launch(Default.WAVEFORM)
url, applications = yield self._get_applications()
self.assertTrue(any([Default.WAVEFORM in x['name'] for x in applications]))
yield self._release(wf_id)
@tornado.testing.gen_test
def test_list(self):
url = '/domains/' + Default.DOMAIN_NAME
json, resp = yield self._async_json_request(url, 200)
self.assertTrue('waveforms' in json)
self.assertTrue(isinstance(json['waveforms'], list))
for app in json['waveforms']:
self.assertTrue('sad' in app)
self.assertTrue('name' in app)
self.assertIdList(json, 'applications')
@tornado.testing.gen_test
def test_info(self):
wf_id = yield self._launch(Default.WAVEFORM)
url = '/domains/%s/applications/%s' % (Default.DOMAIN_NAME, wf_id)
json, resp = yield self._async_json_request(url, 200)
self.assertList(json, 'ports')
self.assertList(json, 'components')
self.assertTrue('name' in json)
self.assertAttr(json, 'id', wf_id)
self.assertList(json, 'properties')
self.assertProperties(json['properties'])
@tornado.testing.gen_test
def test_not_found(self):
url = '/domains/%s/applications/adskfhsdhfasdhjfhsd' %Default.DOMAIN_NAME
json, resp = yield self._async_json_request(url, 404)