3 from __future__ import absolute_import, print_function
4 from future import standard_library
9 import arvnodeman.status as status
10 import arvnodeman.config as config
13 class TestServer(object):
15 cfg = config.NodeManagerConfig()
16 cfg.set('Manage', 'port', '0')
17 cfg.set('Manage', 'address', '127.0.0.1')
18 self.srv = status.Server(cfg)
20 addr, port = self.srv.server_address
21 self.srv_base = 'http://127.0.0.1:'+str(port)
24 def __exit__(self, exc_type, exc_value, traceback):
27 def get_status_response(self):
28 return requests.get(self.srv_base+'/status.json')
31 return self.get_status_response().json()
34 class StatusServerUpdates(unittest.TestCase):
35 def test_updates(self):
36 with TestServer() as srv:
38 status.tracker.update({'nodes_'+str(n): n})
39 r = srv.get_status_response()
40 self.assertEqual(200, r.status_code)
41 self.assertEqual('application/json', r.headers['content-type'])
43 self.assertEqual(n, resp['nodes_'+str(n)])
44 self.assertEqual(1, resp['nodes_1'])
47 class StatusServerDisabled(unittest.TestCase):
48 def test_config_disabled(self):
49 cfg = config.NodeManagerConfig()
50 cfg.set('Manage', 'port', '-1')
51 cfg.set('Manage', 'address', '127.0.0.1')
52 self.srv = status.Server(cfg)
54 self.assertFalse(self.srv.enabled)
55 self.assertFalse(getattr(self.srv, '_thread', False))