o
    i                     @   sp   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 ddlmZ dd	 ZG d
d deZdS )zTest the bundlers API.    N)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   c/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/nbclassic/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 t|   | j}t }|jtd tdd}|j	t
ddd |j| tjt|ddd	d
}t||dd W d   dS 1 sHw   Y  dS )ztMake a test nbclassic. 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)superr   setup_classnotebook_dirr   cellsappendr   r   outputsr   io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/   r4   r   r   r   test_notebook_not_found0   
   z%BundleAPITest.test_notebook_not_foundc                 C   r8   )	z4Should respond with 400 error about disabled bundlerr,   bundle/testnb.ipynbr9   r:   r;   r.   z Bundler fake_bundler not enabledNr/   r4   r   r   r   test_bundler_not_enabled7   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 module5nbclassic.bundler.handlers.BundlerHandler.get_bundlermodule_namefake_moduler,   r?   r9   r:   r;   Ni  z%Could not import bundler fake_bundlerr	   return_valuer0   assert_called_withr1   r2   r3   r   r5   mockr6   r   r   r   test_bundler_import_error>      

z'BundleAPITest.test_bundler_import_errorc                 C   rA   )z9Should respond with 200 and output from test bundler stubrB   rC   z(nbclassic.bundler.tests.test_bundler_apir,   r?   r9   stub_bundlerr;   N   r   rE   rH   r   r   r   test_bundler_invokeH   rK   z!BundleAPITest.test_bundler_invoke)__name__
__module____qualname____doc__classmethodr   r7   r=   r@   rJ   rN   __classcell__r   r   r*   r   r      s    
r   )rR   r"   os.pathr   r$   nbclassic.tests.launchnotebookr   nbformatr   nbformat.v4r   r   r   r   unittest.mockr	   r   r   r   r   r   r   <module>   s    