
B+Qc           @   s  d  Z  d d l m Z m Z d d l m Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m 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 d d l m Z d d l m Z m Z d d l  m! Z! d d l" m# Z# m$ Z$ d d l% m& Z& d d l' m( Z( m) Z) d d l* m+ Z+ d d l Z, d d l- Z- d d l. Z. d d l/ Z/ d e/ j0 f d     YZ1 d e1 f d     YZ2 d e1 f d     YZ3 d e1 f d     YZ4 d  e1 f d!     YZ5 d" e1 f d#     YZ6 d$ e1 f d%     YZ7 d& e1 f d'     YZ8 d( e1 f d)     YZ9 d* e1 f d+     YZ: d, e1 f d-     YZ; d.   Z< e= d/ k re<   Z> e/ j? d0 d1  j@ e>  n  d S(2   s  
Unit Tests for Loris WSGI JPEG 2000 Server
==========================================================
	Unit tests are named so that they run in a logical order, which means 
	running e.g. `python -m unittest -vf test.suite` should make it clearer
	where the actual failure happened, rather than having to trace back through
	a cascade of failures to find the original fault.

Author: Jon Stroop <jstroop@princeton.edu>
Since: 2012-08-25

i(   t   datetimet	   timedelta(   t
   getcontext(   t   loads(   t
   create_app(   t   DeepZoomImageDescriptor(   t   BadRegionRequestException(   t   BadRegionSyntaxException(   t   BadSizeSyntaxException(   t   ImgInfo(   t   RegionParameter(   t   RotationParameter(   t   SizeParameter(   t   resolve(   t   listdirt   patht   remove(   t   rmtree(   t   stderrt   stdout(   t   Headers(   t	   http_datet
   parse_date(   t   Client(   t   BaseResponset   Request(   t   parseStringNt	   LorisTestc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   t  j j |   t d t  |  _ |  j j t   _ t	 |  j t
  |  _ t j t j t   } t j | d  |  _ d |  _ d |  _ d |  _ d  S(   Nt   testt   imgs   another/arbitrary/path/0004s   yet/another/path/0001s   some/path/0042(   t   unittestt   TestCaset   setUpR   t   Truet   appt   decimal_precisionR   t   precR   R   t   clientR   t   abspatht   dirnamet   __file__t   joint   test_img_dirt   test_jp2_idt   test_jp2_1_idt   test_jp2_2_id(   t   selft   abs_path(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyR    *   s    		c         C   sM   x6 t  t j j  D]" } t t j t j j |   q Wt t j j  d  S(   N(   R   t   lorisR"   t   CACHER   R   R)   (   R.   t   d(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   tearDown7   s     c   	      C   s  t  | d  } | j d  | j d  } z=y x| r4t |  d k r4x% t |  d k rs | j d  } qO Wx% t |  d k r | j d  } qw Wt |  d k r t |  d k r | j d  t j d	 | j d
   \ } } Pn0 | j t t j d | j d   d  d  | j d  } q4 Wt |  } t |  } Wn t k
 rf}   n XWd | j   X| | f S(   s   Get the dimensions of a JPEG
		t   ri   i   i   i   i   i   i   s   >HHi   s   >Hi    N(   t   opent   readt   ordt   structt   unpackt   intt	   Exceptiont   close(	   R.   R   t   jpegt   bt   ht   wt   widtht   heightt   e(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   get_jpeg_dimensions=   s,       $!0c         C   s`   |  j  j |  } t j t j j d  } t | d  } | j | j	  | j
   |  j |  S(   s:   Make a request, save it out, and return the dimensions.
		s
   result.jpgR@   (   R%   t   getR   R)   R0   R"   t   TMPR5   t   writet   dataR<   RD   (   R.   t   urit   respt   f_namet   f(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   _dims_from_uriX   s    
(   t   __name__t
   __module__R    R3   RD   RM   (    (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyR   )   s   			t   Test_A_ResolveIdc           B   s   e  Z d  Z d   Z RS(   s"   Test that the ID resolver works.
	c         C   sN   t  j |  j d  } t |  j  } |  j | |  |  j t  j |   d  S(   Ns   another/arbitrary/path/0004.jp2(   R   R)   R*   R   R+   t   assertEqualt
   assertTruet   isfile(   R.   t   expected_patht   resolved_path(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_loris_resolve_idf   s    (   RN   RO   t   __doc__RV   (    (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyRP   c   s   t   Test_B_InfoExtractionc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   sJ   Here we extract info from JPEG 2000 files and test against known values.
	c         C   s   t  |  j  } t | |  j  } |  j | j d  |  j | j d  |  j | j d  |  j | j d  |  j | j d  |  j | j	 d d d d g  |  j | j
 |  j  d  S(	   Ni
  i  i   i   t   nativet   bitonalt   greyt   color(   R   R+   R	   RQ   RA   RB   t
   tile_widtht   tile_heightt   levelst	   qualitiest   ident(   R.   R   t   info(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_img_infop   s    c         C   s   |  j  j |  j  } t | |  j  } |  j | j d  |  j | j d  |  j | j d  |  j | j d  |  j | j	 d  |  j | j
 d d d d g  |  j | j |  j  d  S(	   Ni  i   i   i   RY   RZ   R[   R\   (   R"   t   _resolve_identifierR,   R	   RQ   RA   RB   R]   R^   R_   R`   Ra   (   R.   R   Rb   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_img_info_1|   s    c         C   s   |  j  j |  j  } t | |  j  } |  j | j d  |  j | j d  |  j | j d  |  j | j d  |  j | j	 d  |  j | j
 d d d g  |  j | j |  j  d  S(   Ni	  i  i   i   RY   RZ   R[   (   R"   Rd   R-   R	   RQ   RA   RB   R]   R^   R_   R`   Ra   (   R.   R   Rb   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_img_info_2   s    c         C   s  |  j  j d |  j d  } t | j  } |  j | j d   |  j | j d  |  j  |  j | j d   |  j | j d  d  |  j | j d   |  j | j d  d  |  j | j d   |  j | j d  d	 d
 d d d g  |  j | j d   |  j | j d  d  |  j | j d   |  j | j d  d  |  j | j d   |  j | j d  d d g  |  j | j d   |  j | j d  d d d d g  |  j | j d   |  j | j d  d  d  S(   Nt   /s
   /info.jsonu
   identifieru   widthi
  u   heighti  u   scale_factorsi   i   i   i   i   u
   tile_widthi   u   tile_heightu   formatsu   jpgu   pngu	   qualitiesu   nativeu   bitonalu   greyu   coloru   profileuA   http://library.stanford.edu/iiif/image-api/compliance.html#level1(   R%   RE   R+   R   RH   RR   t   has_keyRQ   (   R.   RJ   t	   resp_json(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_info_json   s(    (%c         C   sF   |  j  j d |  j d  } t | j  } |  j | j j d  d  S(   NRg   s	   /info.xmlRb   (   R%   RE   R+   R   RH   RQ   t   documentElementt   tagName(   R.   RJ   t   dom(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_info_xml   s    (   RN   RO   RW   Rc   Re   Rf   Rj   Rn   (    (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyRX   l   s   				t   Test_C_RegionParameterc           B   sz   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z RS(   sl   Here we construct RegionParameter objects from would-be URI slices and
	test their attributes and methods.
	c         C   s/   d } d } t  |  } |  j | j |  d  S(   Nt   full(   R
   RQ   t   mode(   R.   t   url_segmentt   expected_modet   region_parameter(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt	   test_full   s    c         C   s   d } d } d } d } d } d } t  |  } |  j | j |  |  j | j |  |  j | j |  |  j | j |  |  j | j |  d  S(   Ns   pct:10,11,70.5,80t   pctg      $@g      &@g     Q@g      T@(   R
   RQ   Rq   t   xt   yR@   R?   (   R.   Rr   Rs   t
   expected_xt
   expected_yt
   expected_wt
   expected_hRt   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_pct   s    c         C   s   d } d } d } d } d } d } t  |  } |  j | j |  |  j | j |  |  j | j |  |  j | j |  |  j | j |  d  S(   Ns   80,50,16,75t   pixeliP   i2   i   iK   (   R
   RQ   Rq   Rw   Rx   R@   R?   (   R.   Rr   Rs   Ry   Rz   R{   R|   Rt   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt
   test_pixel   s    c         C   sP   d } |  j  t   t |  Wd  QXd } |  j  t   t |  Wd  QXd  S(   Ns   pct:101,70,50,50s   pct:100,100.1,50,50(   t   assertRaisesR   R
   (   R.   Rr   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_pct_le_100_exception   s    c         C   sP   d } |  j  t   t |  Wd  QXd } |  j  t   t |  Wd  QXd  S(   Ns   pct:101,70,50s	   100,50,50(   R   R   R
   (   R.   Rr   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_missing_dim   s    c         C   sb   |  j  j |  j  } t | |  j  } d } t |  } |  j t   | j |  } Wd  QXd  S(   Ns
   2717,0,1,1(   R"   Rd   R+   R	   R
   R   R   t
   to_kdu_arg(   R.   R   Rb   Rr   Rt   t
   region_arg(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_xpixel_oob   s    c         C   sb   |  j  j |  j  } t | |  j  } d } t |  } |  j t   | j |  } Wd  QXd  S(   Ns
   0,3600,1,1(   R"   Rd   R+   R	   R
   R   R   R   (   R.   R   Rb   Rr   Rt   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_ypixel_oob   s    c         C   sb   |  j  j |  j  } t | |  j  } d } t |  } d } | j |  } |  j | |  d  S(   Ns   0,0,1358,1800s.   -region \{0,0\},\{0.5,0.49981597350018402650\}(   R"   Rd   R+   R	   R
   R   RQ   (   R.   R   Rb   Rr   Rt   t   expected_kduR   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_pixel_to_kdu_hw  s    c         C   sb   |  j  j |  j  } t | |  j  } d } t |  } d } | j |  } |  j | |  d  S(   Ns   1358,1800,200,658sY   -region \{0.5,0.49981597350018402650\},\{0.18277777777777777778,0.073610599926389400074\}(   R"   Rd   R+   R	   R
   R   RQ   (   R.   R   Rb   Rr   Rt   R   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_pixel_to_kdu_tl
  s    c         C   sb   |  j  j |  j  } t | |  j  } d } t |  } d } | j |  } |  j | |  d  S(   Ns   pct:0,0,50,50s   -region \{0,0\},\{0.5,0.5\}(   R"   Rd   R+   R	   R
   R   RQ   (   R.   R   Rb   Rr   Rt   R   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_pct_to_kdu_hw  s    c         C   sb   |  j  j |  j  } t | |  j  } d } t |  } d } | j |  } |  j | |  d  S(   Ns   pct:50,50,50,50s   -region \{0.5,0.5\},\{0.5,0.5\}(   R"   Rd   R+   R	   R
   R   RQ   (   R.   R   Rb   Rr   Rt   R   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_pct_to_kdu_tl  s    c         C   sb   |  j  j |  j  } t | |  j  } d } t |  } d } | j |  } |  j | |  d  S(   Ns   pct:20,20,100,100s   -region \{0.2,0.2\},\{0.8,0.8\}(   R"   Rd   R+   R	   R
   R   RQ   (   R.   R   Rb   Rr   Rt   R   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_pct_to_kdu_adjust%  s    (   RN   RO   RW   Ru   R}   R   R   R   R   R   R   R   R   R   R   (    (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyRo      s   																		t   Test_D_SizeParameterc           B   sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   sj   Here we construct SizeParameter objects from would-be URI slices and
	test their attributes and methods.
	c         C   sK   d } d } d } t  |  } |  j | j |  |  j | j   |  d  S(   NRp   t    (   R   RQ   Rq   t   to_convert_arg(   R.   Rr   Rs   t   expected_convertt   size_parameter(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyRu   2  s    c         C   sd   d } d } d } d } t  |  } |  j | j |  |  j | j |  |  j | j   |  d  S(   Ns   pct:50Rv   g      I@s   -resize 50.0%(   R   RQ   Rq   Rv   R   (   R.   Rr   Rs   t   expected_pctR   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyR}   :  s    c         C   sP   d } |  j  t   t |  Wd  QXd } |  j  t   t |  Wd  QXd  S(   Ns   pct:-0.1s   pct:0(   R   R   R   (   R.   Rr   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_le_0_pct_exceptionD  s    c         C   sw   d } d } d } d } t  |  } |  j | j |  |  j | j d   |  j | j |  |  j | j   |  d  S(   Ns   ,100R~   id   s   -resize x100(   R   RQ   R?   R@   t   NoneRq   R   (   R.   Rr   Rs   t   expected_heightR   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_h_onlyL  s    c         C   s   d } d } d } d } t  |  } |  j | j |  |  j | j d   |  j | j d   |  j | j |  |  j | j   |  d  S(   Ns   500,R~   i  s   -resize 500(   R   RQ   R@   R?   R   t   force_aspectRq   R   (   R.   Rr   Rs   t   expected_widthR   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_w_onlyW  s    c         C   s   d } d } d } d } d } t  |  } |  j | j |  |  j | j |  |  j | j t  |  j | j |  |  j | j   |  d  S(   Ns   500,100R~   i  id   s   -resize 500x100!(   R   RQ   R@   R?   R   R!   Rq   R   (   R.   Rr   Rs   R   R   R   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_force_aspectc  s    c         C   s   d } d } d } d } d } t  |  } |  j | j |  |  j | j |  |  j | j t  |  j | j |  |  j | j   |  d  S(   Ns   !500,100R~   i  id   s   -resize 500x100(   R   RQ   R@   R?   R   t   FalseRq   R   (   R.   Rr   Rs   R   R   R   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_do_not_force_aspectp  s    c      
   C   s   d } |  j  t   t |  Wd  QXd } |  j  t   t |  Wd  QXd } |  j  t   t |  Wd  QXd } |  j  t   t |  Wd  QXd } |  j  t   t |  Wd  QXd  S(   Ns   -1,500s   500,-1s   !500,-1s   ,-30s   -50,(   R   R   R   (   R.   Rr   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt    test_dimension_lt_1_px_exception}  s    (   RN   RO   RW   Ru   R}   R   R   R   R   R   R   (    (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyR   .  s   		
					t   Test_E_RotationParameterc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   sn   Here we construct RotationParameter objects from would-be URI slices and
	test their attributes and methods.
	c         C   sK   d } d } d } t  |  } |  j | j |  |  j | j   |  d  S(   Nt   0i    R   (   R   RQ   t
   nearest_90R   (   R.   Rr   t   expected_rotationt   expected_kdu_argt   rotation_parameter(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_rotation_0  s    c         C   sK   d } d } d } t  |  } |  j | j |  |  j | j   |  d  S(   Ns   -75is   -rotate -90(   R   RQ   R   R   (   R.   Rr   R   R   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_rotation_neg_75  s    c         C   sK   d } d } d } t  |  } |  j | j |  |  j | j   |  d  S(   Nt   91iZ   s
   -rotate 90(   R   RQ   R   R   (   R.   Rr   R   R   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_rotation_91  s    c         C   sK   d } d } d } t  |  } |  j | j |  |  j | j   |  d  S(   Nt   314i  s   -rotate 270(   R   RQ   R   R   (   R.   Rr   R   R   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_rotation_314  s    c         C   sK   d } d } d } t  |  } |  j | j |  |  j | j   |  d  S(   Nt   315ih  R   (   R   RQ   R   R   (   R.   Rr   R   R   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_rotation_315  s    (   RN   RO   RW   R   R   R   R   R   (    (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyR     s   				t   Test_F_Utilitiesc           B   s    e  Z d  Z d   Z d   Z RS(   s?   Here we exercise the shell utilities and make sure they work.
	c         C   s   |  j  t j |  j j   |  j j d } t j | d t d t j d t j } | j	   } t
 j d  x | j
 D] } t
 j |  qv Wx | j D] } t j |  q Wt j d  |  j | d  d  S(   Ns	    -versiont   shellR   R   s   
i    (   RR   R   t   existsR"   t   convert_cmdt
   subprocesst   PopenR!   t   PIPEt   waitR   RG   R   RQ   (   R.   t   convert_versiont   proct   exit_statust   line(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_convert  s    c         C   s   |  j  t j |  j j   |  j j d } t j | d t d t j d t j } | j	   } t
 j d  x | j
 D] } t
 j |  qv Wx | j D] } t j |  q Wt j d  |  j | d  d  S(   Ns    -vR   R   R   s   
i    (   RR   R   R   R"   t   kdu_expand_cmdR   R   R!   R   R   R   RG   R   RQ   (   R.   t   kdu_vR   R   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_kdu  s    (   RN   RO   RW   R   R   (    (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyR     s   	t   Test_G_ContentNegotiationc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s}   Here we make requests for different content types using both HTTP headers
	and poor-mans conneg (via file-like extensions).
	c         C   s  |  j  j d |  j d  } |  j | j j d  d  t   } | j d d  |  j  j d |  j d d | } |  j | j j d  d  |  j  j d |  j d  } |  j | j j d  d	  | j d d	  |  j  j d |  j d d | } |  j | j j d  d	  d  S(
   NRg   s	   /info.xmls   content-types   text/xmlt   accepts   /infot   headerss
   /info.jsons	   text/json(   R%   RE   R+   RQ   R   R   t   add(   R.   RJ   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt	   test_info  s    	##c         C   s  t    } |  j j d |  j d  } |  j | j j d  d  |  j | j d  | j   | j	 d d  |  j j d |  j d d	 | } |  j | j j d  d  |  j | j d  | j   |  j j d |  j d  } |  j | j j d  d  |  j | j d  d  S(
   NRg   s	   /info.txts   content-types	   text/jsoni   R   s
   text/plains   /infoR   (
   R   R%   RE   R+   RQ   R   t   assertEqualst   status_codet   clearR   (   R.   R   RJ   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_info_default  s    	
#
c         C   s'  |  j  j d |  j d  } |  j | j j d  d  t   } | j d d  |  j  j d |  j d d | } |  j | j j d  d  |  j  j d |  j d  } |  j | j j d  d	  | j   | j d d	  |  j  j d |  j d d | } |  j | j j d  d	  d  S(
   NRg   s   /full/full/0/native.jpgs   content-types
   image/jpegR   s   /full/pct:10/0/nativeR   s   /full/pct:10/0/native.pngs	   image/png(   R%   RE   R+   RQ   R   R   R   R   (   R.   RJ   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_img  s    	#
#(   RN   RO   RW   R   R   R   (    (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyR     s   		t   Test_H_Cachingc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   sy   Here we make requests for different content types using both HTTP headers
	and poor-mans conneg (file-like extensions).
	c         C   s   t  |  j _ |  j j |  j  } t | |  j  } d } t |  } y | j |  } WnK t k
 r } |  j	 | j
 j d  d } |  j	 | j
 j |  |  n Xd  S(   Ns   pct:20,20,100,100s   543,720,2717,3600sE   -region \{0.2,0.19985277880014722120\},\{0.8,0.80014722119985277880\}(   R!   R"   t   cache_px_onlyRd   R+   R	   R
   R   t   PctRegionExceptionR   t   new_region_paramt	   url_value(   R.   R   Rb   Rr   Rt   R   RC   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_cache_px_only%  s    c         C   s  d |  j  d } |  j j |  } |  j | j d  |  j | j j d   t   } t	 t
 j   t d d   } | j d |  |  j j | d | } |  j | j d	  | j   t	 t
 j   t d d   } | j d |  |  j j | d | } |  j | j d  d  S(
   NRg   s   /0,0,256,256/full/0/color.jpgi   s   last-modifiedt   daysi   s   if-modified-sinceR   i0  (   R,   R%   RE   R   R   RR   R   Rh   R   R   R    t   utcnowR   R   R   (   R.   t   urlRJ   R   t	   yesterdayt   tomorrow(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_img_caching2  s    	
c         C   s  d |  j  d } |  j j |  } |  j | j d  |  j | j j d   t   } t	 t
 j   t d d   } | j d |  |  j j | d | } |  j | j d	  | j   t	 t
 j   t d d   } | j d |  |  j j | d | } |  j | j d  d  S(
   NRg   s
   /info.jsoni   s   last-modifiedR   i   s   if-modified-sinceR   i0  (   R,   R%   RE   R   R   RR   R   Rh   R   R   R    R   R   R   R   (   R.   R   RJ   R   R   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_info_cachingE  s    	
(   RN   RO   RW   R   R   R   (    (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyR      s   		t   Test_I_ResultantImgc           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   sH   Here we make requests and assertions about the resultant image's size.
	c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni
  i  Rg   s   /full/full/0/native.jpg(   i
  i  (   R+   RM   R   (   R.   t   dimsRI   t   result_dims(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_full_fullZ  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Nid   i   Rg   s   /full/100,/0/native.jpg(   id   i   (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_full_100_w`  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   NiK   id   Rg   s   /full/,100/0/native.jpg(   iK   id   (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_full_100_hf  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   NiO  i  Rg   s   /full/pct:50/0/native.jpg(   iO  i  (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_full_pct50l  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni   iK   Rg   s   /full/150,75/0/native.jpg(   i   iK   (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_full_150_75r  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni9   iK   Rg   s   /full/!150,75/0/native.jpg(   i9   iK   (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_full_150_75_preservedx  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Nid   i   Rg   s    /10,10,100,200/full/0/native.jpg(   id   i   (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_region_full~  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Nid   i   Rg   s    /10,10,150,250/100,/0/native.jpg(   id   i   (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_region_100_w  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni<   id   Rg   s    /10,10,150,250/,100/0/native.jpg(   i<   id   (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_region_100_h  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   NiK   i}   Rg   s"   /10,10,150,250/pct:50/0/native.jpg(   iK   i}   (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_region_pct50  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni   iK   Rg   s"   /10,10,150,250/150,75/0/native.jpg(   i   iK   (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_region_150_75  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni-   iK   Rg   s#   /10,10,150,250/!150,75/0/native.jpg(   i-   iK   (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_region_150_75_preserve  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni  ix  Rg   s   /full/pct:110/0/native.jpg(   i  ix  (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_full_upsample  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni  ix  Rg   s   /full/2989,/0/native.jpg(   i  ix  (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_full_upsample_w  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni  ix  Rg   s   /full/,3960/0/native.jpg(   i  ix  (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_full_upsample_h  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni   i  Rg   s#   /10,10,150,250/pct:110/0/native.jpg(   i   i  (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_region_upsample  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni   i  Rg   s    /10,10,150,250/165,/0/native.jpg(   i   i  (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_region_upsample_w  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni   i  Rg   s    /10,10,150,250/,275/0/native.jpg(   i   i  (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_region_upsample_h  s    c         c   s   d } d } x | | k r t  | | | d |  } d } d } xx | | k r t  | | | d |  }	 d j t t | | | | f   }
 |
 |	 | f f V| | d 7} | d 7} qE W| | d 7} | d 7} q Wd S(   s,  Generates two-tuples:
		[0]: a string in the IIIF region request format, i.e. 'x,y,w,h'.
		[1]: a two-tuple with the expected actual resultant image width and height,
		compensating for the tiles at the far right and bottom, which might not be
		square. Tiles go from left to right, top to bottom.
		i    i   t   ,N(   t   minR)   t   mapt   str(   R.   t	   img_widtht
   img_heightt	   tile_sizet   cyRx   t   actual_ht   cxRw   t   actual_wt   region(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   tile_gen  s    $c         C   s  |  j  } |  j j |  } t | |  } d d d d g } d } x | D] } x |  j | j | j |  D] } d |  j  d | d d } |  j j |  }	 t	 j
 t j j d	  } t | d
  }
 |
 j |	 j  |
 j   |  j |  } |  j | | d  qk WqI Wt |  d S(   s@   Making several grids of tiles to check precision...takes a whilei   i   i   i   R   Rg   i    s   /full/0/native.jpgs
   result.jpgR@   i   N(   R,   R"   Rd   R	   R   RA   RB   R%   RE   R   R)   R0   RF   R5   RG   RH   R<   RD   R   R   (   R.   Ra   t   jp2Rb   t
   test_sizesRK   t   sizet   tileRI   RJ   RL   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_region_precision  s     	"
(   RN   RO   RW   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyR   W  s*   																			t   Test_J_SeaDragonExtensionc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s)   Here we test for the Seadragon feature.
	c         C   s   |  j  j d |  j d  } t | j  } | j } |  j | j d  |  j | j d  d  |  j | j d  d  |  j t	 | j d   |  j
 j  | j d	  d
 } |  j | j d  d  |  j | j d  d  d  S(   NRg   s   .xmlt   Imaget   Formatt   jpgt   OverlapR   t   TileSizet   Sizei    t   Heightt   3600t   Widtht   2717(   R%   RE   R+   R   RH   Rk   RQ   Rl   t   getAttributeR:   R"   t   dz_tile_sizet   getElementsByTagName(   R.   RJ   Rm   t   dEt   sE(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   test_dzi_xml  s    	%c         C   sL   |  j  j |  j  j f } d |  j d } |  j |  } |  j | |  d  S(   NRg   s   _files/9/0_0.jpg(   R"   R  R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt    test_dzi_tile_scaling_tiled_size  s    c         C   s:   d } d |  j  d } |  j |  } |  j | |  d  S(   Ni   i   Rg   s   _files/8/0_0.jpg(   i   i   (   R+   RM   R   (   R.   R   RI   R   (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt$   test_dzi_tile_scaling_not_tiled_size
  s    (   RN   RO   RW   R
  R  R  (    (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyR     s   		c          C   s   t  j   }  g  } | j |  j t   | j |  j t   | j |  j t   | j |  j t   | j |  j t   | j |  j t	   | j |  j t
   | j |  j t   | j |  j t   | j |  j t   t  j |  S(   N(   R   t
   TestLoadert   appendt   loadTestsFromTestCaseRP   RX   Ro   R   R   R   R   R   R   R   t	   TestSuite(   t   tlt   test_suites(    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt	   all_tests  s    t   __main__t	   verbosityi   (A   RW   R    R   t   decimalR   t   jsonR   t	   loris.appR   t   loris.deepzoomR   t   loris.exceptionsR   R   R   t   loris.img_infoR	   t   loris.parametersR
   R   R   t   loris.resolverR   t   osR   R   R   t   shutilR   t   sysR   R   t   werkzeug.datastructuresR   t   werkzeug.httpR   R   t   werkzeug.testR   t   werkzeug.wrappersR   R   t   xml.dom.minidomR   R0   R8   R   R   R   R   RP   RX   Ro   R   R   R   R   R   R   R   R  RN   t
   meta_suitet   TextTestRunnert   run(    (    (    sE   /home/kennisonb/webapps/files/devel/insync/photos/loris/test/suite.pyt   <module>   sP   :	Hzf,&:7		