
    Ib                     l    d 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 ddlmZ d Z G d d	e      Zy
)zTest the bundlers API.    )join)NotebookTestBase)write)new_notebooknew_markdown_cellnew_code_cell
new_output)patchc                 ,    | j                  |d          y)z*Bundler test stub. Echo the notebook path.pathN)finish)handlermodels     I/usr/lib/python3/dist-packages/notebook/bundler/tests/test_bundler_api.pybundler      s    NN5=!    c                   J     e Zd ZdZe fd       Zd Zd Zd Zd Z	d Z
 xZS )BundleAPITestz!Test the bundlers web service APIc                    t         |           | j                  }t               }|j                  j                  t        d             t        d      }|j                  j                  t        dd             |j                  j                  |       t        t        |d      dd	
      5 }t        ||d       ddd       y# 1 sw Y   yxY w)zsMake a test notebook. Borrowed from nbconvert test. Assumes the class
        teardown will clean it up in the end.zCreated by testz
print(2*6))sourcestream12)output_typetexttestnb.ipynbwzutf-8)encoding   )versionN)supersetup_classnotebook_dirr   cellsappendr   r   outputsr	   openpjoinr   )clsnbdirnbcc1f	__class__s        r   r!   zBundleAPITest.setup_class   s     	  ^
)*;<=<0:(FG
%~.%' 	$*+"a#	$ 	$ 	$s   /CCc                     | j                  dd      }| j                  |j                  d       | j                  d|j                         y)z7Should respond with 400 error about missing bundler argGETbundle/fake.ipynb  zMissing argument bundlerNrequestassertEqualstatus_codeassertInr   selfresps     r   test_missing_bundler_argz&BundleAPITest.test_missing_bundler_arg)   s<    ||E#67))3/0$))<r   c                     | j                  ddddi      }| j                  |j                  d       | j                  d|j                         y)	z4Should respond with 404 error about missing notebookr/   r0   bundlerfake_bundlerparamsi  z	Not FoundNr2   r7   s     r   test_notebook_not_foundz%BundleAPITest.test_notebook_not_found/   sJ    ||E#6~.  0))3/k499-r   c                     | j                  ddddi      }| j                  |j                  d       | j                  d|j                         y)	z4Should respond with 400 error about disabled bundlerr/   bundle/testnb.ipynbr<   r=   r>   r1   z Bundler fake_bundler not enabledNr2   r7   s     r   test_bundler_not_enabledz&BundleAPITest.test_bundler_not_enabled6   sK    ||E#8~.  0))3/8$))Dr   c                    t        d      5 }ddi|_        | j                  ddddi      }|j                  d       d	d	d	       | j	                  j
                  d
       | j                  d|j                         y	# 1 sw Y   BxY w)zBShould respond with 500 error about failure to load bundler module4notebook.bundler.handlers.BundlerHandler.get_bundlermodule_namefake_moduler/   rB   r<   r=   r>   Ni  z%Could not import bundler fake_bundlerr
   return_valuer3   assert_called_withr4   r5   r6   r   r8   mockr9   s      r   test_bundler_import_errorz'BundleAPITest.test_bundler_import_error=   s    IJ 	4d!. >D<<'<!>2   4D##N3		4
 	))3/=tyyI	4 	4   1A>>Bc                    t        d      5 }ddi|_        | j                  ddddi      }|j                  d       d	d	d	       | j	                  j
                  d
       | j                  d|j                         y	# 1 sw Y   BxY w)z9Should respond with 200 and output from test bundler stubrE   rF   z'notebook.bundler.tests.test_bundler_apir/   rB   r<   stub_bundlerr>   N   r   rH   rK   s      r   test_bundler_invokez!BundleAPITest.test_bundler_invokeG   s    IJ 	4d!.0Y ZD<<'<!>2   4D##N3		4
 	))3/ndii0	4 	4rN   )__name__
__module____qualname____doc__classmethodr!   r:   r@   rC   rM   rR   __classcell__)r-   s   @r   r   r      s3    +$ $"=.EJ1r   r   N)rV   os.pathr   r'   notebook.tests.launchnotebookr   nbformatr   nbformat.v4r   r   r   r	   unittest.mockr
   r   r    r   r   <module>r_      s4    
 " :    ":1$ :1r   