ó
ù2¢\c           @   s¿   d  Z  d d l Z d d l m Z d d l m Z d d l m Z d d l	 m
 Z
 m Z m Z m Z y d d l m Z Wn! e k
 r› d d l m Z n Xd „  Z d	 e f d
 „  ƒ  YZ d S(   s   Test the bundlers API.iÿÿÿÿN(   t   join(   t   NotebookTestBase(   t   write(   t   new_notebookt   new_markdown_cellt   new_code_cellt
   new_output(   t   patchc         C   s   |  j  | d ƒ d S(   s*   Bundler test stub. Echo the notebook path.t   pathN(   t   finish(   t   handlert   model(    (    sF   lib/python2.7/site-packages/notebook/bundler/tests/test_bundler_api.pyt   bundle   s    t   BundleAPITestc           B   sJ   e  Z d  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s!   Test the bundlers web service APIc      	   C   sº   t  t |  ƒ j ƒ  |  j } t ƒ  } | j j t d ƒ ƒ t d d ƒ } | j	 j t
 d d d d ƒ ƒ | j j | ƒ t j t | d ƒ d	 d
 d ƒ } t | | d d ƒWd QXd S(   ss   Make a test notebook. Borrowed from nbconvert test. Assumes the class
        teardown will clean it up in the end.u   Created by testt   sourceu
   print(2*6)t   output_typet   streamt   textu   12s   testnb.ipynbt   wt   encodings   utf-8t   versioni   N(   t   superR   t   setup_classt   notebook_dirR   t   cellst   appendR   R   t   outputsR   t   iot   opent   pjoinR   (   t   clst   nbdirt   nbt   cc1t   f(    (    sF   lib/python2.7/site-packages/notebook/bundler/tests/test_bundler_api.pyR      s    		c         C   s<   |  j  d d ƒ } |  j | j d ƒ |  j d | j ƒ d S(   s7   Should respond with 400 error about missing bundler argt   GETs   bundle/fake.ipynbi  s   Missing argument bundlerN(   t   requestt   assertEqualt   status_codet   assertInR   (   t   selft   resp(    (    sF   lib/python2.7/site-packages/notebook/bundler/tests/test_bundler_api.pyt   test_missing_bundler_arg,   s    c         C   sI   |  j  d d d i d d 6ƒ} |  j | j d ƒ |  j d | j ƒ d S(	   s4   Shoudl respond with 404 error about missing notebookR#   s   bundle/fake.ipynbt   paramst   fake_bundlert   bundleri”  s	   Not FoundN(   R$   R%   R&   R'   R   (   R(   R)   (    (    sF   lib/python2.7/site-packages/notebook/bundler/tests/test_bundler_api.pyt   test_notebook_not_found2   s    c         C   sI   |  j  d d d i d d 6ƒ} |  j | j d ƒ |  j d | j ƒ d S(	   s4   Should respond with 400 error about disabled bundlerR#   s   bundle/testnb.ipynbR+   R,   R-   i  s    Bundler fake_bundler not enabledN(   R$   R%   R&   R'   R   (   R(   R)   (    (    sF   lib/python2.7/site-packages/notebook/bundler/tests/test_bundler_api.pyt   test_bundler_not_enabled9   s    c         C   s{   t  d ƒ C } i d d 6| _ |  j d d d i d d 6ƒ} | j d ƒ Wd	 QX|  j | j d
 ƒ |  j d | j ƒ d	 S(   sB   Should respond with 500 error about failure to load bundler modules4   notebook.bundler.handlers.BundlerHandler.get_bundlert   fake_modulet   module_nameR#   s   bundle/testnb.ipynbR+   R,   R-   Niô  s%   Could not import bundler fake_bundler(   R   t   return_valueR$   t   assert_called_withR%   R&   R'   R   (   R(   t   mockR)   (    (    sF   lib/python2.7/site-packages/notebook/bundler/tests/test_bundler_api.pyt   test_bundler_import_error@   s    c         C   s{   t  d ƒ C } i d d 6| _ |  j d d d i d d 6ƒ} | j d ƒ Wd	 QX|  j | j d
 ƒ |  j d | j ƒ d	 S(   s9   Should respond with 200 and output from test bundler stubs4   notebook.bundler.handlers.BundlerHandler.get_bundlers'   notebook.bundler.tests.test_bundler_apiR1   R#   s   bundle/testnb.ipynbR+   t   stub_bundlerR-   NiÈ   s   testnb.ipynb(   R   R2   R$   R3   R%   R&   R'   R   (   R(   R4   R)   (    (    sF   lib/python2.7/site-packages/notebook/bundler/tests/test_bundler_api.pyt   test_bundler_invokeJ   s    (
   t   __name__t
   __module__t   __doc__t   classmethodR   R*   R.   R/   R5   R7   (    (    (    sF   lib/python2.7/site-packages/notebook/bundler/tests/test_bundler_api.pyR      s   				
(   R:   R   t   os.pathR    R   t   notebook.tests.launchnotebookR   t   nbformatR   t   nbformat.v4R   R   R   R   t   unittest.mockR   t   ImportErrorR4   R   R   (    (    (    sF   lib/python2.7/site-packages/notebook/bundler/tests/test_bundler_api.pyt   <module>   s   "	