##// END OF EJS Templates
Backport PR #8196: DEV: Allow supplying jinja vars from python config....
Backport PR #8196: DEV: Allow supplying jinja vars from python config. This PR allows the user to specify a dictionary of values to `NotebookApp.jinja_template_vars` whose values are made available in the jinja templating environment. This is primarily useful in conjunction with the `get_body_data` javascript function to allow programmatic access to Python-specified values from Javascript. An example of where this is useful is when you want to use different constants in Javascript based on a deployment environment; this allows you to write code in your ipython_notebook_config that looks like: ``` env = os.environ['DEPLOYMENT_ENV'] if env == 'DEV': template_vars = dev_template_vars ...

File last commit:

r13837:c5bbb0d0
r21455:37a99411
Show More
test_nbconvert_api.py
30 lines | 1020 B | text/x-python | PythonLexer
import requests
from IPython.html.utils import url_path_join
from IPython.html.tests.launchnotebook import NotebookTestBase
class NbconvertAPI(object):
"""Wrapper for nbconvert API calls."""
def __init__(self, base_url):
self.base_url = base_url
def _req(self, verb, path, body=None, params=None):
response = requests.request(verb,
url_path_join(self.base_url, 'api/nbconvert', path),
data=body, params=params,
)
response.raise_for_status()
return response
def list_formats(self):
return self._req('GET', '')
class APITest(NotebookTestBase):
def setUp(self):
self.nbconvert_api = NbconvertAPI(self.base_url())
def test_list_formats(self):
formats = self.nbconvert_api.list_formats().json()
self.assertIsInstance(formats, dict)
self.assertIn('python', formats)
self.assertIn('html', formats)
self.assertEqual(formats['python']['output_mimetype'], 'text/x-python')