a
    !f@                     @   s   d dl Z G dd de jZdS )    Nc                   @   s  e Zd 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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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDdE Z%dFdG Z&dHdI Z'dJdK Z(dLdM Z)dNdO Z*dPdQ Z+dRdS Z,dTdU Z-dVdW Z.dXdY Z/dZd[ Z0d\d] Z1d^d_ Z2d`da Z3dbdc Z4ddde Z5dfdg Z6dhS )iTestKeyPROJECTc                 C   s   ddl m} |S )Nr   )Key)Zgcloud.datastore.keyr   )selfr    r   Z/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/datastore/test_key.py_getTargetClass   s    zTestKey._getTargetClassc                 O   s   |   |i |S N)r   )r   argskwargsr   r   r   _makeOne   s    zTestKey._makeOnec                 C   s   |  t| j d S r	   assertRaises
ValueErrorr   r   r   r   r   test_ctor_empty   s    zTestKey.test_ctor_emptyc                 C   s   |   }| t|d d S )NKIND)r   r   r   )r   klassr   r   r   test_ctor_no_project    s    zTestKey.test_ctor_no_projectc                 C   s   d}| j t| j|d d S )Nr   projectr   )r   _PROJECTr   r   r   'test_ctor_w_explicit_project_empty_path$   s    z/TestKey.test_ctor_w_explicit_project_empty_pathc           
      C   s   d}d}d}d}d}d}||d||dg}| j ||||d}| j |||d	}	| |	j|j | |	j|j | |	j| | |	j| | |	j|u  d S )
NKIND1  PROJECT-ALT	NAMESPACEKIND2)	  kindidr   	namespaceparent)r   assertEqualr   r#   r    path
assertTruer%   )
r   _PARENT_KIND
_PARENT_IDZ_PARENT_PROJECTZ_PARENT_NAMESPACEZ_CHILD_KINDZ	_CHILD_ID_PATH
parent_keykeyr   r   r   test_ctor_parent(   s&    zTestKey.test_ctor_parentc                 C   sN   | j d| jd}| t  | j dd|d W d    n1 s@0    Y  d S )Nr   r   r   r   r$   r   _DEFAULT_PROJECTr   r   r   r,   r   r   r   test_ctor_partial_parent=   s    z TestKey.test_ctor_partial_parentc                 C   sB   |  t$ | jddd| jd W d    n1 s40    Y  d S )Nr   r   )r   r   r%   r   )r   AttributeErrorr   r0   r   r   r   r   test_ctor_parent_bad_typeB   s    
z!TestKey.test_ctor_parent_bad_typec                 C   sX   | j ddd| jd}| t& | j ddd|| jd W d    n1 sJ0    Y  d S )Nr   r   FOOr#   r   r   BAR)r#   r%   r   r/   r1   r   r   r   test_ctor_parent_bad_namespaceG   s    
z&TestKey.test_ctor_parent_bad_namespacec                 C   sP   | j dddd}| t" | j dd|dd W d    n1 sB0    Y  d S )Nr   r   r6   r   r   r8   r3   )r   r   r   r1   r   r   r   test_ctor_parent_bad_projectN   s
    
z$TestKey.test_ctor_parent_bad_projectc                 C   sL   | j dd| jd}| t | j |d W d    n1 s>0    Y  d S )Nr   r   r   r$   r/   r1   r   r   r   test_ctor_parent_empty_pathT   s
    z#TestKey.test_ctor_parent_empty_pathc                 C   sj   d}d}d}d}||dg}| j ||||d}| |j| | |j| | |j| | |j| d S Nr   r   r   r   r   r7   )r   r&   r   r#   r    r'   )r   r   
_NAMESPACE_KIND_IDr+   r-   r   r   r   test_ctor_explicitZ   s    
zTestKey.test_ctor_explicitc                 C   s   | j t| jt | jd d S )Nr   r   r   r   objectr0   r   r   r   r   test_ctor_bad_kindg   s    zTestKey.test_ctor_bad_kindc              	   C   sR   | j t| jdt | jd | j t| jdd | jd | j t| jdddd | jd d S )Nr   r   
   r   rA   r   r   r   r   test_ctor_bad_id_or_namek   s    z TestKey.test_ctor_bad_id_or_namec                 C   sr   d}d}d}d}||dg}| j ||||d}| }| |j| | |j| | |j| | |j| d S r<   )r   _cloner&   r   r#   r    r'   )r   r   r=   r>   r?   r+   r-   cloner   r   r   test__clones   s    
zTestKey.test__clonec                 C   s   d}d}d}d}d}d}||d||dg}| j ||||d}| j |||d	}	| |	j|u  |	 }
| |
j|	ju  | |
j| | |
j| | |
j| d S )
Nr   r   PARENTr   r   r   r   r7   r$   )r   r(   r%   rF   r&   r   r#   r'   )r   r   r=   Z_KIND1Z_KIND2_ID1_ID2r+   r%   r-   rG   r   r   r   test__clone_with_parent   s"    
zTestKey.test__clone_with_parentc                 C   s@   d}d}d}| j |||d}| |t k | |t k d S Nr   r   oner   )r   assertFalserB   r(   r   r   r>   _NAMEr-   r   r   r   test___eq_____ne___w_non_key   s    z$TestKey.test___eq_____ne___w_non_keyc                 C   sD   d}d}| j ||d}| j ||d}| ||k | ||k d S Nr   r   r   r   rO   r(   )r   r   r>   key1key2r   r   r   0test___eq_____ne___two_incomplete_keys_same_kind   s    z8TestKey.test___eq_____ne___two_incomplete_keys_same_kindc                 C   sJ   d}d}d}| j ||d}| j |||d}| ||k | ||k d S Nr   r   r   r   rT   r   r   r>   r?   rU   rV   r   r   r   :test___eq_____ne___incomplete_key_w_complete_key_same_kind   s    zBTestKey.test___eq_____ne___incomplete_key_w_complete_key_same_kindc                 C   sJ   d}d}d}| j |||d}| j ||d}| ||k | ||k d S rX   rT   rY   r   r   r   :test___eq_____ne___complete_key_w_incomplete_key_same_kind   s    zBTestKey.test___eq_____ne___complete_key_w_incomplete_key_same_kindc                 C   sP   d}d}d}d}| j |||d}| j |||d}| ||k | ||k d S )Nr   r   r   r   r   rT   )r   r   r>   rJ   rK   rU   rV   r   r   r   *test___eq_____ne___same_kind_different_ids   s    z2TestKey.test___eq_____ne___same_kind_different_idsc                 C   sL   d}d}d}| j |||d}| j |||d}| ||k | ||k d S rX   r   r(   rO   rY   r   r   r   #test___eq_____ne___same_kind_and_id   s    z+TestKey.test___eq_____ne___same_kind_and_idc                 C   sP   d}d}d}d}| j |||d}| j |||d}| ||k | ||k d S )NPROJECT1PROJECT2r   r   r   rT   )r   	_PROJECT1	_PROJECT2r>   r?   rU   rV   r   r   r   5test___eq_____ne___same_kind_and_id_different_project   s    z=TestKey.test___eq_____ne___same_kind_and_id_different_projectc                 C   sX   d}d}d}d}d}| j ||||d}| j ||||d}| ||k | ||k d S )Nr   
NAMESPACE1
NAMESPACE2r   r   r"   rT   )r   r   _NAMESPACE1_NAMESPACE2r>   r?   rU   rV   r   r   r   7test___eq_____ne___same_kind_and_id_different_namespace   s    

z?TestKey.test___eq_____ne___same_kind_and_id_different_namespacec                 C   sP   d}d}d}d}| j |||d}| j |||d}| ||k | ||k d S )Nr   r   rN   twor   rT   )r   r   r>   Z_NAME1Z_NAME2rU   rV   r   r   r   ,test___eq_____ne___same_kind_different_names   s    z4TestKey.test___eq_____ne___same_kind_different_namesc                 C   sL   d}d}d}| j |||d}| j |||d}| ||k | ||k d S rM   r]   )r   r   r>   rQ   rU   rV   r   r   r   %test___eq_____ne___same_kind_and_name   s    z-TestKey.test___eq_____ne___same_kind_and_namec                 C   sP   d}d}d}d}| j |||d}| j |||d}| ||k | ||k d S )Nr_   r`   r   rN   r   rT   )r   ra   rb   r>   rQ   rU   rV   r   r   r   7test___eq_____ne___same_kind_and_name_different_project   s    z?TestKey.test___eq_____ne___same_kind_and_name_different_projectc                 C   sX   d}d}d}d}d}| j ||||d}| j ||||d}| ||k | ||k d S )Nr   rd   re   r   rN   r"   rT   )r   r   rf   rg   r>   rQ   rU   rV   r   r   r   9test___eq_____ne___same_kind_and_name_different_namespace   s    

zATestKey.test___eq_____ne___same_kind_and_name_different_namespacec                 C   s>   d}d}| j ||d}| t|t|t| td   d S rS   r   ZassertNotEqualhash)r   r   r>   r-   r   r   r   test___hash___incomplete
  s    
z TestKey.test___hash___incompletec                 C   sL   d}d}d}| j |||d}| t|t|t| t| td   d S rX   rn   )r   r   r>   r?   r-   r   r   r   test___hash___completed_w_id  s    
z$TestKey.test___hash___completed_w_idc                 C   sL   d}d}d}| j |||d}| t|t|t| t| td   d S )Nr   r   NAMEr   rn   rP   r   r   r   test___hash___completed_w_name  s    
z&TestKey.test___hash___completed_w_namec                 C   sL   | j d| jd}d}||}| ||u  | |j| | |jd  d S )Nr   r   r   r   r0   completed_keyrO   r&   r!   name)r   r-   r?   new_keyr   r   r   "test_completed_key_on_partial_w_id#  s    
z*TestKey.test_completed_key_on_partial_w_idc                 C   sL   | j d| jd}d}||}| ||u  | |jd  | |j| d S )Nr   r   rr   rt   )r   r-   rQ   rw   r   r   r   $test_completed_key_on_partial_w_name+  s    
z,TestKey.test_completed_key_on_partial_w_namec                 C   s&   | j d| jd}| t|jt  d S Nr   r   )r   r0   r   r   ru   rB   r   r-   r   r   r   'test_completed_key_on_partial_w_invalid3  s    z/TestKey.test_completed_key_on_partial_w_invalidc                 C   s&   | j dd| jd}| t|jd d S )Nr   r   r   i.  )r   r0   r   r   ru   r{   r   r   r   test_completed_key_on_complete7  s    z&TestKey.test_completed_key_on_completec                 C   s   ddl m} d}| j|| jd}| }| t||j | |j	j
| j | |j	jd t|j\}| |j| | |jd | |jd d S )Nr   )
entity_pb2r   r    )Zgcloud.datastore._generatedr~   r   r0   to_protobufr(   
isinstancer   r&   partition_id
project_idnamespace_idlistr'   r    rv   r!   )r   r~   r>   r-   pbelemr   r   r   test_to_protobuf_defaults;  s    z!TestKey.test_to_protobuf_defaultsc                 C   s.   d}| j d|d}| }| |jj| d S )Nr   r   r   )r   r   r&   r   r   )r   r   r-   r   r   r   r   #test_to_protobuf_w_explicit_projectP  s    z+TestKey.test_to_protobuf_w_explicit_projectc                 C   s2   d}| j d|| jd}| }| |jj| d S )Nr   r   r7   )r   r0   r   r&   r   r   )r   r=   r-   r   r   r   r   %test_to_protobuf_w_explicit_namespaceV  s    z-TestKey.test_to_protobuf_w_explicit_namespacec                 C   s   d}d}d}d}| j ||||| jd}| }t|j}| t|d | |d j| | |d j| | |d j| | |d j	| d S )	NrI   ZCHILDr   rr   r      r      )
r   r0   r   r   r'   r&   lenr    rv   r!   )r   Z_PARENTZ_CHILDr?   rQ   r-   r   Zelemsr   r   r    test_to_protobuf_w_explicit_path]  s    
z(TestKey.test_to_protobuf_w_explicit_pathc                 C   s@   | j d| jd}|jd d | }| |jd jd d S )Nr   r   r    r   r   )r   r0   _pathpopr   r&   r'   r    )r   r-   r   r   r   r   test_to_protobuf_w_no_kindl  s    z"TestKey.test_to_protobuf_w_no_kindc                 C   s    | j d| jd}| |j d S rz   )r   r0   r(   
is_partialr{   r   r   r   test_is_partial_no_name_or_idu  s    z%TestKey.test_is_partial_no_name_or_idc                 C   s&   d}| j d|| jd}| |j d S Nr   r   r   r   r0   rO   r   r   r?   r-   r   r   r   test_is_partial_w_idy  s    zTestKey.test_is_partial_w_idc                 C   s&   d}| j d|| jd}| |j d S Nrr   r   r   r   r   rQ   r-   r   r   r   test_is_partial_w_name~  s    zTestKey.test_is_partial_w_namec                 C   s"   | j d| jd}| |jd  d S rz   r   r0   r&   Z
id_or_namer{   r   r   r   test_id_or_name_no_name_or_id  s    z%TestKey.test_id_or_name_no_name_or_idc                 C   s&   | j ddd| jd}| |jd  d S )Nr   r   r   r   r   r{   r   r   r   #test_id_or_name_no_name_or_id_child  s    
z+TestKey.test_id_or_name_no_name_or_id_childc                 C   s(   d}| j d|| jd}| |j| d S r   r   r   r   r   r   test_id_or_name_w_id_only  s    z!TestKey.test_id_or_name_w_id_onlyc                 C   s(   d}| j d|| jd}| |j| d S r   r   r   r   r   r   test_id_or_name_w_name_only  s    z#TestKey.test_id_or_name_w_name_onlyc                 C   s"   | j d| jd}| |jd  d S rz   r   r0   r&   r%   r{   r   r   r   test_parent_default  s    zTestKey.test_parent_defaultc                 C   s$   | j dd| jd}| |jd  d S )Nr   r   r   r   r{   r   r   r   test_parent_explicit_top_level  s    z&TestKey.test_parent_explicit_top_levelc                 C   s<   d}d}||dg}| j ||d| jd}| |jj| d S Nr   r   r   r   r   )r   r0   r&   r%   r'   )r   r)   r*   _PARENT_PATHr-   r   r   r   test_parent_explicit_nested  s    
z#TestKey.test_parent_explicit_nestedc                 C   sT   d}d}||dg}| j ||d| jd}|j}| |j| |j}| ||u  d S r   )r   r0   r%   r&   r'   r(   )r   r)   r*   r   r-   r%   Z
new_parentr   r   r   test_parent_multiple_calls  s    
z"TestKey.test_parent_multiple_callsN)7__name__
__module____qualname__r0   r   r   r   r   r   r.   r2   r5   r9   r:   r;   r@   rC   rE   rH   rL   rR   rW   rZ   r[   r\   r^   rc   rh   rj   rk   rl   rm   rp   rq   rs   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      sh   		
	

	
			r   )Z	unittest2ZTestCaser   r   r   r   r   <module>   s   