Merge branch 'master' into 2955-fail-orphan-jobs
[arvados.git] / sdk / python / tests / test_websockets.py
1 import run_test_server
2 import unittest
3 import arvados
4 import arvados.events
5 import time
6
7 class WebsocketTest(unittest.TestCase):
8     def setUp(self):
9         run_test_server.run(websockets=True)
10
11     def on_event(self, ev):
12         if self.state == 1:
13             self.assertEqual(200, ev['status'])
14             self.state = 2
15         elif self.state == 2:
16             self.assertEqual(self.h[u'uuid'], ev[u'object_uuid'])
17             self.state = 3
18         elif self.state == 3:
19             self.fail()
20
21     def runTest(self):
22         self.state = 1
23
24         run_test_server.authorize_with("admin")
25         api = arvados.api('v1', cache=False)
26         arvados.events.subscribe(api, [['object_uuid', 'is_a', 'arvados#human']], lambda ev: self.on_event(ev))
27         time.sleep(1)
28         self.h = api.humans().create(body={}).execute()
29         time.sleep(1)
30
31     def tearDown(self):
32         run_test_server.stop()