a
    !f]                     @   s   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 j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 jZ	dd Z
dd Zdd Zdd ZG dd deZG dd deZG dd deZdS )     Nc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
Test__timedelta_to_duration_pbc                 O   s   ddl m} ||i |S )Nr   )_timedelta_to_duration_pb)gcloud.bigtable.column_familyr   )selfargskwargsr    r   c/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/bigtable/test_column_family.py_callFUT   s    z'Test__timedelta_to_duration_pb._callFUTc                 C   sj   dd l }ddlm} d }}|j||d}| |}| t||j | |j	| | |j
d|  d S )Nr   duration_pb2   secondsmicroseconds  datetimegoogle.protobufr   	timedeltar
   
assertTrue
isinstanceDurationassertEqualr   nanosr   r   r   r   r   timedelta_valresultr   r   r	   test_it   s    
z&Test__timedelta_to_duration_pb.test_itc                 C   sr   dd l }ddlm} d}d}|j||d}| |}| t||j | |j	|d  | |j
dd|   d S )Nr   r   r   r    ʚ;r   r   r   r   r   r	   test_with_negative_microseconds%   s    
z>Test__timedelta_to_duration_pb.test_with_negative_microsecondsc                 C   st   dd l }ddlm} d}d}|j||d}| |}| t||j | |j	|d  | |j
dd|    d S )	Nr   r      r   r   r    r   r   r   r   r   r	   test_with_negative_seconds2   s    
z9Test__timedelta_to_duration_pb.test_with_negative_secondsN)__name__
__module____qualname__r
   r   r!   r$   r   r   r   r	   r      s   r   c                   @   s   e Zd Zdd Zdd ZdS )Test__duration_pb_to_timedeltac                 O   s   ddl m} ||i |S )Nr   )_duration_pb_to_timedelta)r   r)   )r   r   r   r)   r   r   r	   r
   B   s    z'Test__duration_pb_to_timedelta._callFUTc                 C   sh   dd l }ddlm} d }}|j|d| d}|j||d}| |}| t||j | || d S )Nr   r   r   r   )r   r   r   )	r   r   r   r   r   r
   r   r   r   )r   r   r   r   r   Zduration_pbr   r   r   r   r	   r   F   s    
z&Test__duration_pb_to_timedelta.test_itN)r%   r&   r'   r
   r   r   r   r   r	   r(   @   s   r(   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestMaxVersionsGCRulec                 C   s   ddl m} |S )Nr   MaxVersionsGCRule)r   r,   )r   r,   r   r   r	   _getTargetClassV   s    z%TestMaxVersionsGCRule._getTargetClassc                 O   s   |   |i |S Nr-   r   r   r   r   r   r	   _makeOneZ   s    zTestMaxVersionsGCRule._makeOnec                 C   s    |  d}t }| || d S )N
   r1   objectassertNotEqualr   gc_rule1gc_rule2r   r   r	   test___eq__type_differ]   s    
z,TestMaxVersionsGCRule.test___eq__type_differc                 C   s$   |  d}|  d}| || d S )N   )r1   r   r6   r   r   r	   test___eq__same_valueb   s    

z+TestMaxVersionsGCRule.test___eq__same_valuec                 C   s*   |  d}|  d}||k}| | d S )Nc   )r1   assertFalse)r   r7   r8   comparison_valr   r   r	   test___ne__same_valueg   s    

z+TestMaxVersionsGCRule.test___ne__same_valuec                 C   s2   d}| j |d}| }t|d}| || d S )N9  max_num_versions)r1   to_pb	_GcRulePBr   )r   rB   gc_rulepb_valexpectedr   r   r	   
test_to_pbm   s
    
z TestMaxVersionsGCRule.test_to_pbN	r%   r&   r'   r-   r1   r9   r;   r?   rH   r   r   r   r	   r*   T   s   r*   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestMaxAgeGCRulec                 C   s   ddl m} |S )Nr   MaxAgeGCRule)r   rL   )r   rL   r   r   r	   r-   w   s    z TestMaxAgeGCRule._getTargetClassc                 O   s   |   |i |S r.   r/   r0   r   r   r	   r1   {   s    zTestMaxAgeGCRule._makeOnec                 C   s(   t  }| j|d}t  }| || d S Nmax_ager4   r1   r5   r   rO   r7   r8   r   r   r	   r9   ~   s    z'TestMaxAgeGCRule.test___eq__type_differc                 C   s.   t  }| j|d}| j|d}| || d S rM   r4   r1   r   rQ   r   r   r	   r;      s    z&TestMaxAgeGCRule.test___eq__same_valuec                 C   s4   t  }| j|d}| j|d}||k}| | d S rM   r4   r1   r=   )r   rO   r7   r8   r>   r   r   r	   r?      s
    z&TestMaxAgeGCRule.test___ne__same_valuec                 C   sV   dd l }ddlm} |jdd}|jdd}| j|d}| }| |t|d d S )Nr   r   r   r   rN   )	r   r   r   r   r   r1   rC   r   rD   )r   r   r   rO   durationrE   rF   r   r   r	   rH      s    zTestMaxAgeGCRule.test_to_pbNrI   r   r   r   r	   rJ   u   s   rJ   c                   @   sL   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S )TestGCRuleUnionc                 C   s   ddl m} |S )Nr   GCRuleUnion)r   rX   )r   rX   r   r   r	   r-      s    zTestGCRuleUnion._getTargetClassc                 O   s   |   |i |S r.   r/   r0   r   r   r	   r1      s    zTestGCRuleUnion._makeOnec                 C   s$   t  }| |}| |j|u  d S r.   r4   r1   r   rules)r   rZ   Z
rule_unionr   r   r	   test_constructor   s    
z TestGCRuleUnion.test_constructorc                 C   s*   t  }| |}| |}| || d S r.   rR   r   rZ   r7   r8   r   r   r	   test___eq__   s    

zTestGCRuleUnion.test___eq__c                 C   s&   t  }| |}t  }| || d S r.   rP   r\   r   r   r	   r9      s    
z&TestGCRuleUnion.test___eq__type_differc                 C   s0   t  }| |}| |}||k}| | d S r.   rS   r   rZ   r7   r8   r>   r   r   r	   r?      s
    

z%TestGCRuleUnion.test___ne__same_valuec                 C   s   dd l }ddlm} ddlm} ddlm} d}||}t|d}|jdd}||}	t|jddd	}
| j	||	gd
}tt
||
gd
d}| }| || d S )Nr   r   rK   r+   *   rA   r   rT   rN   rZ   unionr   r   r   r   rL   r,   rD   r   r   r1   _GcRuleUnionPBrC   r   r   r   r   rL   r,   rB   rule1pb_rule1rO   rule2pb_rule2rule3pb_rule3
gc_rule_pbr   r   r	   rH      s$    

zTestGCRuleUnion.test_to_pbc                 C   s   dd l }ddlm} ddlm} ddlm} d}||}t|d}|jdd}||}	t|jddd	}
| j	||	gd
}tt
||
gd
d}d}||}t|d}| j	||gd
}tt
||gd
d}| }| || d S )Nr   r   rK   r+   r_   rA   r   rT   rN   r`   ra   r@   rc   r   r   r   rL   r,   Zmax_num_versions1rf   rg   rO   rh   ri   rj   rk   Zmax_num_versions2Zrule4Zpb_rule4Zrule5Zpb_rule5rl   r   r   r	   test_to_pb_nested   s2    


z!TestGCRuleUnion.test_to_pb_nestedNr%   r&   r'   r-   r1   r[   r]   r9   r?   rH   rn   r   r   r   r	   rV      s   rV   c                   @   sL   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S )TestGCRuleIntersectionc                 C   s   ddl m} |S )Nr   GCRuleIntersection)r   rr   )r   rr   r   r   r	   r-      s    z&TestGCRuleIntersection._getTargetClassc                 O   s   |   |i |S r.   r/   r0   r   r   r	   r1      s    zTestGCRuleIntersection._makeOnec                 C   s$   t  }| |}| |j|u  d S r.   rY   )r   rZ   Zrule_intersectionr   r   r	   r[      s    
z'TestGCRuleIntersection.test_constructorc                 C   s*   t  }| |}| |}| || d S r.   rR   r\   r   r   r	   r]      s    

z"TestGCRuleIntersection.test___eq__c                 C   s&   t  }| |}t  }| || d S r.   rP   r\   r   r   r	   r9     s    
z-TestGCRuleIntersection.test___eq__type_differc                 C   s0   t  }| |}| |}||k}| | d S r.   rS   r^   r   r   r	   r?     s
    

z,TestGCRuleIntersection.test___ne__same_valuec                 C   s   dd l }ddlm} ddlm} ddlm} d}||}t|d}|jdd}||}	t|jddd	}
| j	||	gd
}tt
||
gd
d}| }| || d S )Nr   r   rK   r+   r_   rA   r   rT   rN   r`   intersectionr   r   r   r   rL   r,   rD   r   r   r1   _GcRuleIntersectionPBrC   r   re   r   r   r	   rH     s(    

z!TestGCRuleIntersection.test_to_pbc                 C   s   dd l }ddlm} ddlm} ddlm} d}||}t|d}|jdd}||}	t|jddd	}
| j	||	gd
}tt
||
gd
d}d}||}t|d}| j	||gd
}tt
||gd
d}| }| || d S )Nr   r   rK   r+   r_   rA   r   rT   rN   r`   rs   r@   ru   rm   r   r   r	   rn   *  s:    


z(TestGCRuleIntersection.test_to_pb_nestedNro   r   r   r   r	   rp      s   rp   c                   @   s   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d Zd$ddZdd Zdd Zd%ddZdd Zd d! Zd"d# ZdS )&TestColumnFamilyc                 C   s   ddl m} |S )Nr   )ColumnFamily)r   rx   )r   rx   r   r   r	   r-   M  s    z TestColumnFamily._getTargetClassc                 O   s   |   |i |S r.   r/   r0   r   r   r	   r1   Q  s    zTestColumnFamily._makeOnec                 C   sR   d}t  }t  }| j|||d}| |j| | |j|u  | |j|u  d S )Ncolumn-family-idrE   )r4   r1   r   column_family_idr   _tablerE   )r   r{   tablerE   column_familyr   r   r	   r[   T  s    z!TestColumnFamily.test_constructorc                 C   s:   d}d}t |}| ||}|d | }| |j| d S )Nry   
table_namez/columnFamilies/)_Tabler1   r   name)r   r{   r   r}   r~   Zexpected_namer   r   r	   test_name_property_  s    z#TestColumnFamily.test_name_propertyc                 C   s@   d}t  }t  }| j|||d}| j|||d}| || d S Nr{   rz   rR   )r   r{   r}   rE   column_family1column_family2r   r   r	   r]   h  s    zTestColumnFamily.test___eq__c                 C   s"   |  dd }t }| || d S Nr{   r3   r   r   r   r   r   r	   r9   r  s    z'TestColumnFamily.test___eq__type_differc                 C   sF   d}t  }t  }| j|||d}| j|||d}||k}| | d S r   rS   )r   r{   r}   rE   r   r   r>   r   r   r	   r?   w  s    z&TestColumnFamily.test___ne__same_valuec                 C   s(   |  dd }|  dd }| || d S )NZcolumn_family_id1Zcolumn_family_id2)r1   r5   r   r   r   r	   test___ne__  s    zTestColumnFamily.test___ne__c                 C   s*   |  dd }| }t }| || d S r   )r1   rC   _ColumnFamilyPBr   )r   r~   rF   rG   r   r   r	   test_to_pb_no_rules  s    z$TestColumnFamily.test_to_pb_no_rulesc                 C   sJ   ddl m} |d}| jdd |d}| }t| d}| || d S )Nr   r+   r   r{   rz   )r   r,   r1   rC   r   r   )r   r,   rE   r~   rF   rG   r   r   r	   test_to_pb_with_rule  s    z%TestColumnFamily.test_to_pb_with_ruleNc                 C   s  ddl m} ddlm} d}d}d}d}d}d	}	d
| d | d | d | }
t|	d}t|
|d}| j|||d}|d u rt }nt| d}|j	|
d}|j
j||d t }|| |_}d }| |j|f | }| |jd | || | |jd||	fi fg d S )Nr   bigtable_table_admin_pb2	_FakeStub
project-idzone
cluster-idtable-idry      	projects//zones/
/clusters//tables/timeout_secondsclientrz   r   )idcreater   ModifyColumnFamilies)gcloud.bigtable._generatedr   gcloud.bigtable._testingr   _Clientr   r1   r   rC   ModifyColumnFamiliesRequestmodificationsadd_table_stubr   resultsr   method_calls)r   rE   table_admin_v2_pb2r   
project_idr   
cluster_idtable_idr{   r   r   r   r}   r~   column_family_pb
request_pbresponse_pbstubexpected_resultr   r   r   r	   _create_test_helper  sX    
z$TestColumnFamily._create_test_helperc                 C   s   | j d d d S Nrz   )r   r   r   r   r	   test_create  s    zTestColumnFamily.test_createc                 C   s$   ddl m} |d}| j|d d S Nr   r+   r@   rz   )r   r,   r   r   r,   rE   r   r   r	   test_create_with_gc_rule  s    z)TestColumnFamily.test_create_with_gc_rulec                 C   s  ddl m} ddlm} d}d}d}d}d}d	}	d
| d | d | d | }
t|	d}t|
|d}| j|||d}|d u rt }nt| d}|j	|
d}|j
j||d t }|| |_}d }| |j|f | }| |jd | || | |jd||	fi fg d S )Nr   r   r   r   r   r   r   ry      r   r   r   r   r   r   rz   r   )r   updater   r   )r   r   r   r   r   r   r1   r   rC   r   r   r   r   r   r   r   r   )r   rE   r   r   r   r   r   r   r{   r   r   r   r}   r~   r   r   r   r   r   r   r   r   r	   _update_test_helper  sX    
z$TestColumnFamily._update_test_helperc                 C   s   | j d d d S r   )r   r   r   r   r	   test_update  s    zTestColumnFamily.test_updatec                 C   s$   ddl m} |d}| j|d d S r   )r   r,   r   r   r   r   r	   test_update_with_gc_rule  s    z)TestColumnFamily.test_update_with_gc_rulec                 C   s  ddl m} ddlm} ddlm} d}d}d}d}d	}d
}	d| d | d | d | }
t|	d}t|
|d}| ||}|j	|
d}|j
j|dd | }|| |_}d }| |j|f | }| |jd | || | |jd||	fi fg d S )Nr   )	empty_pb2r   r   r   r   r   r   ry      r   r   r   r   r   r   r   T)r   Zdropr   r   )r   r   r   r   r   r   r   r   r1   r   r   r   Emptyr   r   r   deleter   )r   r   r   r   r   r   r   r   r{   r   r   r   r}   r~   r   r   r   r   r   r   r   r	   test_delete  sP    
zTestColumnFamily.test_delete)N)N)r%   r&   r'   r-   r1   r[   r   r]   r9   r?   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   rw   K  s"   	


3
3rw   c                   @   sD   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S )Test__gc_rule_from_pbc                 O   s   ddl m} ||i |S )Nr   )_gc_rule_from_pb)r   r   )r   r   r   r   r   r   r	   r
   >  s    zTest__gc_rule_from_pb._callFUTc                 C   s   t  }| | |d  d S r.   )rD   r   r
   )r   rl   r   r   r	   
test_emptyB  s    z Test__gc_rule_from_pb.test_emptyc                 C   sF   ddl m} |d}| }| |}| t|| | || d S )Nr   r+   r   )r   r,   rC   r
   r   r   r   )r   r,   	orig_rulerl   r   r   r   r	   test_max_num_versionsG  s    
z+Test__gc_rule_from_pb.test_max_num_versionsc                 C   sV   dd l }ddlm} ||jdd}| }| |}| t|| | || d S )Nr   rK   r   rT   )	r   r   rL   r   rC   r
   r   r   r   )r   r   rL   r   rl   r   r   r   r	   test_max_ageP  s    
z"Test__gc_rule_from_pb.test_max_agec           
      C   s   dd l }ddlm} ddlm} ddlm} |d}||jdd}|||g}| }| |}	| t	|	| | 
|	| d S )Nr   rW   rK   r+   r   rT   )r   r   rX   rL   r,   r   rC   r
   r   r   r   )
r   r   rX   rL   r,   rf   rh   r   rl   r   r   r   r	   
test_unionZ  s    
z Test__gc_rule_from_pb.test_unionc           
      C   s   dd l }ddlm} ddlm} ddlm} |d}||jdd}|||g}| }| |}	| t	|	| | 
|	| d S )Nr   rq   rK   r+   r   rT   )r   r   rr   rL   r,   r   rC   r
   r   r   r   )
r   r   rr   rL   r,   rf   rh   r   rl   r   r   r   r	   test_intersectionh  s    
z'Test__gc_rule_from_pb.test_intersectionc                 C   sB   G dd dt }| |jg  | t| j| | |jdg d S )Nc                   @   s   e Zd Zg Zedd ZdS )z@Test__gc_rule_from_pb.test_unknown_field_name.<locals>.MockProtoc                 S   s   | j | dS )Nunknown)namesappend)clsr   r   r   r	   
WhichOneof{  s    zKTest__gc_rule_from_pb.test_unknown_field_name.<locals>.MockProto.WhichOneofN)r%   r&   r'   r   classmethodr   r   r   r   r	   	MockProtow  s   r   rule)r4   r   r   assertRaises
ValueErrorr
   )r   r   r   r   r	   test_unknown_field_namev  s    	z-Test__gc_rule_from_pb.test_unknown_field_nameN)
r%   r&   r'   r
   r   r   r   r   r   r   r   r   r   r	   r   <  s   	
r   c                  O   s   ddl m} |j| i |S Nr   )	table_pb2)r   r   GcRuler   kwZtable_v2_pb2r   r   r	   rD     s    rD   c                  O   s   ddl m} |jj| i |S r   )r   r   r   ZIntersectionr   r   r   r	   rv     s    rv   c                  O   s   ddl m} |jj| i |S r   )r   r   r   Unionr   r   r   r	   rd     s    rd   c                  O   s   ddl m} |j| i |S r   )r   r   rx   r   r   r   r	   r     s    r   c                   @   s   e Zd ZdddZdS )	_InstanceNc                 C   s
   || _ d S r.   )Z_client)r   r   r   r   r	   __init__  s    z_Instance.__init__)Nr%   r&   r'   r   r   r   r   r	   r     s   r   c                   @   s   e Zd ZdddZdS )r   Nc                 C   s
   || _ d S r.   r   )r   r   r   r   r	   r     s    z_Client.__init__)Nr   r   r   r   r	   r     s   r   c                   @   s   e Zd ZdddZdS )r   Nc                 C   s   || _ t|| _d S r.   )r   r   Z	_instance)r   r   r   r   r   r	   r     s    z_Table.__init__)Nr   r   r   r   r	   r     s   r   )Z	unittest2ZTestCaser   r(   r*   rJ   rV   rp   rw   r   rD   rv   rd   r   r4   r   r   r   r   r   r   r	   <module>   s    -!'VY rI