
dYN2                 @   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 Gd d   d e  Z Gd d   d e  Z Gd	 d
   d
 e  Z Gd d   d e  Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z  d d   Z! d d   Z" d d    Z# d! d"   Z$ d# d$   Z% d% d&   Z& d' d(   Z' d) d*   Z( d+ d,   Z) d- d.   Z* d/ d0   Z+ d1 d2   Z, d3 d4   Z- d5 d6   Z. d7 d8   Z/ d9 d:   Z0 d; d<   Z1 d= d>   Z2 d? d@   Z3 dA dB   Z4 dC dD   Z5 dE dF   Z6 d S)G    N)	get_rules)
exceptionsztests/data/bad_credentials.jsonc               @   s"   e  Z d  Z e d d    Z d S)MockServiceAccountCredentialsc             C   s
   | | f S)N )clsfilescopesr   r   T/home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_get_rules.pyfrom_json_keyfile_name(   s    z4MockServiceAccountCredentials.from_json_keyfile_nameN)__name__
__module____qualname__classmethodr
   r   r   r   r	   r   '   s   r   c               @   s   e  Z d  Z d d   Z d S)MockCredsIdentityc             C   s   | S)Nr   )selfargr   r   r	   	authorize.   s    zMockCredsIdentity.authorizeN)r   r   r   r   r   r   r   r	   r   -   s   r   c               @   s   e  Z d  Z d d   Z d S)MockCredsRaiseOauth2c             C   s   t  j j    d  S)N)oauth2clientclientHttpAccessTokenRefreshError)r   r   r   r   r	   r   3   s    zMockCredsRaiseOauth2.authorizeN)r   r   r   r   r   r   r   r	   r   2   s   r   c                   s   e  Z d  Z   f d d   Z d d   Z d d d d d  Z d d	   Z d d d
 d  Z d d   Z d d d d  Z	   S)	MockDrivec                sM   t  t |   j   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  S)N)	superr   __init__defaultfile_id	mime_typeqorder_bytype)r   )	__class__r   r	   r   8   s    					zMockDrive.__init__c             C   s   |  S)Nr   )r   r   r   r	   filesA   s    zMockDrive.filesNc             C   s   | |  _  | |  _ | |  _ |  S)N)r   r   fields)r   r   orderByr"   r   r   r	   listD   s    			zMockDrive.listc             C   s   |  S)Nr   )r   r   r   r	   executeJ   s    zMockDrive.executec             C   s   | |  _  | |  _ |  S)N)r   r   )r   fileIdmimeTyper   r   r	   exportM   s    		zMockDrive.exportc             C   s   | |  _  | |  _ |  S)N)r   r   )r   r   r   r   r   r	   getR   s    		zMockDrive.getzutf-8strictc             C   s   |  S)Nr   )r   encodingerrorsr   r   r	   decodeW   s    zMockDrive.decode)
r   r   r   r   r!   r$   r%   r(   r)   r-   r   r   )r    r	   r   7   s   	r   c             C   s   t    S)N)r   )	json_filer   r   r	   mock_google_credentials]   s    r/   c             C   s   |  j  t j    S)N)r   httplib2Http)credsr   r   r	   mock_authorize_connectiona   s    r3   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)z*The google credentials are called properlyServiceAccountCredentialsz	some file==X%(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.google_credentials
}(%(py3)s)
} == %(py8)sr   py0py2py5r   py3py8 assert %(py10)spy10N)r5   )r6   r=   )setattrr   service_accountr   r   google_credentialsSCOPES
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation)monkeypatchr   @py_assert1@py_assert4@py_assert7@py_assert6@py_format9@py_format11r   r   r	   test_google_credentials_successg   s    	        rR   c            	   C   s*   t  j t j   t j d  Wd QXd S)z,A non-existant json file raises an exceptionzno_such.jsonN)pytestraisesexNoGoogleCredentialsFileErrorr   rA   r   r   r   r	   &test_google_credentials_file_existanceq   s    rW   c          	   C   s\   Gd d   d t   } |  j t j d |  d } t j t j   t j	 |  Wd QXd S)z<Bad permissions on the json credentials file raises an errorc               @   s"   e  Z d  Z e d d    Z d S)zTtest_google_credentials_file_permissions.<locals>.MockServiceAccountCredentialsRaisec             S   s   t  t j d   d  S)Nzbogus permission error)IOErrorerrnoEPERM)r   r   r   r   r   r	   r
   z   s    zktest_google_credentials_file_permissions.<locals>.MockServiceAccountCredentialsRaise.from_json_keyfile_nameN)r   r   r   r   r
   r   r   r   r	   "MockServiceAccountCredentialsRaisey   s   r[   r4   z	some fileN)
objectr?   r   r@   rS   rT   rU   InsufficientPermissionsErrorr   rA   )rK   r[   r   r   r   r	   (test_google_credentials_file_permissionsw   s    r^   c          	   C   sY   Gd d   d t   } |  j t j d |  d } t j t   t j |  Wd QXd S)z6"Other" ioerror on json credentials file raises itselfc               @   s"   e  Z d  Z e d d    Z d S)zQtest_google_credentials_other_ioerror.<locals>.MockServiceAccountCredentialsRaisec             S   s   t  t j d   d  S)Nzbogus disk full error)rX   rY   ENOSPC)r   r   r   r   r   r	   r
      s    zhtest_google_credentials_other_ioerror.<locals>.MockServiceAccountCredentialsRaise.from_json_keyfile_nameN)r   r   r   r   r
   r   r   r   r	   r[      s   r[   r4   z	some fileN)	r\   r?   r   r@   rS   rT   rX   r   rA   )rK   r[   r   r   r   r	   %test_google_credentials_other_ioerror   s    r`   c            	   C   s-   t  j t j   t j t j  Wd QXd S)z#A non-json file raises an exceptionN)rS   rT   rU   NotAServiceAccountErrorr   rA   libtestTEST_CONFIG_PATHr   r   r   r	    test_google_credentials_not_json   s    rd   c            	   C   s*   t  j t j   t j t  Wd QXd S)z#A bad json file raises an exceptionN)rS   rT   rU   InvalidGoogleCredentialsErrorr   rA   INVALID_JSON_PATHr   r   r   r	    test_google_credentials_bad_json   s    rg   c              C   s  t  j }  t   } |  |  } t j } t | |  } | rd d i	 t j |  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 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 6t j |  d 6t j |  d 6} t t j |    n  d }  } } } } d S)z.Authorizing a connection returns a http objectr<   zassert %(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
})
}py13r;   r   py1r   py4
isinstancer7   r0   py9r:   py6py11N)r   authorize_connectionr   r0   r1   rk   rC   rH   rE   rF   rG   rI   rJ   )@py_assert2@py_assert5rN   @py_assert10Z@py_assert12@py_format14r   r   r	   !test_authorize_connection_success   s    	 	  	    ;  rt   c            	   C   s-   t  j t j   t j t    Wd QXd S)z1Failing to authorize a connection raises an errorN)rS   rT   rU   GoogleAuthorizationErrorr   ro   r   r   r   r   r	   test_authorize_connection_fail   s    rv   c       
      C   s<  d 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 snt j t  r}t j t  n d d 6d t
 j   k st j t  rt j t  n d d
 6t j |	  d 6d t
 j   k st j |  rt j |  n d d 6t j |  d 6} t t j |    n  d } }	 d S)z=The Google API build function is called with the correct argsNc             S   s   |  | | f S)Nr   )apiversionhttpr   r   r	   
mock_build   s    z,test_build_drive_success.<locals>.mock_buildbuildr5   1%(py0)s == %(py4)s
{%(py4)s = %(py2)s.DRIVE_API
}rw   r7   r   r8   rj   r<   assert %(py6)srm   5%(py0)s == %(py4)s
{%(py4)s = %(py2)s.DRIVE_VERSION
}rx   zOassert %(py6)s
{%(py6)s = %(py0)s(%(py1)s, %(py4)s
{%(py4)s = %(py2)s.Http
})
}rk   r0   ry   ri   )r5   )r|   r}   )r5   )r~   r}   )r?   googleapiclient	discoveryr   build_driver   r3   	DRIVE_APIrC   rD   rE   rF   rG   rH   rI   rJ   DRIVE_VERSIONr0   r1   rk   )
rK   rz   rw   rx   ry   @py_assert3rL   @py_format5@py_format7rq   r   r   r	   test_build_drive_success   s0    	      
	      
	     r   c            
   C   s0   t  j t j   t j t   t  Wd QXd S)z?The Google API build function raises an error when oauth2 failsN)rS   rT   rU   GoogleDriveConnectionErrorr   r   r   r3   r   r   r   r	   test_build_drive_fail_oauth2   s    r   c          
   C   sU   d d d  } |  j  t j d |  t j t j   t j t	   t
  Wd QXd S)z@The Google API build function raises an error when the api failsNc             S   s   t  j j    d  S)N)r   r,   Error)rw   rx   ry   r   r   r	   rz      s    z9test_build_drive_fail_googleapiclient.<locals>.mock_buildr{   )r?   r   r   rS   rT   rU   r   r   r   r   r3   )rK   rz   r   r   r	   %test_build_drive_fail_googleapiclient   s    r   c              C   sG  t    }  d } t j |  |  |  j } d } | | 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 6t j	 |  d 6} d i | d 6} t
 t j |    n  d } } } |  j } d } | | k	 } | st j d | f d | | f  i d t j   k sVt j |   ret j	 |   n d d 6t j	 |  d 6t j	 |  d 6} d i | d 6} t
 t j |    n  d } } } |  j } d } | | k	 } | st j d | f d | | f  i d t j   k s*t j |   r9t j	 |   n d d 6t j	 |  d 6t j	 |  d 6} d i | d 6} t
 t j |    n  d } } } |  j } d } | | k	 } | sat j d | f d | | f  i d t j   k st j |   rt j	 |   n d d 6t j	 |  d 6t j	 |  d 6} d i | d 6} t
 t j |    n  d } } } |  j } d } | | k	 } | s5t j d | f d | | f  i d t j   k st j |   rt j	 |   n d d 6t j	 |  d 6t j	 |  d 6} d i | d 6} t
 t j |    n  d } } } d S)z;We call the google drive object with the expected argumentsz	some nameNis not-%(py2)s
{%(py2)s = %(py0)s.q
} is not %(py5)s
mock_driver7   r8   r9   r<   assert %(py7)spy74%(py2)s
{%(py2)s = %(py0)s.order_by
} is not %(py5)s2%(py2)s
{%(py2)s = %(py0)s.fields
} is not %(py5)s0%(py2)s
{%(py2)s = %(py0)s.type
} is not %(py5)s3%(py2)s
{%(py2)s = %(py0)s.default
} is not %(py5)s)r   )r   r   )r   )r   r   )r   )r   r   )r   )r   r   )r   )r   r   )r   r   get_drive_file_infor   rC   rD   rE   rF   rG   rH   rI   rJ   r   r"   r   r   )r   namerL   rM   r   @py_format6@py_format8r   r   r	    test_get_drive_file_info_success   sV    		    |   	    |   	    |   	    |   	    |   r   c           
   C   sF   Gd d   d t   }  t j t j   t j |    d  Wd QXd S)z[We get an exception when google drive api raises one although the
    supplied name is goodc               @   s   e  Z d  Z d d   Z d S)zJtest_get_drive_file_info_fail_drive_goodname.<locals>.MockDriveRaiseClientc             S   s   t  j j    d  S)N)r   r,   r   )r   r   r   r   r   r	   r)      s    zNtest_get_drive_file_info_fail_drive_goodname.<locals>.MockDriveRaiseClient.getN)r   r   r   r)   r   r   r   r	   MockDriveRaiseClient   s   r   z	some nameN)r   rS   rT   rU   GoogleListErrorr   r   )r   r   r   r	   ,test_get_drive_file_info_fail_drive_goodname   s    r   c          
      s~   Gd d   d t  j j    G  f d d   d t  } |  j t  j d    t j t j   t	 j
 |   d  Wd QXd S)zVWe get an exception when google drive api raises one when the
    supplied name is badc               @   s   e  Z d  Z d d   Z d S)zBtest_get_drive_file_info_fail_drive_badname.<locals>.MockHttpErrorc             S   s   i d d 6|  _  d  S)N400status)resp)r   r   r   r	   r      s    zKtest_get_drive_file_info_fail_drive_badname.<locals>.MockHttpError.__init__N)r   r   r   r   r   r   r   r	   MockHttpError   s   r   c                   s"   e  Z d  Z   f d d   Z d S)zItest_get_drive_file_info_fail_drive_badname.<locals>.MockDriveRaiseClientc                s       } |  d  S)Nr   )r   r   r   err)r   r   r	   r)      s    	zMtest_get_drive_file_info_fail_drive_badname.<locals>.MockDriveRaiseClient.getN)r   r   r   r)   r   )r   r   r	   r      s   r   	HttpErrorz	some nameN)r   r,   r   r   r?   rS   rT   rU   InvalidGoogleListCallErrorr   r   )rK   r   r   )r   r	   +test_get_drive_file_info_fail_drive_badname   s
    r   c           
   C   sF   Gd d   d t   }  t j t j   t j |    d  Wd QXd S)z5We get an exception when google oauth2 api raises onec               @   s   e  Z d  Z d d   Z d S)zBtest_get_drive_file_info_fail_oauth2.<locals>.MockDriveRaiseOauth2c             S   s   t  j j    d  S)N)r   r   r   )r   r   r   r   r   r	   r)     s    zFtest_get_drive_file_info_fail_oauth2.<locals>.MockDriveRaiseOauth2.getN)r   r   r   r)   r   r   r   r	   MockDriveRaiseOauth2  s   r   z	some nameN)r   rS   rT   rU   r   r   r   )r   r   r   r	   $test_get_drive_file_info_fail_oauth2   s    r   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 6t j	 |  d 6d t j   k st j t  rt j	 t  n d d	 6} d i | d 6} t
 t j |    n  d } } } d S)z-The google drive object is called as expectedzsome idz	some namer5   /%(py2)s
{%(py2)s = %(py0)s.file_id
} == %(py4)sr   r7   r8   idrj   r<   assert %(py6)srm   NS%(py2)s
{%(py2)s = %(py0)s.mime_type
} == %(py6)s
{%(py6)s = %(py4)s.DST_MIMETYPE
}r   assert %(py8)sr;   )r5   )r   r   )r5   )r   r   )r   r   download_sheetr   rC   rD   rE   rF   rG   rH   rI   rJ   r   DST_MIMETYPE)	r   r   r   rL   r   r   r   rq   rP   r   r   r	   test_download_sheet_success  s&    		      
	 	      r   c              C   sI   Gd d   d t   }  t j t j   t j |    d d  Wd QXd S)z4We get an exception when google drive api raises onec               @   s   e  Z d  Z d d   Z d S)z<test_download_sheet_fail_drive.<locals>.MockDriveRaiseClientc             S   s   t  j j    d  S)N)r   r,   r   )r   r   r   r	   r%     s    zDtest_download_sheet_fail_drive.<locals>.MockDriveRaiseClient.executeN)r   r   r   r%   r   r   r   r	   r     s   r   zsome idz	some nameN)r   rS   rT   rU   GoogleDownloadErrorr   r   )r   r   r   r	   test_download_sheet_fail_drive  s    r   c              C   sI   Gd d   d t   }  t j t j   t j |    d d  Wd QXd S)z5We get an exception when google oauth2 api raises onec               @   s   e  Z d  Z d d   Z d S)z=test_download_sheet_fail_oauth2.<locals>.MockDriveRaiseOauth2c             S   s   t  j j    d  S)N)r   r   r   )r   r   r   r	   r%   $  s    zEtest_download_sheet_fail_oauth2.<locals>.MockDriveRaiseOauth2.executeN)r   r   r   r%   r   r   r   r	   r   #  s   r   zsome idz	some nameN)r   rS   rT   rU   r   r   r   )r   r   r   r	   test_download_sheet_fail_oauth2!  s    r   c              C   sI   Gd d   d t   }  t j t j   t j |    d d  Wd QXd S)z6We get an exception when google returns no spreadsheetc               @   s   e  Z d  Z d d   Z d S)z7test_download_sheet_fail_content.<locals>.MockDriveNonec             S   s   d  S)Nr   )r   r   r   r	   r%   /  s    z?test_download_sheet_fail_content.<locals>.MockDriveNone.executeN)r   r   r   r%   r   r   r   r	   MockDriveNone.  s   r   zsome idz	some nameN)r   rS   rT   rU   NoSheetDownloadedErrorr   r   )r   r   r   r	    test_download_sheet_fail_content,  s    r   c                s-  Gd d   d t     d   f d 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)z5We get something back when the download is successfulc               @   s:   e  Z d  Z d d d d  Z d d   Z d d   Z d	 S)
z5test_rules_from_google_success.<locals>.MockDriveDatazutf-8r*   c             S   s   d S)NzMockDriveData()
r   )r   r+   r,   r   r   r	   r-   <  s    z<test_rules_from_google_success.<locals>.MockDriveData.decodec             S   s   i d d 6g S)Nzsome idr   r   )r   r   r   r   r   r	   r)   ?  s    z9test_rules_from_google_success.<locals>.MockDriveData.getc             S   s   |  S)Nr   )r   valuer   r   r	   splitB  s    z;test_rules_from_google_success.<locals>.MockDriveData.splitN)r   r   r   r-   r)   r   r   r   r   r	   MockDriveData;  s   r   Nc                s       S)Nr   )rw   rx   ry   )r   r   r	   rz   E  s    z2test_rules_from_google_success.<locals>.mock_buildrA   r{   z
creds.jsonz	some namezMockDriveData()
r5   %(py0)s == %(py3)srulesr7   r:   r<   assert %(py5)sr9   )r5   )r   r   )r   r?   r   r/   r   r   rules_from_googler3   rC   rD   rE   rF   rG   rH   rI   rJ   )rK   rz   metainfor   rp   rL   @py_format4r   r   )r   r	   test_rules_from_google_success9  s    
	   l   r   c                s   Gd d   d t     d   f d d  } |  j t d t  |  j t j d |  t j t j	   t j
 d t d	  Wd QXd S)
z?We get an exception when the spreadsheet is not found by googlec               @   s   e  Z d  Z d d   Z d S)z5test_rules_from_google_fail.<locals>.MockDriveNoSheetc             S   s   g  S)Nr   )r   r   r   r   r   r	   r)   T  s    z9test_rules_from_google_fail.<locals>.MockDriveNoSheet.getN)r   r   r   r)   r   r   r   r	   MockDriveNoSheetS  s   r   Nc                s       S)Nr   )rw   rx   ry   )r   r   r	   rz   W  s    z/test_rules_from_google_fail.<locals>.mock_buildrA   r{   z
creds.jsonz	some name)r   r?   r   r/   r   r   rS   rT   rU   NoSuchSpreadsheetErrorr   r3   )rK   rz   r   )r   r	   test_rules_from_google_failQ  s    r   c             C   sb   d d   } |  j  t d t  |  j  t d |  t j t j   t j d d d  Wd QXd S)z1We get an exception when httplib2 raises an errorc             S   s   t  j d   d  S)Nztest exception)r0   HttpLib2Error)r2   r   r   r   r	   mock_build_drivee  s    z:test_rules_from_google_httperror.<locals>.mock_build_driverA   r   z
creds.jsonNz	some name)r?   r   r/   rS   rT   rU   r   r   )rK   r   r   r   r	    test_rules_from_google_httperrorc  s    r   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)z,The first 2 lines of a rule file can be readzsample_rules.csvr      zline 1
zline 2
r5   %(py1)s == %(py4)sri   rj   r<   assert %(py6)srm   N)r5   )r   r   )r   rules_from_filerC   rD   rH   rI   rJ   )r   data@py_assert0r   rp   r   r   r   r   r	   test_rules_from_file_firstr  s        E   r   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)z(The last line of a rule file can be readzsample_rules.csv   z
last line
r5   %(py1)s == %(py4)sri   rj   r<   assert %(py6)srm   N)r5   )r   r   )r   r   rC   rD   rH   rI   rJ   )r   r   r   r   rp   r   r   r   r   r	   test_rules_from_file_lastx  s    
    E   r   c            	   C   s*   t  j t j   t j d  Wd QXd S)z,A non-existant rule file raises an exceptionzno_such.csvN)rS   rT   rU   NoRulesFileErrorr   r   r   r   r   r	   test_rule_file_existance~  s    r   c       	      C   se  d d   } |  j  t d |  d } t j } i t j d 6| d 6} | |  } | | k } | sO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 6d t j   k s t j |  r t j	 |  n d d 6t j	 |  d 6t j	 |  d 6} d i | d 6} t
 t j |    n  d } } } } d S)zReturn rules from a filec             S   s   |  S)Nr   )pathr   r   r	   mock_rules_from_file  s    z5test_get_rule_file_file.<locals>.mock_rules_from_filer   z	some/pathrules_source
rules_pathr5   S%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.get_rule_file
}(%(py4)s)
} == %(py8)sr   r7   r8   r   r;   rm   rj   r<   assert %(py10)sr>   N)r5   )r   r   )r?   r   get_rule_fileFILE_SOURCErC   rD   rE   rF   rG   rH   rI   rJ   )	rK   r   r   rL   r   rq   rN   rP   rQ   r   r   r	   test_get_rule_file_file  s    	        r   c             C   sa  d d   } |  j  t d |  d } d } t j } i t j d 6| d 6| d 6} | |  } | t j | f } | | k } | sG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)zReturn rules from googlec             S   s   |  | | f S)Nr   )r2   r   r   r   r   r	   mock_rules_from_google  s    z9test_get_rule_file_google.<locals>.mock_rules_from_googler   z	some.jsonz	some namer   rA   spreadsheet_namer5   S%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.get_rule_file
}(%(py4)s)
} == %(py9)sr   r7   r8   rl   rm   rj   r<   assert %(py11)srn   N)r5   )r   r   )r?   r   r   GOOGLE_SOURCEro   rC   rD   rE   rF   rG   rH   rI   rJ   )rK   r   r2   r   rL   r   rq   @py_assert8rN   @py_format10@py_format12r   r   r	   test_get_rule_file_google  s    	         r   )7builtinsrE   _pytest.assertion.rewrite	assertionrewriterC   rY   googleapiclient.discoveryr   googleapiclient.errorsr0   oauth2client.clientr   oauth2client.service_accountrS   enforcerr   r   rU   rb   rf   r\   r   r   r   r   r/   r3   rR   rW   r^   r`   rd   rg   rt   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   <module>   sZ     &
