ó
üR‹_c           @   sæ   d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 d d l	 m Z d Z d d Z e j e j Z d	 d
 „ Z d e
 f d „  ƒ  YZ e d k râ e e e j ƒ Z e j e ƒ n  d S(   s^  
Functional tests from version 1.1 of the sync storage protocol.

This file is a copy of the functional tests from sync1.1, minimally
edited to run against the sync1.5 server.  They're here to help verify
that sync1.1 clients can still sync successfully agains the sync1.5 server
if they stick to the parts of the spec that were in use in practice.

iÿÿÿÿN(   t   Decimal(   t   StorageFunctionalTestCase(   t   run_live_functional_testsi   t   *iô  i
   c         C   s/   d j  g  t |  ƒ D] } t j t ƒ ^ q ƒ S(   Nt    (   t   joint   ranget   randomt   choicet   _ASCII(   t   sizet   i(    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   randtext   s    t   TestOldStoragec           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 d „  Z d „  Z d „  Z d „  Z RS(   c         C   s  t  t |  ƒ j ƒ  d |  j |  _ |  j j |  j d d i d d 6ƒx, d D]$ } |  j j |  j d | g  ƒ qN WxL t d ƒ D]> } |  j j	 |  j d t
 | ƒ i d d 6ƒ t j d ƒ qƒ WxL t d ƒ D]> } |  j j	 |  j d t
 | ƒ i d d 6ƒ t j d ƒ qÒ Wd  S(   Ns   /1.5/%ds   /storaget   headerst   1s   X-Confirm-Deletet   clientt   cryptot   formst   historyt   xxx_col1t   xxx_col2s	   /storage/i   s   /storage/xxx_col1/t   xxxt   payloadg{®Gáz”?i   s   /storage/xxx_col2/(   R   R   R   R   R   R   (   t   superR   t   setUpt   user_idt   roott   appt   deletet	   post_jsonR   t   put_jsont   strt   timet   sleep(   t   selft   namet   item(    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyR   %   s    
"c         C   sk   |  j  j |  j d ƒ } | j } | j ƒ  } |  j t | ƒ d ƒ |  j t | j	 d ƒ t | ƒ ƒ d  S(   Ns   /info/collectionsi   s   X-Weave-Records(
   R   t   getR   t   jsont   keyst
   assertTruet   lent   assertEqualst   intR   (   R#   t   respt   resR(   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_get_collections9   s
    	c         C   so   |  j  j |  j d ƒ } | j } | j ƒ  } | j ƒ  |  j | d d g ƒ |  j t | j d ƒ d ƒ d  S(   Ns   /info/collection_countsi   i   s   X-Weave-Recordsi   (	   R   R&   R   R'   t   valuest   sortR+   R,   R   (   R#   R-   R.   R0   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_get_collection_count@   s    	
c         C   sM  |  j  j |  j d ƒ } | j } |  j | g  ƒ |  j  j |  j d ƒ } | j } | j ƒ  |  j | d d d d d g ƒ |  j t | j d ƒ d	 ƒ |  j  j |  j d
 ƒ } | j } | j ƒ  |  j | d d g ƒ |  j  j |  j d ƒ i d d 6d d 6} |  j  j	 |  j d | ƒ } | j } t j
 | ƒ } t j d ƒ i d d 6d d 6} |  j  j	 |  j d | ƒ } | j } t j
 | ƒ } |  j | | k  ƒ |  j  j |  j d | ƒ } | j } |  j | d g ƒ |  j  j |  j d ƒ } | j } | d j ƒ  } | j ƒ  d d d g }	 |  j | |	 ƒ |  j  j |  j d ƒ } | j } |  j t | t ƒ ƒ |  j  j |  j d ƒ g  }
 x; t d ƒ D]- } i t | ƒ d 6d d 6} |
 j | ƒ q™W|  j  j |  j d |
 ƒ |  j  j |  j d ƒ } | j } |  j t | ƒ d ƒ |  j  j |  j d ƒ } | j } |  j t | ƒ d k ƒ |  j  j |  j d ƒ xb d" d# d$ f D]Q \ } } i | d 6d d 6| d 6} |  j  j |  j d | g ƒ t j d ƒ q~W|  j  j |  j d  ƒ } | j } |  j | d d d g ƒ |  j  j |  j d! ƒ } | j } |  j | d d d g ƒ d  S(%   Ns   /storage/col3s   /storage/xxx_col2t   0R   t   2t   3t   4s   X-Weave-Recordsi   s   /storage/xxx_col2?ids=1,3t   128t   idt   xR   s   /storage/xxx_col2/128g333333Ó?t   129s   /storage/xxx_col2/129s   /storage/xxx_col2?newer=%ss   /storage/xxx_col2?full=1i    t   modifiedi
   s   /storage/xxx_col2?limit=2i   i	   i   i"   i   t	   sortindexgš™™™™™¹?s   /storage/xxx_col2?sort=newests   /storage/xxx_col2?sort=index(   R3   i   (   R   i"   (   R4   i   (   R   R&   R   R'   R+   R1   R,   R   R   R   t   dumpsR!   R"   R)   R(   t
   isinstancet   listR   R    t   appendR   R*   (   R#   R-   R.   t   wbot   tst   ftst   ts2t   fts2R(   t   wantedt   wbosR   t   indexR<   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_get_collectionH   st    		
	
				
					c         C   s  |  j  j |  j d ƒ } |  j | j j d ƒ d d ƒ | j } | j ƒ  |  j | d d d d d	 g ƒ |  j  j |  j d d
 d g ƒ} |  j | j j d ƒ d d ƒ g  | j j	 ƒ  j d ƒ D] } t j
 | ƒ ^ qÆ } | j ƒ  |  j | d d d d d	 g ƒ d  S(   Ns   /storage/xxx_col2t   ;i    s   application/jsonR3   R   R4   R5   R6   R   t   Accepts   application/newliness   
(   RK   s   application/newlines(   R   R&   R   R+   t   content_typet   splitR'   R1   t   bodyt   stript   loads(   R#   R.   t   line(    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_alternative_formats§   s     	
4
c         C   s†   |  j  j |  j d ƒ } | j } | j ƒ  } | j ƒ  |  j | d d d g ƒ |  j | d d ƒ |  j  j |  j d d d ƒd  S(	   Ns   /storage/xxx_col2/1R8   R;   R   R   s   /storage/xxx_col2/99t   statusi”  (   R   R&   R   R'   R(   R1   R+   (   R#   R.   R(   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_get_itemº   s    	
c         C   s¾   i t  d 6} |  j j |  j d | ƒ |  j j |  j d ƒ } | j } |  j | d t  ƒ i d d 6} |  j j |  j d | ƒ |  j j |  j d ƒ } | j } |  j | d d ƒ d  S(   NR   s   /storage/xxx_col2/12345t   YYY(   t   _PLDR   R   R   R&   R'   R+   (   R#   RA   R.   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_set_itemÆ   s    		c         C   sê  i d d 6t  d 6} i d d 6t  d 6} | | g } |  j j |  j d | ƒ |  j j |  j d ƒ } | j } |  j | d t  ƒ |  j j |  j d ƒ } | j } |  j | d t  ƒ i d d 6d d 6} i d	 d 6t  d 6} | | g } |  j j |  j d | ƒ |  j j |  j d
 ƒ } | j } |  j | d t  ƒ |  j j |  j d ƒ } | j } |  j | d d ƒ i d d 6t  d 6} i d d 6t  d 6d d 6} | | g } |  j j |  j d | ƒ |  j j |  j d d d ƒd  S(   Nt   12R8   R   t   13s   /storage/xxx_col2s   /storage/xxx_col2/12s   /storage/xxx_col2/13t   XyXt   14s   /storage/xxx_col2/14t   onet   twot   FAILR<   s   /storage/xxx_col2/twoRS   i”  (   RV   R   R   R   R&   R'   R+   (   R#   t   wbo1t   wbo2RG   R.   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_set_collectionÕ   s4    				
c         C   sÐ   |  j  j |  j d d d g ƒi d d 6d d 6} i d	 d 6t d 6} | | g } |  j  j |  j d
 | ƒ |  j  j |  j d ƒ } | j } | d } t | d ƒ t | d ƒ } |  j | | d ƒ d  S(   Ns   /storageR   s   X-Confirm-DeleteR   RY   R8   RZ   R   R[   s   /storage/xxx_col2s   /info/collection_usageR   g      @(   s   X-Confirm-DeleteR   (	   R   R   R   RV   R   R&   R'   R*   t   assertEqual(   R#   R_   R`   RG   R.   t   usaget   xxx_col2_sizeRF   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_collection_usageú   s    
	
c         C   s§  |  j  j |  j d ƒ i d d 6t d 6} i d d 6t d 6} i d d 6t d 6} | | | g } |  j  j |  j d | ƒ |  j  j |  j d ƒ } |  j t | j ƒ d ƒ |  j  j |  j d ƒ |  j  j |  j d ƒ } |  j t | j ƒ d ƒ |  j  j |  j d | ƒ |  j  j |  j d	 ƒ |  j  j |  j d ƒ } |  j t | j ƒ d
 ƒ |  j  j |  j d ƒ |  j  j |  j d ƒ } |  j t | j ƒ d ƒ d  S(   Ns   /storage/xxx_col2RX   R8   R   RY   R[   i   i    s   /storage/xxx_col2?ids=12,14i   s   /storage/xxx_col2?ids=13(	   R   R   R   RV   R   R&   R+   R*   R'   (   R#   R_   R`   t   wbo3RG   R.   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_delete_collection	  s$    c         C   s  |  j  j |  j d ƒ i d d 6t d 6} i d d 6t d 6} i d d 6t d 6} | | | g } |  j  j |  j d | ƒ |  j  j |  j d ƒ } |  j t | j ƒ d ƒ |  j  j |  j d ƒ |  j  j |  j d ƒ } |  j t | j ƒ d	 ƒ |  j  j |  j d
 d d ƒd  S(   Ns   /storage/xxx_col2RX   R8   R   RY   R[   i   s   /storage/xxx_col2/13i   s   /storage/xxx_col2/12982RS   i”  (	   R   R   R   RV   R   R&   R+   R*   R'   (   R#   R_   R`   Rf   RG   R.   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_delete_item'  s    c         C   sí  |  j  j |  j d ƒ i d d 6t d 6} i d d 6t d 6} i d d 6t d 6} | | | g } |  j  j |  j d | ƒ |  j  j |  j d ƒ } |  j t | j ƒ d ƒ i t d 6} |  j  j	 |  j d | ƒ |  j  j	 |  j d	 | ƒ |  j  j |  j d ƒ } |  j | j d t ƒ |  j  j |  j d	 ƒ } |  j | j d t ƒ |  j  j |  j d
 d d g ƒ} t j
 | j ƒ } |  j  j |  j d ƒ j } |  j | g  ƒ |  j  j |  j d d d ƒ|  j  j |  j d	 d d ƒd  S(   Ns   /storage/xxx_col2RX   R8   R   RY   R[   i   s   /storage/meta/globals   /storage/tabs/homes   /storageR   s   X-Confirm-DeleteR   RS   i”  (   s   X-Confirm-DeleteR   (   R   R   R   RV   R   R&   R+   R*   R'   R   RP   RN   (   R#   R_   R`   Rf   RG   R.   RA   t   items(    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_delete_storage<  s,    c         C   sQ  |  j  r d  St j ƒ  } |  j j |  j d ƒ } t | t | j d ƒ ƒ } |  j | d k  ƒ i t	 d 6} t j ƒ  } |  j j
 |  j d | ƒ } t | t | j d ƒ ƒ } |  j | d k  ƒ i d d 6t	 d 6} i d	 d 6t	 d 6} | | g } t j ƒ  } |  j j |  j d | ƒ } |  j t | t | j d ƒ ƒ d k  ƒ d  S(
   Ns   /storage/xxx_col2s   X-Weave-Timestampgš™™™™™¹?R   s   /storage/xxx_col2/12345gš™™™™™É?i   R8   i   (   t   distantR!   R   R&   R   t   abst   floatR   R)   RV   R   R   (   R#   t   nowR.   t   diffRA   R_   R`   RG   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_x_weave_timestamp]  s$    	c         C   sx   i t  d 6} |  j j |  j d | ƒ } t j | j ƒ d } |  j j |  j d | d d t | ƒ f g d d ƒd  S(   NR   s   /storage/xxx_col2/12345iè  R   s   X-If-Unmodified-SinceRS   iœ  (   RV   R   R   R   R'   RP   RN   R    (   R#   RA   RB   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_ifunmodifiedsincev  s    c         C   s™   |  j  j |  j d ƒ } | j \ } } i t d 6} |  j  j |  j d | ƒ |  j  j |  j d ƒ } | j \ } } |  j | | t t ƒ d ƒ d  S(   Ns   /info/quotaR   s   /storage/xxx_col2/12345g      @(   R   R&   R   R'   RV   R   R+   R*   (   R#   R.   t   old_usedt   quotaRA   t   used(    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt
   test_quota~  s    c         C   sq  |  j  j |  j d ƒ i t d 6d d 6} |  j  j |  j d | ƒ } t j d ƒ |  j  j |  j d ƒ } |  j | j	 g  ƒ i t d 6d d 6} |  j  j |  j d | ƒ } |  j  j |  j d ƒ } |  j t
 | j	 ƒ d	 ƒ |  j  j |  j d | ƒ |  j  j |  j d ƒ } |  j t
 | j	 ƒ d	 ƒ t j d
 ƒ |  j  j |  j d ƒ } |  j t
 | j	 ƒ d ƒ d  S(   Ns   /storage/xxx_col2R   i    t   ttls   /storage/xxx_col2/12345gš™™™™™ñ?i   s   /storage/xxx_col2/123456i   gÍÌÌÌÌÌ @(   R   R   R   RV   R   R!   R"   R&   R+   R'   R*   (   R#   RA   R.   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_get_collection_ttl‡  s     c         C   s  g  t  d ƒ D]  } i t | ƒ d 6t d 6^ q } |  j j |  j d | ƒ } | j } d } x8 | D]0 } |  j j |  j d | t ƒ  f d	 d
 ƒqe Wd j	 g  t  d ƒ D] } t d ƒ ^ q¬ ƒ } |  j j |  j d | ƒ } |  j
 | j g  ƒ |  j j |  j d d	 d ƒd  S(   Ni
   R8   R   s   /storage/xxx_col2t   newert   limitt   offsets   /storage/xxx_col2?%s=%sRS   i  t   ,id   s   /storage/xxx_col2?ids=%ss   /storage/xxx_col2?blabla=1iÈ   (   Rx   Ry   Rz   (   R   R    RV   R   R   R   R'   R&   R   R   R+   (   R#   R   RG   R.   t   argst   argt   ids(    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_weird_argsŸ  s    3	.c         C   sÑ   g  t  d ƒ D] } i d | d 6t d 6^ q } |  j j |  j d | ƒ } | j } d j g  t  d ƒ D] } d | ^ qi ƒ } |  j j |  j d | ƒ |  j j |  j d | ƒ } |  j	 | j g  ƒ d  S(	   Ni   s'   {6820f3ca-6e8a-4ff4-8af7-8b3625d7d65%d}R8   R   s   /storage/passwordsR{   i   s   /storage/passwords?ids=%s(
   R   RV   R   R   R   R'   R   R   R&   Rb   (   R#   R   RG   R.   R~   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_guid_deletionµ  s    .		#c         C   s!   |  j  j |  j d d d ƒd  S(   Ns'   /info/collections?client=FxHome&v=1.1b2RS   iÈ   (   R   R&   R   (   R#   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_metricsÅ  s    c   
      C   s…  |  j  j |  j d ƒ } t j | j d t ƒ} g  } t d ƒ } xu | D]m } | d } y |  j | | j	 | ƒ ƒ Wn0 t
 k
 r© d } | | j 7} t | ƒ ‚ n X| j | ƒ qJ W| j ƒ  t | d ƒ } |  j  j |  j d | ƒ }	 |	 j }	 |	 j ƒ  y |  j |	 d d	 g ƒ Wn_ t k
 r€d
 | } | d |  j  j |  j d ƒ j 7} | d t | ƒ 7} t | ƒ ‚ n Xd  S(   Ns   /storage/xxx_col2?full=1t   use_decimals   1.00R;   s   could not quantize iýÿÿÿs   /storage/xxx_col2?newer=%sR5   R6   s   Stamp used: %st    s    Stamps received: %s(   R   R&   R   R'   RP   RN   t   TrueR    Rb   t   quantizet   BaseExceptiont   AssertionErrorR@   R1   Rm   R+   R    (
   R#   R-   RG   t   stampst	   two_placeRA   t   stampt   msgRB   R.   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_roundingÊ  s4    

	

c         C   s  i d d 6t  d 6} i d d 6t  d 6} | | g } |  j j |  j d | ƒ } t j | j d t ƒd } t j	 d ƒ i d	 d 6t  d 6} i d
 d 6t  d 6} | | g } |  j j |  j d | ƒ } |  j j
 |  j d | ƒ } | j } | j ƒ  |  j | d	 d
 g ƒ d  S(   NR   R8   R   R4   s   /storage/xxx_mehR‚   R;   gš™™™™™É?R5   R6   s   /storage/xxx_meh?newer=%s(   RV   R   R   R   R'   RP   RN   R„   R!   R"   R&   R1   R+   (   R#   R_   R`   RG   R.   RB   Rf   t   wbo4(    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_strict_newerõ  s    	
c         C   s  i d d 6t  d 6} i d d 6t  d 6} | | g } |  j j |  j d | ƒ } t j | j d t ƒd } t j	 d ƒ i d	 d 6t  d 6} i d
 d 6t  d 6} | | g } |  j j |  j d | ƒ |  j j
 |  j d | ƒ } | j } | j ƒ  |  j | d	 d
 g ƒ d  S(   NR   R8   R   R4   s   /storage/tabsR‚   R;   gš™™™™™É?R5   R6   s   /storage/tabs?newer=%s(   RV   R   R   R   R'   RP   RN   R„   R!   R"   R&   R1   R+   (   R#   R_   R`   RG   R.   RB   Rf   R   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_strict_newer_tabs  s    	
c         C   sd  d } |  j  j |  j d | d d ƒ} |  j t | j ƒ t ƒ d } |  j  j |  j d | d d ƒ} |  j t | j ƒ t ƒ i d d g d 6i d	 d
 6d 6} |  j  j |  j d | d d ƒ} |  j t | j ƒ t ƒ d } |  j  j |  j d | d d ƒ} |  j t | j ƒ t ƒ d } |  j  j |  j d | d d ƒ} |  j t | j ƒ t ƒ d  S(   Nt   notawbos   /storage/xxx_col2/invalidRS   i  i*   R   R4   R8   R6   R5   R   t   notalists   /storage/xxx_col2(   R   R   R   R+   R,   RN   t   WEAVE_INVALID_WBOR   (   R#   RA   R.   RG   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   test_handling_of_invalid_json%  s(    		!			c         C   s©   i d d 6d d 6} |  j  j |  j d | ƒ } xr t d ƒ D]d } |  j  j |  j d ƒ j } |  j  j |  j d | ƒ } |  j t | j ƒ t | j	 d ƒ ƒ q= Wd  S(   Nt   TESTR8   t   DATAR   s   /storage/xxx_col2/TESTiÈ   s   X-Weave-Timestamp(
   R   R   R   t   xrangeR&   R'   R+   Rm   RN   R   (   R#   RA   R.   R   (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt+   test_that_put_reports_consistent_timestampsG  s    c         C   sŠ   i d d 6d d 6} |  j  j |  j d | ƒ t j d ƒ |  j  j |  j d d d ƒi d d 6d	 d 6} |  j  j |  j d | ƒ d  S(
   Nt   XYZR   i    Rv   s   /storage/xxx_col2/TESTg{®Gáz”?RS   i”  i*   (   R   R   R   R!   R"   R&   (   R#   t   bso(    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt2   test_that_expired_items_can_be_overwritten_via_PUTS  s    (   t   __name__t
   __module__R   R/   R2   RI   RR   RT   RW   Ra   Re   Rg   Rh   Rj   Rp   Rq   Ru   Rw   R   R€   R   RŒ   RŽ   R   R“   R—   Rš   (    (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyR   #   s2   				_				%				!									+			"	t   __main__(   t   __doc__t   sysR!   R   t   stringt
   simplejsonR'   t   decimalR    t$   syncstorage.tests.functional.supportR   R   R’   RV   t   ascii_letterst   digitsR	   R   R   R›   t   argvR.   t   exit(    (    (    sf   /var/www/syncserver/local/lib/python2.7/site-packages/syncstorage/tests/functional/test_old_storage.pyt   <module>   s$   
ÿ ÿ >