o
    i                     @   sh   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d ZG d	d
 d
eZdS )zTest the bundlers API.    )join)NotebookTestBase)write)new_notebooknew_markdown_cellnew_code_cell
new_output)patchc                 C   s   |  |d  dS )z*Bundler test stub. Echo the notebook path.pathN)finish)handlermodel r   b/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/notebook/bundler/tests/test_bundler_api.pybundle   s   r   c                       sL   e Zd ZdZe fddZdd Zdd Zdd	 Zd
d Z	dd Z
  ZS )BundleAPITestz!Test the bundlers web service APIc                    s   t    | j}t }|jtd tdd}|jt	ddd |j| t
t|ddd	d
}t||dd W d   dS 1 sEw   Y  dS )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__r   r   r      s   

"zBundleAPITest.setup_classc                 C   s,   |  dd}| |jd | d|j dS )z7Should respond with 400 error about missing bundler argGETbundle/fake.ipynb  zMissing argument bundlerNrequestassertEqualstatus_codeassertInr   selfrespr   r   r   test_missing_bundler_arg)   s   z&BundleAPITest.test_missing_bundler_argc                 C   4   | j ddddid}| |jd | d|j dS )	z4Should respond with 404 error about missing notebookr+   r,   bundlerfake_bundlerparamsi  z	Not FoundNr.   r3   r   r   r   test_notebook_not_found/   
   z%BundleAPITest.test_notebook_not_foundc                 C   r7   )	z4Should respond with 400 error about disabled bundlerr+   bundle/testnb.ipynbr8   r9   r:   r-   z Bundler fake_bundler not enabledNr.   r3   r   r   r   test_bundler_not_enabled6   r=   z&BundleAPITest.test_bundler_not_enabledc                 C   p   t d}ddi|_| jddddid}|d W d	   n1 s#w   Y  | |jd
 | d|j d	S )zBShould respond with 500 error about failure to load bundler module4notebook.bundler.handlers.BundlerHandler.get_bundlermodule_namefake_moduler+   r>   r8   r9   r:   Ni  z%Could not import bundler fake_bundlerr	   return_valuer/   assert_called_withr0   r1   r2   r   r4   mockr5   r   r   r   test_bundler_import_error=      

z'BundleAPITest.test_bundler_import_errorc                 C   r@   )z9Should respond with 200 and output from test bundler stubrA   rB   z'notebook.bundler.tests.test_bundler_apir+   r>   r8   stub_bundlerr:   N   r   rD   rG   r   r   r   test_bundler_invokeG   rJ   z!BundleAPITest.test_bundler_invoke)__name__
__module____qualname____doc__classmethodr   r6   r<   r?   rI   rM   __classcell__r   r   r)   r   r      s    
r   N)rQ   os.pathr   r#   notebook.tests.launchnotebookr   nbformatr   nbformat.v4r   r   r   r   unittest.mockr	   r   r   r   r   r   r   <module>   s    