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
168 lines (133 loc) · 5.89 KB
/
application.py
File metadata and controls
168 lines (133 loc) · 5.89 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
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
#
# 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 pprint
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
url = '/domains/'+Default.DOMAIN_NAME
json, resp = self._json_request(url, 200)
if 'applications' not in json:
json['applications'] = []
for a in json['applications']:
if a['name'].startswith('SigTest'):
self._json_request(
'/domains/'+Default.DOMAIN_NAME+'/applications/'+a['id'],
200,
'DELETE'
)
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):
url, applications = yield self._get_applications()
json, resp = yield self._async_json_request(url+'/applications', 200)
self.assertTrue('waveforms' in json)
self.assertTrue(Default.WAVEFORM in [x['name'] for x in json['waveforms']])
wf_id = yield self._launch(Default.WAVEFORM)
yield self._release(wf_id)
@tornado.testing.gen_test
def test_list(self):
url, applications = yield self._get_applications()
json, resp = yield self._async_json_request(url+'/applications', 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')
self.assertEquals(applications, 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')
# TODO: self.assertProperties(json['properties'])
@tornado.testing.gen_test
def test_detect_new_applications(self):
yield [ self.detect_new_applications() for x in xrange(10) ]
@tornado.gen.coroutine
def detect_new_applications(self):
'Test when an application started'
url, apps = yield self._get_applications()
# start a new app
id = yield self.redhawk.launch_application(Default.DOMAIN_NAME, Default.WAVEFORM)
# yield self._async_sleep(.5)
# ensure it exists in the application
url, apps2 = yield self._get_applications()
if id not in (a['id'] for a in apps2):
self.fail("Expecting %s in domain %s" % (id, Default.DOMAIN_NAME))
# if (len(apps)+1 != len(apps2)):
# self.fail("Expecting one additional app %s %s" % (apps, apps2))
# now release it
yield self.redhawk.release_application(Default.DOMAIN_NAME, id)
# ensure it is missing in the application list
url, apps3 = yield self._get_applications()
if id in (a['id'] for a in apps3):
self.fail("Not Expecting %s in domain %s" % (id, Default.DOMAIN_NAME))
# if (len(apps) != len(apps3)):
# self.fail("Expecting same number of apps %s %s" % (apps, apps3))
@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)
self._resource_not_found(json)