
    Ib                     X    d dl mZ d dlmZ ddlmZ d dlZd dlmZ d Z	 G d d	e      Z
y)
    )TestCase)TemporaryDirectory   )LargeFileManagerN)webc                     | j                  |      }	 t        j                  |       y# t        $ r t	        d|       Y yw xY w)z
    Make a directory.
    zDirectory already exists: N)_get_os_pathosmakedirsOSErrorprint)contents_managerapi_pathos_paths      X/usr/lib/python3/dist-packages/notebook/services/contents/tests/test_largefilemanager.py	_make_dirr      sD     ++H5G8
G 8*7+678s   ) AAc                       e Zd Zd Zd Zd Zy)TestLargeFileManagerc                     t               | _        | j                  j                  | _        t	        | j                        | _        y )N)root_dir)r   	_temp_dirnametdr   r   )selfs    r   setUpzTestLargeFileManager.setUp   s.    +-..%% 0$'' B    c                 0    t        | j                  |       y)zomake a subdirectory at api_path

        override in subclasses if contents are not on the filesystem.
        N)r   r   )r   r   s     r   make_dirzTestLargeFileManager.make_dir   s    
 	$''2r   c                 ,   | j                   }|j                  d      }|d   }|d   }|j                  |      }|j                  ||      }t	        |t
              sJ | j                  d|       | j                  d|       | j                  |d   |       | j                  |d   |       	 dddd}|j                  ||d          	 ddddd	}|j                  ||d          	 ddddd	}|j                  ||d          	 ddddddd}|j                  ||d          dddddd}|d   }|d   }|j                  ||       dD ]  }dD ]  }|j                  |      }||d<   ||d<   |j                  ||      }	t	        |	t
              sJ | j                  d|	       | j                  d|	       | j                  d|	       | j                  |	d   |       | j                  |	d   |         d}
| j                  d       |j                  |
d      }|d   }|d   }|j                  |      }|j                  ||      }t	        |t
              sJ | j                  d|       | j                  d|       | j                  |d   d       | j                  |d   d       y # t        j                  $ r&}| j                  dt        |             Y d }~d }~ww xY w# t        j                  $ r&}| j                  d
t        |             Y d }~1d }~ww xY w# t        j                  $ r&}| j                  dt        |             Y d }~Pd }~ww xY w# t        j                  $ r&}| j                  dt        |             Y d }~md }~ww xY w)Nnotebook)typer   pathtest   )r   r"   chunkz-HTTP 400: Bad Request (No file type provided))r   r"   r%   r!   zUHTTP 400: Bad Request (File type "notebook" is not supported for large file transfer)filez0HTTP 400: Bad Request (No file content provided)r   json)r   r"   r%   r!   contentformatzRHTTP 400: Bad Request (Must specify format of file contents as 'text' or 'base64')ztest==text)r   r"   r!   r(   r)   )r$   r   )r*   base64r%   r)   z/foo/foo)r"   r!   zUntitled.ipynbzfoo/Untitled.ipynb)r   new_untitledgetsave
isinstancedictassertInassertEqualr   	HTTPErrorstrassertNotInr   )r   cmmodelr   r"   
full_modeler%   fm	model_ressub_dirs              r   	test_savezTestLargeFileManager.test_save!   s   ""Z0V}V} VVD\

D)%&&&fe$fe$v-v-	V#Va@EGGE5=)	~#VaTEGGE5=)	Y#VaPEGGE5=)	#Va &&:EGGE5=)  $8V}V}
t 	:E( :VVD\
&+
7#')
8$GGJ5	!)T222fi0fi0  )4  6!2D9  6!2D9:	:  eW:>V}V}t t$%&&&fe$fe$v(89v(<=w }} 	VLcRSfUU	V }} 	~tvyz{v|}}	~ }} 	YOQTUVQWXX	Y }} 	qQ 	s`   -J& 	K" &L M &K9KK"L5LLM1MMN-NNN)__name__
__module____qualname__r   r   r?    r   r   r   r      s    C
3P>r   r   )unittestr   ipython_genutils.tempdirr   largefilemanagerr   r
   tornador   r   r   rC   r   r   <module>rH      s'     7 / 	 8^>8 ^>r   