##// END OF EJS Templates
Fix #4777 and #7887...
Fix #4777 and #7887 The function in charge of actually converting cursor offset to CodeMirror line number and character number was actually crashing when the cursor was at the last character (loop until undefined, then access length of variable, which is undefined). This was hiding a bug in which when you would completer to a single completion pressing tab after as-you-type filtering, the completion would be completed twice. The logic that was supposed to detect whether or not all completions had a common prefix was actually faulty as the common prefix used to be a string but was then changed to an object. Hence the logic to check whether or not there was actually a common prefix was always true, even for empty string, leading to the deletion of the line (replace by '') in some cases.

File last commit:

r18707:dc68aaa5
r20538:ae7f6d6a
Show More
test_config_api.py
68 lines | 2.3 KiB | text/x-python | PythonLexer
# coding: utf-8
"""Test the config webservice API."""
import json
import requests
from IPython.html.utils import url_path_join
from IPython.html.tests.launchnotebook import NotebookTestBase
class ConfigAPI(object):
"""Wrapper for notebook API calls."""
def __init__(self, base_url):
self.base_url = base_url
def _req(self, verb, section, body=None):
response = requests.request(verb,
url_path_join(self.base_url, 'api/config', section),
data=body,
)
response.raise_for_status()
return response
def get(self, section):
return self._req('GET', section)
def set(self, section, values):
return self._req('PUT', section, json.dumps(values))
def modify(self, section, values):
return self._req('PATCH', section, json.dumps(values))
class APITest(NotebookTestBase):
"""Test the config web service API"""
def setUp(self):
self.config_api = ConfigAPI(self.base_url())
def test_create_retrieve_config(self):
sample = {'foo': 'bar', 'baz': 73}
r = self.config_api.set('example', sample)
self.assertEqual(r.status_code, 204)
r = self.config_api.get('example')
self.assertEqual(r.status_code, 200)
self.assertEqual(r.json(), sample)
def test_modify(self):
sample = {'foo': 'bar', 'baz': 73,
'sub': {'a': 6, 'b': 7}, 'sub2': {'c': 8}}
self.config_api.set('example', sample)
r = self.config_api.modify('example', {'foo': None, # should delete foo
'baz': 75,
'wib': [1,2,3],
'sub': {'a': 8, 'b': None, 'd': 9},
'sub2': {'c': None} # should delete sub2
})
self.assertEqual(r.status_code, 200)
self.assertEqual(r.json(), {'baz': 75, 'wib': [1,2,3],
'sub': {'a': 8, 'd': 9}})
def test_get_unknown(self):
# We should get an empty config dictionary instead of a 404
r = self.config_api.get('nonexistant')
self.assertEqual(r.status_code, 200)
self.assertEqual(r.json(), {})