forked from RedhawkSDR/rest-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathport.py
More file actions
executable file
·92 lines (75 loc) · 3.3 KB
/
port.py
File metadata and controls
executable file
·92 lines (75 loc) · 3.3 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
#!/usr/bin/env python
#
# 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/.
#
# system imports
import unittest
import json
import logging
import time
import threading
from functools import partial
# tornado imports
import tornado
import tornado.testing
from tornado.testing import AsyncHTTPTestCase, LogTrapTestCase
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
from tornado import websocket, gen
from base import JsonAssertions
# application imports
from pyrest import Application
# all method returning suite is required by tornado.testing.main()
def all():
return unittest.TestLoader().loadTestsFromModule(__import__(__name__))
class PortTests(AsyncHTTPTestCase, LogTrapTestCase, JsonAssertions):
# def setUp(self):
# super(RESTfulTest, self).setUp()
# rtl_app.RTLApp('REDHAWK_DEV').stop_survey()
def get_app(self):
return Application(debug=True, _ioloop=self.io_loop)
@tornado.testing.gen_test
def test_domain_get_instance(self):
response = yield AsyncHTTPClient(self.io_loop).fetch(self.get_url('/redhawk/rest/domains/REDHAWK_DEV'))
self.assertEquals(200, response.code)
data = json.loads(response.body)
for name in ('applications', 'properties', 'deviceManagers', 'id', 'name'):
self.assertTrue(name in data, "json missing %s" % name)
def test_domain_get_failure(self):
# callback must be used to get response to non-200 HTTPResponse
AsyncHTTPClient(self.io_loop).fetch(self.get_url('/redhawk/rest/domains/REDHAWK_DEV_FOO'), self.stop)
response = self.wait()
self.assertEquals(404, response.code)
pdata = json.loads(response.body)
logging.debug("Found port data %s", pdata)
# FIXME: Check error response
@tornado.testing.gen_test
def test_application_port_get(self):
# get a list of waveforms
response = yield AsyncHTTPClient(self.io_loop).fetch(self.get_url('/redhawk/rest/domains/REDHAWK_DEV/applications'))
self.assertEquals(200, response.code)
data = json.loads(response.body)
for wf in data['applications']:
portr = yield AsyncHTTPClient(self.io_loop).fetch(self.get_url('/redhawk/rest/domains/REDHAWK_DEV/applications/%s/ports' % wf['id']))
self.assertEquals(200, portr.code)
pdata = json.loads(portr.body)
# FIXME: Test against a applications with ports
logging.debug("Found port data %s", pdata)
break
else:
self.fail('Unable to find any applications')