##// END OF EJS Templates
ensure test_no_kernels runs first...
MinRK -
Show More
@@ -1,54 +1,54 b''
1 """Test the kernels service API."""
1 """Test the kernels service API."""
2
2
3
3
4 import os
4 import os
5 import sys
5 import sys
6 import json
6 import json
7
7
8 import requests
8 import requests
9
9
10 from IPython.html.utils import url_path_join
10 from IPython.html.utils import url_path_join
11 from IPython.html.tests.launchnotebook import NotebookTestBase
11 from IPython.html.tests.launchnotebook import NotebookTestBase
12
12
13
13
14 class KernelAPITest(NotebookTestBase):
14 class KernelAPITest(NotebookTestBase):
15 """Test the kernels web service API"""
15 """Test the kernels web service API"""
16
16
17 def base_url(self):
17 def base_url(self):
18 return url_path_join(super(KernelAPITest,self).base_url(), 'api/kernels')
18 return url_path_join(super(KernelAPITest,self).base_url(), 'api/kernels')
19
19
20 def mkkernel(self):
20 def mkkernel(self):
21 r = requests.post(self.base_url())
21 r = requests.post(self.base_url())
22 return r.json()
22 return r.json()
23
23
24 def test_no_kernels(self):
24 def test__no_kernels(self):
25 """Make sure there are no kernels running at the start"""
25 """Make sure there are no kernels running at the start"""
26 url = self.base_url()
26 url = self.base_url()
27 r = requests.get(url)
27 r = requests.get(url)
28 self.assertEqual(r.json(), [])
28 self.assertEqual(r.json(), [])
29
29
30 def test_main_kernel_handler(self):
30 def test_main_kernel_handler(self):
31 # POST request
31 # POST request
32 r = requests.post(self.base_url())
32 r = requests.post(self.base_url())
33 data = r.json()
33 data = r.json()
34 assert isinstance(data, dict)
34 assert isinstance(data, dict)
35
35
36 # GET request
36 # GET request
37 r = requests.get(self.base_url())
37 r = requests.get(self.base_url())
38 assert isinstance(r.json(), list)
38 assert isinstance(r.json(), list)
39 self.assertEqual(r.json()[0], data['id'])
39 self.assertEqual(r.json()[0], data['id'])
40
40
41 def test_kernel_handler(self):
41 def test_kernel_handler(self):
42 # GET kernel with id
42 # GET kernel with id
43 data = self.mkkernel()
43 data = self.mkkernel()
44 url = self.base_url() +'/' + data['id']
44 url = self.base_url() +'/' + data['id']
45 r = requests.get(url)
45 r = requests.get(url)
46 assert isinstance(r.json(), dict)
46 assert isinstance(r.json(), dict)
47 self.assertIn('id', r.json())
47 self.assertIn('id', r.json())
48 self.assertEqual(r.json()['id'], data['id'])
48 self.assertEqual(r.json()['id'], data['id'])
49
49
50 # DELETE kernel with id
50 # DELETE kernel with id
51 r = requests.delete(url)
51 r = requests.delete(url)
52 self.assertEqual(r.status_code, 204)
52 self.assertEqual(r.status_code, 204)
53 r = requests.get(self.base_url())
53 r = requests.get(self.base_url())
54 self.assertEqual(r.json(), []) No newline at end of file
54 self.assertEqual(r.json(), [])
General Comments 0
You need to be logged in to leave comments. Login now