a
    ù!fYq  ã                   @   sr   d dl Z G dd„ de jƒZG dd„ de jƒZG dd„ de jƒZG dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZdS )é    Nc                   @   sb  e Zd ZdZdd„ Zdd„ ZdWd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)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCdD„ Z$dEdF„ Z%dGdH„ Z&dIdJ„ Z'dKdL„ Z(dMdN„ Z)dOdP„ Z*dQdR„ Z+dSdT„ Z,dUdV„ Z-dS )XÚ	TestQueryÚPROJECTc                 C   s   ddl m} |S )Nr   )ÚQuery)Úgcloud.datastore.queryr   )Úselfr   © r   ú\/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/datastore/test_query.pyÚ_getTargetClass   s    zTestQuery._getTargetClassc                 O   s   |   ¡ |i |¤ŽS ©N©r	   ©r   ÚargsÚkwr   r   r   Ú_makeOne   s    zTestQuery._makeOneNc                 C   s   |d u rt ƒ }t| j|ƒS r
   ©Ú_ConnectionÚ_ClientÚ_PROJECT©r   Ú
connectionr   r   r   Ú_makeClient   s    zTestQuery._makeClientc                 C   sš   |   ¡ }|  |¡}|  |j|u ¡ |  |j|j¡ |  |jd ¡ |  |j|j¡ |  |jd ¡ |  |j	g ¡ |  |j
g ¡ |  |jg ¡ |  |jg ¡ d S r
   )r   r   Ú
assertTrueÚ_clientÚassertEqualÚprojectÚkindÚ	namespaceÚancestorÚfiltersÚ
projectionÚorderÚdistinct_on)r   ÚclientÚqueryr   r   r   Útest_ctor_defaults"   s    
zTestQuery.test_ctor_defaultsc                 C   sð   ddl m} d}d}d}|  ¡ }|dd|d}d	d
g}g d¢}ddg}	dg}
| j||||||||	|
d	}|  |j|u ¡ |  |j|¡ |  |j|¡ |  |j	|¡ |  |j
j|j¡ |  |j|¡ |  |j|¡ |  |j|	¡ |  |j|
¡ d S )Nr   ©ÚKeyZOTHER_PROJECTÚKINDÚOTHER_NAMESPACEZANCESTORé{   ©r   )Úfooú=ZQux)Úbarú<é   )r+   r-   Zbazr+   r-   )r   r   r   r   r   r   r    r!   )Úgcloud.datastore.keyr&   r   r   r   r   r   r   r   r   r   Úpathr   r   r    r!   )r   r&   r   Ú_KINDÚ
_NAMESPACEr"   r   ÚFILTERSZ
PROJECTIONZORDERZDISTINCT_ONr#   r   r   r   Útest_ctor_explicit/   s<    ÷zTestQuery.test_ctor_explicitc                 C   s"   t ƒ }| jt| j|  ¡ |d d S )N©r   ©ÚobjectÚassertRaisesÚ	TypeErrorr   r   )r   ZBAD_PROJECTIONr   r   r   Útest_ctor_bad_projectionO   s    ÿz"TestQuery.test_ctor_bad_projectionc                 C   s"   t ƒ }| jt| j|  ¡ |d d S )N©r    r7   )r   Z	BAD_ORDERr   r   r   Útest_ctor_bad_orderT   s    ÿzTestQuery.test_ctor_bad_orderc                 C   s"   t ƒ }| jt| j|  ¡ |d d S )N©r!   r7   )r   ZBAD_DISTINCT_ONr   r   r   Útest_ctor_bad_distinct_onY   s    ÿz#TestQuery.test_ctor_bad_distinct_onc                 C   s"   dg}| j t| j|  ¡ |d d S )N)ÚoneÚtwo©r   )r9   Ú
ValueErrorr   r   )r   ZFILTERS_CANT_UNPACKr   r   r   Útest_ctor_bad_filters^   s    ÿzTestQuery.test_ctor_bad_filtersc                    s.   |   |  ¡ ¡‰ ‡ fdd„}|  t|tƒ ¡ d S )Nc                    s
   | ˆ _ d S r
   )r   ©Úval©r#   r   r   Ú_assignf   s    z=TestQuery.test_namespace_setter_w_non_string.<locals>._assign)r   r   r9   rC   r8   ©r   rH   r   rG   r   Ú"test_namespace_setter_w_non_stringc   s    z,TestQuery.test_namespace_setter_w_non_stringc                 C   s*   d}|   |  ¡ ¡}||_|  |j|¡ d S )Nr(   )r   r   r   r   )r   r3   r#   r   r   r   Útest_namespace_setterk   s    zTestQuery.test_namespace_setterc                    s.   |   |  ¡ ¡‰ ‡ fdd„}|  t|tƒ ¡ d S )Nc                    s
   | ˆ _ d S r
   ©r   rE   rG   r   r   rH   t   s    z8TestQuery.test_kind_setter_w_non_string.<locals>._assign©r   r   r9   r:   r8   rI   r   rG   r   Útest_kind_setter_w_non_stringq   s    z'TestQuery.test_kind_setter_w_non_stringc                 C   s*   d}|   |  ¡ ¡}||_|  |j|¡ d S )Nr'   )r   r   r   r   )r   r2   r#   r   r   r   Útest_kind_setter_wo_existingy   s    z&TestQuery.test_kind_setter_wo_existingc                 C   sP   d}d}| j |  ¡ |d}|  |j|¡ ||_|  |j| j¡ |  |j|¡ d S )NZKIND_BEFOREZ
KIND_AFTERrL   )r   r   r   r   r   r   )r   Z_KIND_BEFOREZ_KIND_AFTERr#   r   r   r   Útest_kind_setter_w_existing   s    z%TestQuery.test_kind_setter_w_existingc                    s@   |   |  ¡ ¡‰ ‡ fdd„}|  t|tƒ ¡ |  t|ddg¡ d S )Nc                    s
   | ˆ _ d S r
   ©r   rE   rG   r   r   rH   ‹   s    z9TestQuery.test_ancestor_setter_w_non_key.<locals>._assignr'   ÚNAMErM   rI   r   rG   r   Útest_ancestor_setter_w_non_keyˆ   s    z(TestQuery.test_ancestor_setter_w_non_keyc                 C   sX   ddl m} d}|dd| jd}|  |  ¡ ¡}| dd|¡ ||_|  |jj|j¡ d S )	Nr   r%   rR   r'   r)   r*   Únamer,   )	r0   r&   r   r   r   Ú
add_filterr   r   r1   )r   r&   Z_NAMEÚkeyr#   r   r   r   Útest_ancestor_setter_w_key‘   s    z$TestQuery.test_ancestor_setter_w_keyc                 C   sF   ddl m} |dd| jd}| j|  ¡ |d}|`|  |jd u ¡ d S )Nr   r%   r'   r)   r*   )r"   r   )r0   r&   r   r   r   r   r   ©r   r&   rV   r#   r   r   r   Útest_ancestor_deleter_w_keyš   s
    z%TestQuery.test_ancestor_deleter_w_keyc                 C   s&   |   |  ¡ ¡}|  t|jddd¡ d S )NÚ	firstnamez~~ÚJohn©r   r   r9   rC   rU   ©r   r#   r   r   r   Ú)test_add_filter_setter_w_unknown_operator¡   s    
ÿz3TestQuery.test_add_filter_setter_w_unknown_operatorc                 C   s0   |   |  ¡ ¡}| ddd¡ |  |jdg¡ d S )NrZ   r,   r[   )rZ   r,   r[   ©r   r   rU   r   r   r]   r   r   r   Ú test_add_filter_w_known_operator¦   s    z*TestQuery.test_add_filter_w_known_operatorc                 C   sÄ   |   |  ¡ ¡}| ddd¡ | ddd¡ | ddd	¡ | d
dd¡ | ddd¡ |  t|jƒd¡ |  |jd d¡ |  |jd d¡ |  |jd d¡ |  |jd d¡ |  |jd d¡ d S )NÚleq_propú<=Úval1Úgeq_propú>=Úval2Últ_propr.   Úval3Úgt_propú>Úval4Úeq_propr,   Úval5é   r   )ra   rb   rc   é   )rd   re   rf   é   )rg   r.   rh   é   )ri   rj   rk   é   )rl   r,   rm   )r   r   rU   r   Úlenr   r]   r   r   r   Útest_add_filter_w_all_operators«   s    z)TestQuery.test_add_filter_w_all_operatorsc                 C   sX   ddl m} |  |  ¡ ¡}|ƒ }d|d< d|d< | dd|¡ |  |jdd|fg¡ d S )	Nr   )ÚEntityr[   rZ   ZSmithÚlastnameÚotherr,   )Zgcloud.datastore.entityru   r   r   rU   r   r   )r   ru   r#   rw   r   r   r   Ú+test_add_filter_w_known_operator_and_entity¹   s    z5TestQuery.test_add_filter_w_known_operator_and_entityc                 C   s:   |   |  ¡ ¡}d}| |dd¡ |  |j|ddfg¡ d S )Nz  property with lots of space r,   r[   r_   )r   r#   ZPROPERTY_NAMEr   r   r   Ú*test_add_filter_w_whitespace_property_nameÂ   s    z4TestQuery.test_add_filter_w_whitespace_property_namec                 C   sP   ddl m} |  |  ¡ ¡}|d| jd}| dd|¡ |  |jdd|fg¡ d S )Nr   r%   ÚFoor*   Ú__key__r,   )r0   r&   r   r   r   rU   r   r   )r   r&   r#   rV   r   r   r   Ú test_add_filter___key__valid_keyÈ   s
    z*TestQuery.test_add_filter___key__valid_keyc                 C   sP   ddl m} |d| jd}|  |  ¡ ¡}| dd|¡ |  |jdd|fg¡ d S )Nr   r%   rz   r*   r{   r.   )r0   r&   r   r   r   rU   r   r   rX   r   r   r   Ú%test_filter___key__not_equal_operatorÏ   s
    z/TestQuery.test_filter___key__not_equal_operatorc                 C   s&   |   |  ¡ ¡}|  t|jddd ¡ d S )Nr{   r,   r\   r]   r   r   r   Ú test_filter___key__invalid_valueÖ   s    z*TestQuery.test_filter___key__invalid_valuec                 C   s&   |   |  ¡ ¡}g |_|  |jg ¡ d S r
   ©r   r   r   r   r]   r   r   r   Útest_projection_setter_emptyÚ   s    z&TestQuery.test_projection_setter_emptyc                 C   s(   |   |  ¡ ¡}d|_|  |jdg¡ d S ©NÚfield1r   r]   r   r   r   Útest_projection_setter_stringß   s    z'TestQuery.test_projection_setter_stringc                 C   s.   |   |  ¡ ¡}ddg|_|  |jddg¡ d S ©Nr‚   Úfield2r   r]   r   r   r   Ú test_projection_setter_non_emptyä   s    
z*TestQuery.test_projection_setter_non_emptyc                 C   sH   ddg}dg}|   |  ¡ ¡}||_|  |j|¡ ||_|  |j|¡ d S ©Nr‚   r…   Zfield3r   )r   Z_PROJECTION1Z_PROJECTION2r#   r   r   r   Ú%test_projection_setter_multiple_callsé   s    z/TestQuery.test_projection_setter_multiple_callsc                 C   s*   |   |  ¡ ¡}| ¡  |  |jdg¡ d S )Nr{   )r   r   Z	keys_onlyr   r   r]   r   r   r   Útest_keys_onlyò   s    zTestQuery.test_keys_onlyc                 C   s^   ddl m} |  ¡ }|  |¡}|  |jg ¡ |dddd}| |¡ |  |jdd|fg¡ d S )	Nr   r%   ÚKindéÒ  r   r*   r{   r,   ©r0   r&   r   r   r   r   Z
key_filter©r   r&   r"   r#   rV   r   r   r   Útest_key_filter_defaults÷   s    

z"TestQuery.test_key_filter_defaultsc                 C   sb   ddl m} |  ¡ }|  |¡}|  |jg ¡ |dddd}|j|dd |  |jd	d|fg¡ d S )
Nr   r%   rŠ   r‹   r   r*   rj   )Úoperatorr{   rŒ   r   r   r   r   Útest_key_filter_explicit  s    
z"TestQuery.test_key_filter_explicitc                 C   s.   | j |  ¡ ddgd}g |_|  |jg ¡ d S )Nr+   ú-barr<   ©r   r   r    r   r]   r   r   r   Útest_order_setter_empty  s    z!TestQuery.test_order_setter_emptyc                 C   s(   |   |  ¡ ¡}d|_|  |jdg¡ d S )NÚfieldr’   r]   r   r   r   Útest_order_setter_string  s    z"TestQuery.test_order_setter_stringc                 C   s*   |   |  ¡ ¡}dg|_|  |jdg¡ d S )Nz-fieldr’   r]   r   r   r   Ú'test_order_setter_single_item_list_desc  s    z1TestQuery.test_order_setter_single_item_list_descc                 C   s.   |   |  ¡ ¡}ddg|_|  |jddg¡ d S )Nr+   r‘   r’   r]   r   r   r   Útest_order_setter_multiple  s    
z$TestQuery.test_order_setter_multiplec                 C   s.   | j |  ¡ ddgd}g |_|  |jg ¡ d S )Nr+   r-   r>   ©r   r   r!   r   r]   r   r   r   Útest_distinct_on_setter_empty  s    z'TestQuery.test_distinct_on_setter_emptyc                 C   s(   |   |  ¡ ¡}d|_|  |jdg¡ d S r   r˜   r]   r   r   r   Útest_distinct_on_setter_string$  s    z(TestQuery.test_distinct_on_setter_stringc                 C   s.   |   |  ¡ ¡}ddg|_|  |jddg¡ d S r„   r˜   r]   r   r   r   Ú!test_distinct_on_setter_non_empty)  s    
z+TestQuery.test_distinct_on_setter_non_emptyc                 C   sH   ddg}dg}|   |  ¡ ¡}||_|  |j|¡ ||_|  |j|¡ d S r‡   r˜   )r   Z_DISTINCT_ON1Z_DISTINCT_ON2r#   r   r   r   Útest_distinct_on_multiple_calls.  s    z)TestQuery.test_distinct_on_multiple_callsc                 C   sb   t ƒ }|  |¡}|  |¡}| ¡ }|  |j|u ¡ |  |j|u ¡ |  |jd ¡ |  |j	d¡ d S )Nr   ©
r   r   r   Úfetchr   Ú_queryr   r   Ú_limitÚ_offset)r   r   r"   r#   Úiteratorr   r   r   Ú!test_fetch_defaults_w_client_attr7  s    

z+TestQuery.test_fetch_defaults_w_client_attrc                 C   st   t ƒ }|  |¡}|  |¡}|  |¡}|jdd|d}|  |j|u ¡ |  |j|u ¡ |  |jd¡ |  |j	d¡ d S )Né   é   )ÚlimitÚoffsetr"   r   )r   r   r"   Zother_clientr#   r¢   r   r   r   Útest_fetch_w_explicit_clientA  s    


z&TestQuery.test_fetch_w_explicit_client)N).Ú__name__Ú
__module__Ú__qualname__r   r	   r   r   r$   r5   r;   r=   r?   rD   rJ   rK   rN   rO   rP   rS   rW   rY   r^   r`   rt   rx   ry   r|   r}   r~   r€   rƒ   r†   rˆ   r‰   rŽ   r   r“   r•   r–   r—   r™   rš   r›   rœ   r£   r¨   r   r   r   r   r      sV   
 					

	
r   c                   @   s˜   e Zd ZdZdZdZdZdZdZdd„ Z	d	d
„ Z
edddfdd„Zd#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S )$ÚTestIteratorr   Z	NAMESPACEr'   r)   ó    ó   ÿc                 C   s   ddl m} |S )Nr   )ÚIterator)r   r¯   )r   r¯   r   r   r   r	   U  s    zTestIterator._getTargetClassc                 O   s   |   ¡ |i |¤ŽS r
   r   r   r   r   r   r   Y  s    zTestIterator._makeOneFNc                 C   s¤   ddl m} ddl m} ddlm} |r2|jj}	n|jj}	d}
|rHg }nD| ¡ }| j	|j
j_|j
j ¡ }| j|_|
|_||dƒ}d|_|g}|j |||	|f¡ d S )Nr   )Ú
entity_pb2©Ú	query_pb2)Ú_new_value_pbr)   r+   rz   )Úgcloud.datastore._generatedr°   r²   Zgcloud.datastore.helpersr³   ZQueryResultBatchZNOT_FINISHEDZMORE_RESULTS_AFTER_LIMITru   r   rV   Zpartition_idZ
project_idr1   Úaddr2   r   ÚidÚstring_valueÚ_resultsÚappend)r   r   ÚcursorÚmoreÚskipped_resultsÚ	no_entityr°   r²   r³   Z	more_enumÚ_IDÚentitiesZ	entity_pbZpath_elementZvalue_pbr   r   r   Ú_addQueryResults\  s(    


ÿzTestIterator._addQueryResultsc                 C   s   |d u rt ƒ }t| j|ƒS r
   r   r   r   r   r   r   v  s    zTestIterator._makeClientc                 C   sV   t ƒ }tƒ }|  ||¡}|  |j|u ¡ |  |jd ¡ |  |jd ¡ |  |jd ¡ d S r
   )	r   r8   r   r   rŸ   r   r    r¡   Ú_skipped_results)r   r   r#   r¢   r   r   r   r$   {  s    zTestIterator.test_ctor_defaultsc                 C   sP   |   ¡ }t|ƒ}|  ||dd¡}|  |j|u ¡ |  |jd¡ |  |jd¡ d S )Né   é   )r   Ú_Queryr   r   rŸ   r   r    r¡   )r   r"   r#   r¢   r   r   r   r5   „  s    zTestIterator.test_ctor_explicitc                 C   s   ddl m} tƒ }|  |¡}t|| j| j| jƒ}| j|dd |  	||¡}| 
¡ \}}}|  |jd ¡ |  |d ¡ |  |¡ |  |j¡ |  t|ƒd¡ |  |d jj| j| jdœg¡ |  |d d d¡ ||ƒ}	d|	_| j|	| jd d	œ}
|  |j|
g¡ d S )
Nr   ©Ú_pb_from_queryó    )rº   ro   ©r   r¶   r+   rz   ©r   Zquery_pbr   Ztransaction_id)r   rÆ   r   r   rÄ   r2   r   r3   rÀ   r   Ú	next_pager   rÁ   ÚassertFalseÚ_more_resultsrs   rV   r1   r¾   r§   Ú_called_with)r   rÆ   r   r"   r#   r¢   r¿   Úmore_resultsrº   ÚqpbÚEXPECTEDr   r   r   Ú!test_next_page_no_cursors_no_moreŒ  s0    

ÿüz.TestIterator.test_next_page_no_cursors_no_morec                 C   s  ddl m} tƒ }|  |¡}t|| j| j| jƒ}tƒ }| j	|d|d |  
||dd¡}| ¡ \}}}	|  |	d ¡ |  |¡ |  |j¡ |  |j|¡ |  t|ƒd¡ |  |d jj| j| jdœg¡ |  |d d	 d
¡ ||ƒ}
d|
j_d|
_| j|
| jd dœ}|  |j|g¡ d S )Nr   rÅ   rÇ   )rº   r¼   rÂ   rÃ   ro   rÈ   r+   rz   rÉ   )r   rÆ   r   r   rÄ   r2   r   r3   r8   rÀ   r   rÊ   r   rË   rÌ   rÁ   rs   rV   r1   r¾   r¦   Úvaluer§   rÍ   )r   rÆ   r   r"   r#   r¼   r¢   r¿   rÎ   rº   rÏ   rÐ   r   r   r   Ú4test_next_page_no_cursors_no_more_w_offset_and_limit§  s8    
ÿ
ÿüzATestIterator.test_next_page_no_cursors_no_more_w_offset_and_limitc                 C   sl  ddl m} ddl m} ddlm} tƒ }|  |¡}t|| j| j	| j
ƒ}| j|| jdd |  ||¡}| j|_| j|_| ¡ \}}	}
|  |
|| jƒ¡ |  |	¡ |  |j¡ |  |jd ¡ |  |jd ¡ |  ||jƒ| j¡ |  t|ƒd¡ |  |d jj| j| jdœg¡ |  |d d	 d
¡ ||ƒ}d|_|| jƒ|_|| jƒ|_| j	|| j
d dœ}|  |j|g¡ d S )Nr   )Úurlsafe_b64decode)Úurlsafe_b64encoderÅ   T©rº   r»   ro   rÈ   r+   rz   rÉ   )Úbase64rÔ   rÕ   r   rÆ   r   r   rÄ   r2   r   r3   rÀ   Ú_ENDr   Ú_STARTZ_start_cursorZ_end_cursorrÊ   r   r   rÌ   rÁ   rs   rV   r1   r¾   r§   Ústart_cursorÚ
end_cursorrÍ   )r   rÔ   rÕ   rÆ   r   r"   r#   r¢   r¿   rÎ   rº   rÏ   rÐ   r   r   r   Útest_next_page_w_cursors_w_moreÅ  s@    

ÿüz,TestIterator.test_next_page_w_cursors_w_morec                 C   sz   t ƒ }|  |¡}t|| j| j| jƒ}| j|| jdd |j 	¡ \}}}}|j 
||dd f¡ |  ||¡}|  t|j¡ d S )NTrÖ   rn   )r   r   rÄ   r2   r   r3   rÀ   rØ   r¸   Úpopr¹   r   r9   rC   rÊ   )r   r   r"   r#   Zepbrº   Ú_r¢   r   r   r   Ú%test_next_page_w_cursors_w_bogus_moreè  s    
z2TestIterator.test_next_page_w_cursors_w_bogus_morec           	      C   sÒ   ddl m} tƒ }|  |¡}t|| j| j| jƒ}|  |¡ |  	||¡}t
|ƒ}|  |j¡ |  t|ƒd¡ |  |d jj| j| jdœg¡ |  |d d d¡ ||ƒ}d|_| j|| jd dœ}|  |j|g¡ d S )Nr   rÅ   ro   rÈ   r+   rz   rÉ   )r   rÆ   r   r   rÄ   r2   r   r3   rÀ   r   ÚlistrË   rÌ   r   rs   rV   r1   r¾   r§   rÍ   )	r   rÆ   r   r"   r#   r¢   r¿   rÏ   rÐ   r   r   r   Útest___iter___no_moreò  s*    

ÿüz"TestIterator.test___iter___no_morec                 C   s,  ddl m} tƒ }|  |¡}t|| j| j| jƒ}| j|| j	dd |  |¡ |  
||¡}t|ƒ}|  |j¡ |  t|ƒd¡ |D ]4}|  |jj| j| jdœg¡ |  |d d d	¡ q€||ƒ}||ƒ}	| j	|	_| j|| jd d
œ}
| j|	| jd d
œ}|  t|jƒd¡ |  |jd |
¡ |  |jd |¡ d S )Nr   rÅ   TrÖ   rp   rÈ   ro   r+   rz   rÉ   )r   rÆ   r   r   rÄ   r2   r   r3   rÀ   rØ   r   rà   rË   rÌ   r   rs   rV   r1   r¾   rÚ   rÍ   )r   rÆ   r   r"   r#   r¢   r¿   ÚentityÚqpb1Úqpb2Ú	EXPECTED1Ú	EXPECTED2r   r   r   Útest___iter___w_more
  s@    

þüüz!TestIterator.test___iter___w_morec                 C   sš  ddl m} tƒ }|  |¡}t|| j| j| jƒ}d}d}| j|d|dd | j|d|d |  |¡ || }| j	||d|d	}t
|ƒ}	|  |j¡ |  t|	ƒd¡ |	D ] }
|  |
jj| j| jd
œg¡ q¦||ƒ}d|j_||_||ƒ}| j|_d|j_|| |_||ƒ}| j|_d|j_| j|| jd dœ}| j|| jd dœ}| j|| jd dœ}|  t|jƒd¡ |  |jd |¡ |  |jd |¡ |  |jd |¡ d S )Nr   rÅ   rr   é	   T)r»   r¼   r½   )r»   r¼   rp   )r¦   r§   rÈ   ro   rÉ   rq   )r   rÆ   r   r   rÄ   r2   r   r3   rÀ   r   rà   rË   rÌ   r   rs   rV   r1   r¾   r¦   rÒ   r§   rØ   rÚ   rÍ   )r   rÆ   r   r"   r#   Zskip1Zskip2r§   r¢   r¿   râ   rã   rä   Zqpb3rå   ræ   Z	EXPECTED3r   r   r   Útest___iter___w_limit.  sd    

ÿ
þ
üüüz"TestIterator.test___iter___w_limit)N)r©   rª   r«   r   r3   r2   r¾   rÙ   rØ   r	   r   rÀ   r   r$   r5   rÑ   rÓ   rÜ   rß   rá   rç   ré   r   r   r   r   r¬   M  s*   ÿ

	#
$r¬   c                   @   sT   e Z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S )ÚTest__pb_from_queryc                 C   s   ddl m} ||ƒS )Nr   rÅ   )r   rÆ   )r   r#   rÆ   r   r   r   Ú_callFUTh  s    zTest__pb_from_query._callFUTc                 C   sÞ   ddl m} |  tƒ ¡}|  t|jƒg ¡ |  t|jƒg ¡ |  t|jƒg ¡ |  t|j	ƒg ¡ |  |j
jjjd¡ |j
j}|  |j|jj¡ |  t|jƒg ¡ |  |jd¡ |  |jd¡ |  |jjd¡ |  |jd¡ d S )Nr   r±   Ú rÇ   )r´   r²   rë   rÄ   r   rà   r   r   r    r!   ÚfilterÚproperty_filterÚpropertyrT   Úcomposite_filterÚopÚCompositeFilterZOPERATOR_UNSPECIFIEDr   rÚ   rÛ   r¦   rÒ   r§   )r   r²   ÚpbÚcfilterr   r   r   Ú
test_emptyl  s     ÿzTest__pb_from_query.test_emptyc                 C   s4   |   tg d¢d¡}|  dd„ |jD ƒg d¢¡ d S )N©ÚaÚbÚcr6   c                 S   s   g | ]}|j j‘qS r   ©rï   rT   ©Ú.0Úitemr   r   r   Ú
<listcomp>€  rÇ   z7Test__pb_from_query.test_projection.<locals>.<listcomp>)rë   rÄ   r   r   ©r   ró   r   r   r   Útest_projection~  s    ÿz#Test__pb_from_query.test_projectionc                 C   s.   |   tdd¡}|  dd„ |jD ƒdg¡ d S )Nr'   rL   c                 S   s   g | ]
}|j ‘qS r   ©rT   rû   r   r   r   rþ   …  rÇ   z1Test__pb_from_query.test_kind.<locals>.<listcomp>)rë   rÄ   r   r   rÿ   r   r   r   Ú	test_kindƒ  s    zTest__pb_from_query.test_kindc                 C   sš   ddl m} ddlm} |dddd}|  t|d¡}|jj}|  |j	|j
j¡ |  t|jƒd	¡ |jd j}|  |jjd
¡ | ¡ }|  |jj|¡ d S )Nr   r%   r±   ZAncestorr)   r   r*   rQ   ro   r{   )r0   r&   r´   r²   rë   rÄ   rí   rð   r   rñ   rò   ÚANDrs   r   rî   rï   rT   Úto_protobufrÒ   Ú	key_value)r   r&   r²   r   ró   rô   ÚpfilterZancestor_pbr   r   r   Útest_ancestor‡  s    z!Test__pb_from_query.test_ancestorc                 C   sŒ   ddl m} tdgd}d|jji|_|  |¡}|jj}|  	|j
|jj¡ |  	t|jƒd¡ |jd j}|  	|jjd¡ |  	|jjd¡ d S )	Nr   r±   )rT   r,   r[   rB   r,   ro   rT   r[   )r´   r²   rÄ   ÚPropertyFilterÚEQUALÚ	OPERATORSrë   rí   rð   r   rñ   rò   r  rs   r   rî   rï   rT   rÒ   r·   )r   r²   r#   ró   rô   r  r   r   r   Útest_filter•  s    ÿ
zTest__pb_from_query.test_filterc           	      C   s´   ddl m} ddlm} |dddd}tdd	|fgd
}d	|jji|_|  |¡}|j	j
}|  |j|jj¡ |  t|jƒd¡ |jd j}|  |jjd¡ | ¡ }|  |jj|¡ d S )Nr   r%   r±   rŠ   r)   r   r*   r{   r,   rB   ro   )r0   r&   r´   r²   rÄ   r  r	  r
  rë   rí   rð   r   rñ   rò   r  rs   r   rî   rï   rT   r  rÒ   r  )	r   r&   r²   rV   r#   ró   rô   r  Zkey_pbr   r   r   Útest_filter_key¤  s    ÿ
z#Test__pb_from_query.test_filter_keyc                 C   sj   ddl m} |  tg d¢d¡}|  dd„ |jD ƒg d¢¡ |  dd„ |jD ƒ|jj|jj|jjg¡ d S )	Nr   r±   )r÷   z-brù   r<   c                 S   s   g | ]}|j j‘qS r   rú   rû   r   r   r   rþ   º  rÇ   z2Test__pb_from_query.test_order.<locals>.<listcomp>rö   c                 S   s   g | ]
}|j ‘qS r   )Ú	directionrû   r   r   r   rþ   ¼  rÇ   )	r´   r²   rë   rÄ   r   r    ZPropertyOrderZ	ASCENDINGZ
DESCENDING)r   r²   ró   r   r   r   Ú
test_order¶  s    ÿþÿzTest__pb_from_query.test_orderc                 C   s4   |   tg d¢d¡}|  dd„ |jD ƒg d¢¡ d S )Nrö   r>   c                 S   s   g | ]
}|j ‘qS r   r  rû   r   r   r   rþ   Ã  rÇ   z8Test__pb_from_query.test_distinct_on.<locals>.<listcomp>)rë   rÄ   r   r!   rÿ   r   r   r   Útest_distinct_onÁ  s    ÿz$Test__pb_from_query.test_distinct_onN)r©   rª   r«   rë   rõ   r   r  r  r  r  r  r  r   r   r   r   rê   f  s   rê   c                	   @   s*   e Zd Zeƒ ddddddddf	dd„ZdS )rÄ   Nr   c
           
      C   s:   || _ || _|| _|| _|| _|| _|| _|| _|	| _d S r
   )	r   r   r   r   r   r   r   r    r!   )
r   r"   r   r   r   r   r   r   r    r!   r   r   r   Ú__init__É  s    
z_Query.__init__)r©   rª   r«   r8   r  r   r   r   r   rÄ   Ç  s   ÷rÄ   c                   @   s(   e Zd ZdZdZdZdd„ Zdd„ ZdS )r   Nr­   r   c                 C   s   g | _ g | _d S r
   )r¸   rÍ   ©r   r   r   r   r  ä  s    z_Connection.__init__c                 K   s,   | j  |¡ | jd | jdd …  }| _|S )Nr   ro   )rÍ   r¹   r¸   )r   r   Úresultr   r   r   Ú	run_queryè  s    z_Connection.run_query)r©   rª   r«   rÍ   Z_cursorÚ_skippedr  r  r   r   r   r   r   Þ  s
   r   c                   @   s"   e Zd Zddd„Zedd„ ƒZdS )r   Nc                 C   s   || _ || _|| _d S r
   )r   r   r   )r   r   r   r   r   r   r   r  ð  s    z_Client.__init__c                 C   s   d S r
   r   r  r   r   r   Úcurrent_transactionõ  s    z_Client.current_transaction)N)r©   rª   r«   r  rï   r  r   r   r   r   r   î  s   
r   )	Z	unittest2ZTestCaser   r¬   rê   r8   rÄ   r   r   r   r   r   r   Ú<module>   s     =  a