ó
ÊdYN2  c           @   s  d  d l  Z d  d l j j Z d  d l Z d  d l 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 Z d Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ 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# „  Z0 d$ „  Z1 d% „  Z2 d& „  Z3 d' „  Z4 d( „  Z5 d) „  Z6 d S(*   iÿÿÿÿN(   t	   get_rules(   t
   exceptionss   tests/data/bad_credentials.jsont   MockServiceAccountCredentialsc           B   s   e  Z e d  „  ƒ Z RS(   c         C   s
   | | f S(   N(    (   t   clst   filet   scopes(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   from_json_keyfile_name(   s    (   t   __name__t
   __module__t   classmethodR   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR   '   s   t   MockCredsIdentityc           B   s   e  Z d  „  Z RS(   c         C   s   | S(   N(    (   t   selft   arg(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt	   authorize.   s    (   R   R   R   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR
   -   s   t   MockCredsRaiseOauth2c           B   s   e  Z d  „  Z RS(   c         C   s   t  j j ƒ  ‚ d  S(   N(   t   oauth2clientt   clientt   HttpAccessTokenRefreshError(   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR   3   s    (   R   R   R   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR   2   s   t	   MockDrivec           B   s\   e  Z d  „  Z d „  Z d	 d	 d	 d „ Z d „  Z d	 d	 d „ Z d „  Z d d d „ Z	 RS(
   c         C   sM   t  t |  ƒ j ƒ  d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _	 d  S(   N(
   t   superR   t   __init__t   Nonet   defaultt   file_idt	   mime_typet   qt   order_byt   type(   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR   8   s    					c         C   s   |  S(   N(    (   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   filesA   s    c         C   s   | |  _  | |  _ | |  _ |  S(   N(   R   R   t   fields(   R   R   t   orderByR   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   listD   s    			c         C   s   |  S(   N(    (   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   executeJ   s    c         C   s   | |  _  | |  _ |  S(   N(   R   R   (   R   t   fileIdt   mimeType(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   exportM   s    		c         C   s   | |  _  | |  _ |  S(   N(   R   R   (   R   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   getR   s    		s   utf-8t   strictc         C   s   |  S(   N(    (   R   t   encodingt   errors(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   decodeW   s    N(
   R   R   R   R   R   R   R    R#   R$   R(   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR   7   s   					c         C   s   t  ƒ  S(   N(   R
   (   t	   json_file(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   mock_google_credentials]   s    c         C   s   |  j  t j ƒ  ƒ S(   N(   R   t   httplib2t   Http(   t   creds(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   mock_authorize_connectiona   s    c         C   sT  |  j  t j d t ƒ d } t j } | | ƒ } | t j f } | | k } | s>t j d | f d | | f ƒ i d t	 j
 ƒ  k s” t j t ƒ r£ t j t ƒ n d d 6t j | ƒ d 6t j | ƒ d 6d	 t	 j
 ƒ  k së t j | ƒ rú t j | ƒ n d	 d
 6t j | ƒ d 6} d i | d 6} t t j | ƒ ƒ ‚ n  d } } } } d S(   s*   The google credentials are called properlyt   ServiceAccountCredentialss	   some files   ==sX   %(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.google_credentials
}(%(py3)s)
} == %(py8)sR    t   py0t   py8t   py2R   t   py3t   py5t    s   assert %(py10)st   py10N(   s   ==(   sX   %(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.google_credentials
}(%(py3)s)
} == %(py8)ss   assert %(py10)s(   t   setattrR   t   service_accountR   R    t   google_credentialst   SCOPESt
   @pytest_art   _call_reprcomparet   @py_builtinst   localst   _should_repr_global_namet	   _safereprt   AssertionErrort   _format_explanationR   (   t   monkeypatchR   t   @py_assert1t   @py_assert4t   @py_assert7t   @py_assert6t   @py_format9t   @py_format11(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_google_credentials_successg   s    	     Ã   c           C   s*   t  j t j ƒ  t j d ƒ Wd QXd S(   s,   A non-existant json file raises an exceptions   no_such.jsonN(   t   pytestt   raisest   ext   NoGoogleCredentialsFileErrorR    R9   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt&   test_google_credentials_file_existanceq   s    c         C   s\   d t  f d „  ƒ  Y} |  j t j d | ƒ d } t j t j ƒ  t j	 | ƒ Wd QXd S(   s<   Bad permissions on the json credentials file raises an errort"   MockServiceAccountCredentialsRaisec           B   s   e  Z e d  „  ƒ Z RS(   c         S   s   t  t j d ƒ ‚ d  S(   Ns   bogus permission error(   t   IOErrort   errnot   EPERM(   R   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR   z   s    (   R   R   R	   R   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyRP   y   s   R/   s	   some fileN(
   t   objectR7   R   R8   RK   RL   RM   t   InsufficientPermissionsErrorR    R9   (   RC   RP   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt(   test_google_credentials_file_permissionsw   s    c         C   sY   d t  f d „  ƒ  Y} |  j t j d | ƒ d } t j t ƒ  t j | ƒ Wd QXd S(   s6   "Other" ioerror on json credentials file raises itselfRP   c           B   s   e  Z e d  „  ƒ Z RS(   c         S   s   t  t j d ƒ ‚ d  S(   Ns   bogus disk full error(   RQ   RR   t   ENOSPC(   R   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR   Š   s    (   R   R   R	   R   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyRP   ‰   s   R/   s	   some fileN(	   RT   R7   R   R8   RK   RL   RQ   R    R9   (   RC   RP   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt%   test_google_credentials_other_ioerror‡   s    c           C   s-   t  j t j ƒ  t j t j ƒ Wd QXd S(   s#   A non-json file raises an exceptionN(   RK   RL   RM   t   NotAServiceAccountErrorR    R9   t   libtestt   TEST_CONFIG_PATH(    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt    test_google_credentials_not_json—   s    c           C   s*   t  j t j ƒ  t j t ƒ Wd QXd S(   s#   A bad json file raises an exceptionN(   RK   RL   RM   t   InvalidGoogleCredentialsErrorR    R9   t   INVALID_JSON_PATH(    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt    test_google_credentials_bad_json   s    c          C   s©  t  j }  t ƒ  } |  | ƒ } t j } t | | ƒ } | rd d i	 t j | ƒ d 6d t j	 ƒ  k pu t j
 t ƒ r‡ t j t ƒ n d d 6t j | ƒ d 6d t j	 ƒ  k p¼ t j
 t ƒ rÎ t j t ƒ n d d 6d	 t j	 ƒ  k pó t j
 t  ƒ rt j t  ƒ n d	 d
 6t j |  ƒ d 6d t j	 ƒ  k p:t j
 t ƒ rLt j t ƒ n d d 6t j | ƒ d 6t j | ƒ d 6} t t j | ƒ ƒ ‚ n  t }  } } } } d S(   s.   Authorizing a connection returns a http objectR5   s²   assert %(py13)s
{%(py13)s = %(py0)s(%(py8)s
{%(py8)s = %(py3)s
{%(py3)s = %(py1)s.authorize_connection
}(%(py6)s
{%(py6)s = %(py4)s()
})
}, %(py11)s
{%(py11)s = %(py9)s.Http
})
}R1   R+   t   py9t   py11t
   isinstanceR0   R    t   py1R3   R
   t   py4t   py6t   py13N(   R    t   authorize_connectionR
   R+   R,   Rb   R;   R@   R=   R>   R?   RA   RB   R   (   t   @py_assert2t   @py_assert5RF   t   @py_assert10t   @py_assert12t   @py_format14(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt!   test_authorize_connection_success¥   s    	 	  	   ÿ ;  c           C   s-   t  j t j ƒ  t j t ƒ  ƒ Wd QXd S(   s1   Failing to authorize a connection raises an errorN(   RK   RL   RM   t   GoogleAuthorizationErrorR    Rg   R   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_authorize_connection_fail«   s    c   
      C   s9  d d „ } |  j t j d | ƒ t j t ƒ  t ƒ \ } } } t j } | | k } | s't	 j
 d | f d | | f ƒ i d t j ƒ  k s t	 j | ƒ r¬ t	 j | ƒ n d d 6d t j ƒ  k sÔ t	 j t ƒ rã t	 j t ƒ n d d 6t	 j | ƒ d	 6} d i | d 6} t t	 j | ƒ ƒ ‚ n  d } } t j } | | k } | st	 j
 d | f d | | f ƒ i d t j ƒ  k sŽt	 j | ƒ rt	 j | ƒ n d d 6d t j ƒ  k sÅt	 j t ƒ rÔt	 j t ƒ n d d 6t	 j | ƒ d	 6} d i | d 6} t t	 j | ƒ ƒ ‚ n  d } } t j } t | | ƒ }	 |	 s+d
 d i d t j ƒ  k skt	 j t ƒ rzt	 j t ƒ n d d 6d t j ƒ  k s¢t	 j | ƒ r±t	 j | ƒ n d d 6d t j ƒ  k sÙt	 j t ƒ rèt	 j t ƒ n d d 6t	 j | ƒ d	 6t	 j |	 ƒ d 6} t t	 j | ƒ ƒ ‚ n  d } }	 d S(   s=   The Google API build function is called with the correct argsc         S   s   |  | | f S(   N(    (   t   apit   versiont   http(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt
   mock_buildµ   s    t   builds   ==s1   %(py0)s == %(py4)s
{%(py4)s = %(py2)s.DRIVE_API
}Rp   R0   R    R2   Rd   R5   s   assert %(py6)sRe   s5   %(py0)s == %(py4)s
{%(py4)s = %(py2)s.DRIVE_VERSION
}Rq   sO   assert %(py6)s
{%(py6)s = %(py0)s(%(py1)s, %(py4)s
{%(py4)s = %(py2)s.Http
})
}Rb   Rr   Rc   R+   N(   s   ==(   s1   %(py0)s == %(py4)s
{%(py4)s = %(py2)s.DRIVE_API
}s   assert %(py6)s(   s   ==(   s5   %(py0)s == %(py4)s
{%(py4)s = %(py2)s.DRIVE_VERSION
}s   assert %(py6)s(   R   R7   t   googleapiclientt	   discoveryR    t   build_driveR
   R.   t	   DRIVE_APIR;   R<   R=   R>   R?   R@   RA   RB   t   DRIVE_VERSIONR+   R,   Rb   (
   RC   Rs   Rp   Rq   Rr   t   @py_assert3RD   t   @py_format5t   @py_format7Ri   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_build_drive_success³   s0    	   £   
	   £   
	   Ó  c           C   s0   t  j t j ƒ  t j t ƒ  t ƒ Wd QXd S(   s?   The Google API build function raises an error when oauth2 failsN(   RK   RL   RM   t   GoogleDriveConnectionErrorR    Rw   R   R.   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_build_drive_fail_oauth2Á   s    c         C   sR   d d „ } |  j t j d | ƒ t j t j ƒ  t j	 t
 ƒ  t ƒ Wd QXd S(   s@   The Google API build function raises an error when the api failsc         S   s   t  j j ƒ  ‚ d  S(   N(   Ru   R'   t   Error(   Rp   Rq   Rr   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyRs   Ê   s    Rt   N(   R   R7   Ru   Rv   RK   RL   RM   R~   R    Rw   R
   R.   (   RC   Rs   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt%   test_build_drive_fail_googleapiclientÈ   s    c          C   sØ  t  ƒ  }  d } t j |  | ƒ |  j } | d k	 } | st j d | f d | d f ƒ i d t j ƒ  k s| t j	 |  ƒ r‹ t j
 |  ƒ n d d 6t j
 | ƒ d 6d t j ƒ  k sÃ t j	 d ƒ rÒ t j
 d ƒ n d d 6} d i | d 6} t t j | ƒ ƒ ‚ n  d } } |  j } | d k	 } | s÷t j d | f d | d f ƒ i d t j ƒ  k smt j	 |  ƒ r|t j
 |  ƒ n d d 6t j
 | ƒ d 6d t j ƒ  k s´t j	 d ƒ rÃt j
 d ƒ n d d 6} d i | d 6} t t j | ƒ ƒ ‚ n  d } } |  j } | d k	 } | sèt j d | f d | d f ƒ i d t j ƒ  k s^t j	 |  ƒ rmt j
 |  ƒ n d d 6t j
 | ƒ d 6d t j ƒ  k s¥t j	 d ƒ r´t j
 d ƒ n d d 6} d i | d 6} t t j | ƒ ƒ ‚ n  d } } |  j } | d k	 } | sÙt j d | f d | d f ƒ i d t j ƒ  k sOt j	 |  ƒ r^t j
 |  ƒ n d d 6t j
 | ƒ d 6d t j ƒ  k s–t j	 d ƒ r¥t j
 d ƒ n d d 6} d i | d 6} t t j | ƒ ƒ ‚ n  d } } |  j } | d k	 } | sÊt j d | f d | d f ƒ i d t j ƒ  k s@t j	 |  ƒ rOt j
 |  ƒ n d d 6t j
 | ƒ d 6d t j ƒ  k s‡t j	 d ƒ r–t j
 d ƒ n d d 6} d i | d 6} t t j | ƒ ƒ ‚ n  d } } d S(    s;   We call the google drive object with the expected argumentss	   some names   is nots-   %(py2)s
{%(py2)s = %(py0)s.q
} is not %(py4)st
   mock_driveR0   R2   R   Rd   R5   s   assert %(py6)sRe   s4   %(py2)s
{%(py2)s = %(py0)s.order_by
} is not %(py4)ss2   %(py2)s
{%(py2)s = %(py0)s.fields
} is not %(py4)ss0   %(py2)s
{%(py2)s = %(py0)s.type
} is not %(py4)ss3   %(py2)s
{%(py2)s = %(py0)s.default
} is not %(py4)sN(   s   is not(   s-   %(py2)s
{%(py2)s = %(py0)s.q
} is not %(py4)ss   assert %(py6)s(   s   is not(   s4   %(py2)s
{%(py2)s = %(py0)s.order_by
} is not %(py4)ss   assert %(py6)s(   s   is not(   s2   %(py2)s
{%(py2)s = %(py0)s.fields
} is not %(py4)ss   assert %(py6)s(   s   is not(   s0   %(py2)s
{%(py2)s = %(py0)s.type
} is not %(py4)ss   assert %(py6)s(   s   is not(   s3   %(py2)s
{%(py2)s = %(py0)s.default
} is not %(py4)ss   assert %(py6)s(   R   R    t   get_drive_file_infoR   R   R;   R<   R=   R>   R?   R@   RA   RB   R   R   R   R   (   R‚   t   nameRD   Rz   R{   R|   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt    test_get_drive_file_info_successÕ   sL    		   £   
	   £   
	   £   
	   £   
	   £   c          C   sF   d t  f d „  ƒ  Y}  t j t j ƒ  t j |  ƒ  d ƒ Wd QXd S(   s[   We get an exception when google drive api raises one although the
    supplied name is goodt   MockDriveRaiseClientc           B   s   e  Z d  „  Z RS(   c         S   s   t  j j ƒ  ‚ d  S(   N(   Ru   R'   R€   (   R   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR$   æ   s    (   R   R   R$   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR†   å   s   s	   some nameN(   R   RK   RL   RM   t   GoogleListErrorR    Rƒ   (   R†   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt,   test_get_drive_file_info_fail_drive_goodnameâ   s    c            s~   d t  j j f d „  ƒ  Y‰  d t f ‡  f d †  ƒ  Y} |  j t  j d ˆ  ƒ t j t j ƒ  t	 j
 | ƒ  d ƒ Wd QXd S(   sV   We get an exception when google drive api raises one when the
    supplied name is badt   MockHttpErrorc           B   s   e  Z d  „  Z RS(   c         S   s   i d d 6|  _  d  S(   Nt   400t   status(   t   resp(   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR   ñ   s    (   R   R   R   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR‰   ð   s   R†   c              s   e  Z ‡  f d  †  Z RS(   c            s   ˆ  ƒ  } | ‚ d  S(   N(    (   R   R   R   t   err(   R‰   (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR$   õ   s    	(   R   R   R$   (    (   R‰   (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR†   ô   s   t	   HttpErrors	   some nameN(   Ru   R'   R€   R   R7   RK   RL   RM   t   InvalidGoogleListCallErrorR    Rƒ   (   RC   R†   (    (   R‰   sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt+   test_get_drive_file_info_fail_drive_badnameí   s
    c          C   sF   d t  f d „  ƒ  Y}  t j t j ƒ  t j |  ƒ  d ƒ Wd QXd S(   s5   We get an exception when google oauth2 api raises onet   MockDriveRaiseOauth2c           B   s   e  Z d  „  Z RS(   c         S   s   t  j j ƒ  ‚ d  S(   N(   R   R   R€   (   R   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR$     s    (   R   R   R$   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR‘     s   s	   some nameN(   R   RK   RL   RM   R‡   R    Rƒ   (   R‘   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt$   test_get_drive_file_info_fail_oauth2ÿ   s    c    	      C   s+  t  ƒ  }  d } d } t j |  | | ƒ |  j } | | k } | st j d | f d | | f ƒ i d t j ƒ  k s… t j |  ƒ r” t j	 |  ƒ n d d 6t j	 | ƒ d 6d t j ƒ  k sÌ t j | ƒ rÛ t j	 | ƒ n d d	 6} d i | d 6} t
 t j | ƒ ƒ ‚ n  d } } |  j } t j } | | k } | st j d | f d | | f ƒ i d t j ƒ  k st j |  ƒ rŽt j	 |  ƒ n d d 6t j	 | ƒ d 6d t j ƒ  k sÆt j t ƒ rÕt j	 t ƒ n d d	 6t j	 | ƒ d 6} d i | d 6} t
 t j | ƒ ƒ ‚ n  d } } } d S(   s-   The google drive object is called as expecteds   some ids	   some names   ==s/   %(py2)s
{%(py2)s = %(py0)s.file_id
} == %(py4)sR‚   R0   R2   t   idRd   R5   s   assert %(py6)sRe   sS   %(py2)s
{%(py2)s = %(py0)s.mime_type
} == %(py6)s
{%(py6)s = %(py4)s.DST_MIMETYPE
}R    s   assert %(py8)sR1   N(   s   ==(   s/   %(py2)s
{%(py2)s = %(py0)s.file_id
} == %(py4)ss   assert %(py6)s(   s   ==(   sS   %(py2)s
{%(py2)s = %(py0)s.mime_type
} == %(py6)s
{%(py6)s = %(py4)s.DST_MIMETYPE
}s   assert %(py8)s(   R   R    t   download_sheetR   R;   R<   R=   R>   R?   R@   RA   RB   R   R   t   DST_MIMETYPE(	   R‚   R“   R„   RD   Rz   R{   R|   Ri   RH   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_download_sheet_success  s&    		   £   
	 	   ³   c          C   sI   d t  f d „  ƒ  Y}  t j t j ƒ  t j |  ƒ  d d ƒ Wd QXd S(   s4   We get an exception when google drive api raises oneR†   c           B   s   e  Z d  „  Z RS(   c         S   s   t  j j ƒ  ‚ d  S(   N(   Ru   R'   R€   (   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR      s    (   R   R   R    (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR†     s   s   some ids	   some nameN(   R   RK   RL   RM   t   GoogleDownloadErrorR    R”   (   R†   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_download_sheet_fail_drive  s    c          C   sI   d t  f d „  ƒ  Y}  t j t j ƒ  t j |  ƒ  d d ƒ Wd QXd S(   s5   We get an exception when google oauth2 api raises oneR‘   c           B   s   e  Z d  „  Z RS(   c         S   s   t  j j ƒ  ‚ d  S(   N(   R   R   R€   (   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR    $  s    (   R   R   R    (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR‘   #  s   s   some ids	   some nameN(   R   RK   RL   RM   R—   R    R”   (   R‘   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_download_sheet_fail_oauth2!  s    c          C   sI   d t  f d „  ƒ  Y}  t j t j ƒ  t j |  ƒ  d d ƒ Wd QXd S(   s6   We get an exception when google returns no spreadsheett   MockDriveNonec           B   s   e  Z d  „  Z RS(   c         S   s   d  S(   N(   R   (   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR    /  s    (   R   R   R    (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyRš   .  s   s   some ids	   some nameN(   R   RK   RL   RM   t   NoSheetDownloadedErrorR    R”   (   Rš   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt    test_download_sheet_fail_content,  s    c            s*  d t  f d „  ƒ  Y‰  d ‡  f d † } |  j t d t ƒ |  j t j d | ƒ t j d t d ƒ \ } } d g } | | k } | st	 j
 d | f d | | f ƒ i d t j ƒ  k sÉ t	 j | ƒ rØ t	 j | ƒ n d d 6t	 j | ƒ d 6} d i | d 6} t t	 j | ƒ ƒ ‚ n  d } } d S(   s5   We get something back when the download is successfult   MockDriveDatac           B   s)   e  Z d  d d „ Z d „  Z d „  Z RS(   s   utf-8R%   c         S   s   d S(   Ns   MockDriveData()
(    (   R   R&   R'   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR(   <  s    c         S   s   i d d 6g S(   Ns   some idR“   (    (   R   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR$   ?  s    c         S   s   |  S(   N(    (   R   t   value(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   splitB  s    (   R   R   R(   R$   RŸ   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR   ;  s   	c            s   ˆ  ƒ  S(   N(    (   Rp   Rq   Rr   (   R   (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyRs   E  s    R9   Rt   s
   creds.jsons	   some names   MockDriveData()
s   ==s   %(py0)s == %(py3)st   rulesR0   R3   R5   s   assert %(py5)sR4   N(   s   ==(   s   %(py0)s == %(py3)ss   assert %(py5)s(   R   R   R7   R    R*   Ru   Rv   t   rules_from_googleR.   R;   R<   R=   R>   R?   R@   RA   RB   (   RC   Rs   t   metainfoR    Rh   RD   t   @py_format4t   @py_format6(    (   R   sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_rules_from_google_success9  s    
	   l   c            s   d t  f d „  ƒ  Y‰  d ‡  f d † } |  j t d t ƒ |  j t j d | ƒ t j t	 j
 ƒ  t j d t d ƒ Wd QXd S(	   s?   We get an exception when the spreadsheet is not found by googlet   MockDriveNoSheetc           B   s   e  Z d  „  Z RS(   c         S   s   g  S(   N(    (   R   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR$   T  s    (   R   R   R$   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyR¦   S  s   c            s   ˆ  ƒ  S(   N(    (   Rp   Rq   Rr   (   R¦   (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyRs   W  s    R9   Rt   s
   creds.jsons	   some nameN(   R   R   R7   R    R*   Ru   Rv   RK   RL   RM   t   NoSuchSpreadsheetErrorR¡   R.   (   RC   Rs   (    (   R¦   sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_rules_from_google_failQ  s    c         C   s_   d „  } |  j  t d t ƒ |  j  t d | ƒ t j t j ƒ  t j d d d ƒ Wd QXd S(   s1   We get an exception when httplib2 raises an errorc         S   s   t  j d ƒ ‚ d  S(   Ns   test exception(   R+   t   HttpLib2Error(   R-   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   mock_build_drivee  s    R9   Rw   s
   creds.jsons	   some nameN(	   R7   R    R*   RK   RL   RM   R©   R¡   R   (   RC   Rª   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt    test_rules_from_google_httperrorc  s    	c          C   sÀ   t  j d ƒ \ }  } | d d !} d d g } | | k } | s® t j d | f d | | f ƒ i t j | ƒ d 6t j | ƒ d	 6} d i | d 6} t t j | ƒ ƒ ‚ n  d } } } d S(   s,   The first 2 lines of a rule file can be reads   sample_rules.csvi    i   s   line 1
s   line 2
s   ==s   %(py1)s == %(py4)sRc   Rd   R5   s   assert %(py6)sRe   N(   s   ==(   s   %(py1)s == %(py4)ss   assert %(py6)s(   R    t   rules_from_fileR;   R<   R@   RA   RB   R   (   R¢   t   datat   @py_assert0Rz   Rh   R{   R|   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_rules_from_file_firstr  s        E   c          C   s·   t  j d ƒ \ }  } | d } d } | | k } | s¥ t j d | f d | | f ƒ i t j | ƒ d 6t j | ƒ d 6} d i | d
 6} t t j | ƒ ƒ ‚ n  d } } } d S(   s(   The last line of a rule file can be reads   sample_rules.csviÿÿÿÿs
   last line
s   ==s   %(py1)s == %(py4)sRc   Rd   R5   s   assert %(py6)sRe   N(   s   ==(   s   %(py1)s == %(py4)ss   assert %(py6)s(   R    R¬   R;   R<   R@   RA   RB   R   (   R¢   R­   R®   Rz   Rh   R{   R|   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_rules_from_file_lastx  s    
    E   c           C   s*   t  j t j ƒ  t j d ƒ Wd QXd S(   s,   A non-existant rule file raises an exceptions   no_such.csvN(   RK   RL   RM   t   NoRulesFileErrorR    R¬   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_rule_file_existance~  s    c   	      C   sb  d „  } |  j  t d | ƒ d } t j } i t j d 6| d 6} | | ƒ } | | k } | sLt j d | f d | | f ƒ i d t j ƒ  k s¢ t j t ƒ r± t j	 t ƒ n d d	 6d
 t j ƒ  k sÙ t j | ƒ rè t j	 | ƒ n d
 d 6t j	 | ƒ d 6t j	 | ƒ d 6t j	 | ƒ d 6} d i | d 6} t
 t j | ƒ ƒ ‚ n  d } } } } d S(   s   Return rules from a filec         S   s   |  S(   N(    (   t   path(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   mock_rules_from_fileˆ  s    R¬   s	   some/patht   rules_sourcet
   rules_paths   ==sS   %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.get_rule_file
}(%(py4)s)
} == %(py8)sR    R0   R³   R1   R2   Rd   Re   R5   s   assert %(py10)sR6   N(   s   ==(   sS   %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.get_rule_file
}(%(py4)s)
} == %(py8)ss   assert %(py10)s(   R7   R    t   get_rule_filet   FILE_SOURCER;   R<   R=   R>   R?   R@   RA   RB   R   (	   RC   R´   R³   RD   Rz   Ri   RF   RH   RI   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_get_rule_file_file†  s    		     Ã   c         C   s^  d „  } |  j  t d | ƒ d } d } t j } i t j d 6| d 6| d 6} | | ƒ } | t j | f } | | k } | sDt j d | f d | | f ƒ i d
 t j ƒ  k sÁ t j	 t ƒ rÐ t j
 t ƒ n d
 d 6t j
 | ƒ d 6t j
 | ƒ d 6t j
 | ƒ d 6t j
 | ƒ d 6}	 d i |	 d 6}
 t t j |
 ƒ ƒ ‚ n  d } } } } } d S(   s   Return rules from googlec         S   s   |  | | f S(   N(    (   R-   R   R„   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   mock_rules_from_google•  s    R¡   s	   some.jsons	   some nameRµ   R9   t   spreadsheet_names   ==sS   %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.get_rule_file
}(%(py4)s)
} == %(py9)sR    R0   R`   R2   Rd   Re   R5   s   assert %(py11)sRa   N(   s   ==(   sS   %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.get_rule_file
}(%(py4)s)
} == %(py9)ss   assert %(py11)s(   R7   R    R·   t   GOOGLE_SOURCERg   R;   R<   R=   R>   R?   R@   RA   RB   R   (   RC   Rº   R-   R„   RD   Rz   Ri   t   @py_assert8RF   t   @py_format10t   @py_format12(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   test_get_rule_file_google“  s    		      œ   (7   t   __builtin__R=   t   _pytest.assertion.rewritet	   assertiont   rewriteR;   RR   t   googleapiclient.discoveryRu   t   googleapiclient.errorsR+   t   oauth2client.clientR   t   oauth2client.service_accountRK   t   enforcerR    R   RM   RZ   R^   RT   R   R
   R   R   R*   R.   RJ   RO   RV   RX   R\   R_   Rm   Ro   R}   R   R   R…   Rˆ   R   R’   R–   R˜   R™   Rœ   R¥   R¨   R«   R¯   R°   R²   R¹   RÀ   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyt   <module>   sZ     &			
																									