forked from RedhawkSDR/rest-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent.py
More file actions
113 lines (91 loc) · 3.8 KB
/
component.py
File metadata and controls
113 lines (91 loc) · 3.8 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
#
# 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/{ID}/components portion of the REST API
"""
from pyrest import Application
from base import JsonTests
from defaults import Default
class ComponentTests(JsonTests):
def setUp(self):
super(ComponentTests, self).setUp()
json, resp = self._json_request(
'/domains/%s/applications' % Default.DOMAIN_NAME,
200,
'POST',
{'name': Default.WAVEFORM}
)
self.assertTrue('launched' in json)
self.base_url = '/domains/%s/applications/%s' % (Default.DOMAIN_NAME, json['launched'])
json, resp = self._json_request(self.base_url, 200)
self.assertList(json, 'components')
self.assertTrue(json['components'])
self.components = json['components']
def tearDown(self):
self._json_request(
self.base_url,
200,
'DELETE'
)
super(ComponentTests, self).tearDown()
def _get_comps(self):
pass
def test_list(self):
json, resp = self._json_request(self.base_url + '/components', 200)
self.assertIdList(json, 'components')
self.assertEquals(self.components, json['components'])
def test_info(self):
comp_id = self.components[0]['id']
json, resp = self._json_request('%s/components/%s' % (self.base_url, comp_id), 200)
self.assertList(json, 'ports')
self.assertAttr(json, 'id', comp_id)
self.assertAttr(json, 'name', Default.COMPONENT)
self.assertList(json, 'properties')
self.assertProperties(json['properties'])
def test_not_found(self):
json, resp = self._json_request('%s/components/ggsdfgfdg' % self.base_url, 404)
self._resource_not_found(json)
def test_properties(self):
comp_id = self.components[0]['id']
json, resp = self._json_request('%s/components/%s' % (self.base_url, comp_id), 200)
properties = json['properties']
json, resp = self._json_request("%s/components/%s/properties" % (self.base_url, comp_id), 200)
self.assertList(json, 'properties')
self.assertEquals(properties, json['properties'])
prop = None
for p in json['properties']:
if p['id'] == Default.COMPONENT_PROPERTY:
prop = p
self.assertEquals(prop['value'], Default.COMPONENT_PROPERTY_VALUE)
# Configure
json, resp = self._json_request(
"%s/components/%s/properties" % (self.base_url, comp_id),
200,
'PUT',
{'properties': [
{'id': Default.COMPONENT_PROPERTY, 'value': Default.COMPONENT_PROPERTY_CHANGE}
]}
)
json, resp = self._json_request("%s/components/%s/properties" % (self.base_url, comp_id), 200)
prop = None
for p in json['properties']:
if p['id'] == Default.COMPONENT_PROPERTY:
prop = p
self.assertEquals(prop['value'], Default.COMPONENT_PROPERTY_CHANGE)