a
    !f/                     @   sP   d dl 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dS )
    Nc                   @   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 )TestResourceDescriptorc                 C   s   ddl m} |S )Nr   )ResourceDescriptor)gcloud.monitoring.resourcer   )selfr    r   `/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/monitoring/test_resource.py_getTargetClass   s    z&TestResourceDescriptor._getTargetClassc                 O   s   |   |i |S Nr   r   argskwargsr   r   r   _makeOne   s    zTestResourceDescriptor._makeOnec                 C   s   ddl m} d}d| }d}d}|ddd	d
|dddd
|dddd
g}| j|||||d}| |j| | |j| | |j| | |j| | |j| d S )Nr   )LabelDescriptorgce_instance1projects/my-project/monitoredResourceDescriptors/GCE Instance.A VM instance hosted in Google Compute Engine.
project_idSTRINGThe ID of the GCP project...)keyZ
value_typedescriptioninstance_idThe VM instance identifier...zoneThe GCE zone...)nametype_display_namer   labels)	Zgcloud.monitoring.labelr   r   assertEqualr   typer   r   r    )r   r   TYPENAMEDISPLAY_NAMEDESCRIPTIONLABELS
descriptorr   r   r   test_constructor   s6    	z'TestResourceDescriptor.test_constructorc                 C   s   d}d| }d}d}dddd}d	dd
d}dddd}|||||||gd}|   |}	| |	j| | |	j| | |	j| | |	j| | t|	jd |	j\}
}}| |
j	|d  | |j	|d  | |j	|d  d S )Nr   r   r   r   r   r   r   r   Z	valueTyper   r   r   r   r   r   r"   ZdisplayNamer   r       r   )
r   
_from_dictr!   r   r"   r   r   lenr    r   )r   r#   r$   r%   r&   LABEL1LABEL2LABEL3infor(   label1label2label3r   r   r   test_from_dict9   s:    z%TestResourceDescriptor.test_from_dictc                 C   sn   d}d| }||d}|   |}| |j| | |j| | |jd | |jd | |jd d S )Nr   r   )r   r"    r   )r   r-   r!   r   r"   r   r   r    )r   r#   r$   r2   r(   r   r   r   test_from_dict_defaultsY   s    z.TestResourceDescriptor.test_from_dict_defaultsc                 C   s.  d}d}dj ||d}d}d}ddd	d
}dddd
}dddd
}|||||||gd}	t|	}
t||
d}|  ||}| |j| | |j| | |j| | |j	| | t
|jd |j\}}}| |j|d  | |j|d  | |j|d  |
j\}dd| d}| || d S )N
my-projectr   z6projects/{project}/monitoredResourceDescriptors/{type})projectr"   r   r   r   r   r   r*   r   r   r   r   r+   r:   
connectionr,   r   GET/)methodpath)format_Connection_Clientr   Z_fetchr!   r   r"   r   r   r.   r    r   
_requested)r   PROJECTr#   r$   r%   r&   r/   r0   r1   ZRESOURCE_DESCRIPTORr<   clientr(   r3   r4   r5   requestexpected_requestr   r   r   
test_fetchi   sJ    z!TestResourceDescriptor.test_fetchc                 C   s
  d}dj |d}d}d}|| }|||d}d}d}|| }	|	||d}
d	||
gi}t|}t||d
}|  |}| t|d |\}}| |j| | |j| | |j	| | |j|	 | |j| | |j	| |j
\}dd| i d}| || d S )Nr9   0projects/{project}/monitoredResourceDescriptors/r:    custom.googleapis.com/resource-1This is the first resource.r   r"   r    custom.googleapis.com/resource-2This is the second resource.resourceDescriptorsr;      r=   r>   r?   r@   Zquery_params)rA   rB   rC   r   _listr!   r.   r   r"   r   rD   )r   rE   PATHTYPE1DESCRIPTION1NAME1RESOURCE_DESCRIPTOR1TYPE2DESCRIPTION2NAME2RESOURCE_DESCRIPTOR2RESPONSEr<   rF   descriptorsdescriptor1descriptor2rG   rH   r   r   r   	test_list   sJ    z TestResourceDescriptor.test_listc                 C   s  ddl m} d}dj|d}d}d}|| }|||d}d	}d
}	|| }
|
||	d}d}|g|d}d|gi}t||}t||d}|  |}| t|d |\}}| |j	| | |j
| | |j| | |j	|
 | |j
| | |j|	 |j\}}dd| i d}dd| d|id}| || | || | | |  | W d    n1 st0    Y  d S )Nr   NotFoundr9   rJ   rK   rL   rM   rN   rO   rP   zsecond-page-please)rQ   ZnextPageTokenrQ   r;   rR   r=   r>   rS   Z	pageToken)gcloud.exceptionsrd   rA   rB   rC   r   rT   r!   r.   r   r"   r   rD   assertRaises)r   rd   rE   rU   rV   rW   rX   rY   rZ   r[   r\   r]   ZTOKENZ	RESPONSE1Z	RESPONSE2r<   rF   r_   r`   ra   Zrequest1Zrequest2Zexpected_request1Zexpected_request2r   r   r   test_list_paged   s^    

z&TestResourceDescriptor.test_list_pagedc           
      C   s|   d}dj |d}d}dg i}t|}t||d}|  ||}| t|d |j\}dd	| d
|id}	| ||	 d S )Nr9   rJ   rK   z&resource.type = starts_with("foobar_")rQ   r;   r   r=   r>   filterrS   )rA   rB   rC   r   rT   r!   r.   rD   )
r   rE   rU   ZFILTERr^   r<   rF   r_   rG   rH   r   r   r   test_list_filtered   s    z)TestResourceDescriptor.test_list_filteredN)__name__
__module____qualname__r   r   r)   r6   r8   rI   rb   rg   ri   r   r   r   r   r      s    )0<r   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestResourcec                 C   s   ddl m} |S )Nr   )Resource)r   rn   )r   rn   r   r   r   r     s    zTestResource._getTargetClassc                 O   s   |   |i |S r	   r
   r   r   r   r   r     s    zTestResource._makeOnec                 C   s>   d}dddd}| j ||d}| |j| | |j| d S Nr   r9   Z1234567890123456789zus-central1-a)r   r   r   )r"   r    )r   r!   r"   r    )r   r#   r'   resourcer   r   r   r)     s    zTestResource.test_constructorc                 C   sH   d}dddd}||d}|   |}| |j| | |j| d S ro   r   r-   r!   r"   r    )r   r#   r'   r2   rp   r   r   r   r6   )  s    zTestResource.test_from_dictc                 C   s:   d}d|i}|   |}| |j| | |ji  d S )Nr   r"   rq   )r   r#   r2   rp   r   r   r   r8   8  s
    z$TestResource.test_from_dict_defaultsN)rj   rk   rl   r   r   r)   r6   r8   r   r   r   r   rm     s
   rm   c                   @   s   e Zd Zdd Zdd ZdS )rB   c                 G   s   t || _g | _d S r	   )list
_responsesrD   )r   	responsesr   r   r   __init__B  s    
z_Connection.__init__c                 K   sF   ddl m} | j| z| jdW S  ty@   |dY n0 d S )Nr   rc   Zmiss)re   rd   rD   appendrs   pop
IndexError)r   r   rd   r   r   r   api_requestF  s    z_Connection.api_requestN)rj   rk   rl   ru   ry   r   r   r   r   rB   @  s   rB   c                   @   s   e Zd Zdd ZdS )rC   c                 C   s   || _ || _d S r	   r;   )r   r:   r<   r   r   r   ru   Q  s    z_Client.__init__N)rj   rk   rl   ru   r   r   r   r   rC   O  s   rC   )Z	unittest2ZTestCaser   rm   objectrB   rC   r   r   r   r   <module>   s     +