a
    !fy*                     @   sN   d dl 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                   @   s   e Zd ZdZdZdeef ZdZdeef 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"S )#
TestClientPROJECTZ
topic_nameprojects/%s/topics/%sZsubscription_namezprojects/%s/subscriptions/%sc                 C   s   ddl m} |S )Nr   )Client)Zgcloud.pubsub.clientr   )selfr    r   Z/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/pubsub/test_client.py_getTargetClass   s    zTestClient._getTargetClassc                 O   s   |   |i |S N)r	   )r   argskwr   r   r   _makeOne   s    zTestClient._makeOnec           	      C   s   ddl m} ddlm} ddlm} t }| j| j|d}t	  }|_
||dd |j}W d    n1 sn0    Y  | || | |j|u  |j}| ||u  d S )Nr   )_PublisherAPIclient_MonkeyprojectcredentialsF_USE_GAX)gcloud.pubsub.connectionr   gcloud.pubsubr   gcloud._testingr   _Credentialsr   r   object
connectionpublisher_apiassertIsInstance
assertTrue_connection)	r   r   MUTr   credsr   connapiagainr   r   r   test_publisher_api_wo_gax    s    $z$TestClient.test_publisher_api_wo_gaxc           	         s   ddl m} ddlm} t g   fdd}G dd dt}t }| j| j|d}||d	||d
 |j}W d    n1 s0    Y  | 	|| | 
|ju  |j}| 
||u  d S )Nr   r   r   c                     s     | |f S r
   appendr   r   Z_called_withwrappedr   r   _generated_api8   s    z;TestClient.test_publisher_api_w_gax.<locals>._generated_apic                   @   s   e Zd Zdd ZdS )z=TestClient.test_publisher_api_w_gax.<locals>._GaxPublisherAPIc                 S   s
   || _ d S r
   _wrappedr   r/   r   r   r   __init__>   s    zFTestClient.test_publisher_api_w_gax.<locals>._GaxPublisherAPI.__init__N__name__
__module____qualname__r1   r   r   r   r   _GaxPublisherAPI<   s   r6   r   T)r   ZGeneratedPublisherAPIZGAXPublisherAPI)r   r   r   r   r   r   r   r   r   r   r    r/   )	r   r"   r   r-   r6   r#   r   r%   r&   r   r+   r   test_publisher_api_w_gax1   s$    $z#TestClient.test_publisher_api_w_gaxc           	      C   s   ddl m} ddlm} ddlm} t }| j| j|d}t	  }|_
||dd |j}W d    n1 sn0    Y  | || | |j|u  |j}| ||u  d S )Nr   )_SubscriberAPIr   r   r   Fr   )r   r8   r   r   r   r   r   r   r   r   r   subscriber_apir   r    r!   )	r   r8   r"   r   r#   r   r$   r%   r&   r   r   r   test_subscriber_api_wo_gaxP   s    $z%TestClient.test_subscriber_api_wo_gaxc           	         s   ddl m} ddlm} t g   fdd}G dd dt}t }| j| j|d}||d	||d
 |j}W d    n1 s0    Y  | 	|| | 
|ju  |j}| 
||u  d S )Nr   r   r   c                     s     | |f S r
   r(   r*   r+   r   r   r-   h   s    z<TestClient.test_subscriber_api_w_gax.<locals>._generated_apic                   @   s   e Zd Zdd ZdS )z?TestClient.test_subscriber_api_w_gax.<locals>._GaxSubscriberAPIc                 S   s
   || _ d S r
   r.   r0   r   r   r   r1   n   s    zHTestClient.test_subscriber_api_w_gax.<locals>._GaxSubscriberAPI.__init__Nr2   r   r   r   r   _GaxSubscriberAPIl   s   r;   r   T)r   ZGeneratedSubscriberAPIZGAXSubscriberAPI)r   r   r   r   r   r   r   r   r9   r   r    r/   )	r   r"   r   r-   r;   r#   r   r%   r&   r   r+   r   test_subscriber_api_w_gaxa   s$    $z$TestClient.test_subscriber_api_w_gaxc                 C   sh   ddl m} t }| j| j|d}t  }|_|j}| || | 	|j
|u  |j}| 	||u  d S )Nr   )_IAMPolicyAPIr   )r   r=   r   r   r   r   r   Ziam_policy_apir   r    r!   )r   r=   r#   r   r$   r%   r&   r   r   r   test_iam_policy_api   s    zTestClient.test_iam_policy_apic                 C   s   ddl m} t }| j| j|d}t |_t  }|_d| j	igd f|_
| \}}| t|d | |d | | |d j| j | |d  | |j| jd d f d S )Nr   Topicr   name   Zgcloud.pubsub.topicr@   r   r   r   r   r   _FauxPublisherAPI_publisher_api
TOPIC_PATH_list_topics_responselist_topicsassertEquallenr   rA   
TOPIC_NAME_listed_topics)r   r@   r#   r   r%   topicsnext_page_tokenr   r   r   test_list_topics_no_paging   s    z%TestClient.test_list_topics_no_pagingc           
      C   s   ddl m} d}d}d}t }| j| j|d}t |_t  }|_d| j	ig|f|_
|||\}}	| t|d | |d | | |d j| j | |	| | |j| jd|f d S )Nr   r?   TOKEN1TOKEN2rB   r   rA   rC   )
r   r@   rP   rQ   SIZEr#   r   r%   rM   rN   r   r   r   test_list_topics_with_paging   s    z'TestClient.test_list_topics_with_pagingc                 C   sr   t  }| j| j|d}t |_t  }|_d|_| \}}| 	t
|d | 	|d  | 	|j| jd d f d S )Nr   r   Nr   )r   r   r   r   r   rD   rE   rG   rH   rI   rJ   rL   )r   r#   r   r%   rM   rN   r   r   r   test_list_topics_missing_key   s    z'TestClient.test_list_topics_missing_keyc                 C   s   ddl m} | j| jd}t }| j| j|d}t |_t	  }|_
|gd f|_| \}}| t|d | |d | | |d j| j | |d jj| j | |d  | |j| jd d f d S )Nr   SubscriptionrA   topicr   rB   )gcloud.pubsub.subscriptionrW   SUB_PATHrF   r   r   r   r   r   _FauxSubscriberAPI_subscriber_api_list_subscriptions_responselist_subscriptionsrI   rJ   r   rA   SUB_NAMErY   rK   _listed_subscriptions)r   rW   SUB_INFOr#   r   r%   subscriptionsrN   r   r   r   !test_list_subscriptions_no_paging   s     
z,TestClient.test_list_subscriptions_no_pagingc                 C   s  ddl m} | j| jd}t }| j| j|d}d}d}| j| j|d|id}d	}d
}d}	t |_t	  }
|_
|g|f|
_||	|\}}| t|d | |d | | |d j| j | |d jj| j | |d j| | |d j| | || | |
j| j|	|f d S )Nr   rV   rX   r   *   z!https://push.example.com/endpointZpushEndpoint)rA   rY   ZackDeadlineSecondsZ
pushConfigrP   rQ   rB   )rZ   rW   r[   rF   r   r   r   r   r   r\   r]   r^   r_   rI   rJ   r   rA   r`   rY   rK   Zack_deadlineZpush_endpointra   )r   rW   rb   r#   r   ZACK_DEADLINEZPUSH_ENDPOINTrP   rQ   rR   r%   rc   rN   r   r   r   #test_list_subscriptions_with_paging   s<    
z.TestClient.test_list_subscriptions_with_pagingc                 C   st   d}t  }| j||d}t |_t  }|_d|_| \}}| t	|d | |d  | |j
| jd d f d S )Nr   r   rT   r   )r   r   r   r   r\   r]   r^   r_   rI   rJ   ra   r   )r   r   r#   r   r%   rc   rN   r   r   r   %test_list_subscriptions_w_missing_key   s    
z0TestClient.test_list_subscriptions_w_missing_keyc                 C   sx   d}d}t  }| j||d}||}| |j| | |j|u  | |j| | |jd||f  | 	|j
 d S )Nr   rK   r   r   )r   r   rY   rI   rA   r    Z_clientr   Z	full_nameZassertFalseZtimestamp_messages)r   r   rK   r#   Z
client_objZ	new_topicr   r   r   
test_topic  s    

zTestClient.test_topicN)r3   r4   r5   r   rK   rF   r`   r[   r	   r   r'   r7   r:   r<   r>   rO   rS   rU   rd   rf   rg   rh   r   r   r   r   r      s&    r   c                   @   s$   e Zd ZdZedd Zdd ZdS )r   Nc                   C   s   dS )NTr   r   r   r   r   create_scoped_required  s    z#_Credentials.create_scoped_requiredc                 C   s
   || _ | S r
   )_scopes)r   scoper   r   r   create_scoped  s    z_Credentials.create_scoped)r3   r4   r5   rj   staticmethodri   rl   r   r   r   r   r     s   
r   c                   @   s   e Zd Zdd ZdS )rD   c                 C   s   |||f| _ | jS r
   )rL   rG   r   r   Z	page_sizeZ
page_tokenr   r   r   rH   "  s    z_FauxPublisherAPI.list_topicsN)r3   r4   r5   rH   r   r   r   r   rD      s   rD   c                   @   s   e Zd Zdd ZdS )r\   c                 C   s   |||f| _ | jS r
   )ra   r^   rn   r   r   r   r_   )  s    z%_FauxSubscriberAPI.list_subscriptionsN)r3   r4   r5   r_   r   r   r   r   r\   '  s   r\   )Z	unittest2ZTestCaser   r   r   rD   r\   r   r   r   r   <module>   s     