U
    •uÄc¨£  ã                   @   sb  d dl Z d dlmZ e j dd¡�r^d dlmZmZmZ d dlm	Z	m
Z
mZ d dlmZ d dlZd dlmZ d dlmZ d d	lmZ d d
lmZmZmZmZmZmZ d dlmZ d dlmZmZ d dlm Z m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z' G dd„ de(ƒ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S )é    NZUSE_TWISTEDF)ÚinlineCallbacksÚDeferredÚreturnValue)ÚsucceedÚfailÚDeferredList)Úunittest)Úutil)ÚApplicationSession)ÚSession)ÚmessageÚroleÚ
serializerÚtypesÚuriÚCloseDetails)ÚCallRequest)ÚApplicationErrorÚNotAuthorized)Ú
InvalidUriÚProtocolError)Úcreate_authenticator)ÚIAuthenticator)ÚTransportDetailsc                   @   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 )ÚMockTransportc                 C   s~   d| _ || _t ¡ | _i | _i | _i | _| j | ¡ t	 
¡ | _t ¡ t ¡ dœ}t | j|¡}| j |¡ tƒ | _tƒ | _d S )NF)ZbrokerZdealer)Ú_logÚ_handlerr   ZJsonSerializerÚ_serializerÚ_registrationsÚ_invocationsÚ_subscription_topicsZonOpenr	   ÚidZ_my_session_idr   ZRoleBrokerFeaturesZRoleDealerFeaturesr   ZWelcomeÚ	onMessager
   Ú_fake_router_sessionr   Ú_transport_details)ÚselfÚhandlerZrolesÚmsg© r(   úpc:\users\psant\downloads\hotstarbackend\school\venv38\Lib\site-packages\autobahn\wamp\test\test_wamp_protocol.pyÚ__init__2   s    

zMockTransport.__init__c                 C   s   | j S ©N)r$   ©r%   r(   r(   r)   Útransport_detailsG   s    zMockTransport.transport_detailsc                 C   s   | j  t d|¡¡ d S )Nr   )r   r"   r   ÚUnregistered)r%   Zreg_idr(   r(   r)   Údrop_registrationJ   s    
ÿzMockTransport.drop_registrationc           	      C   s  | j r$| j |¡\}}td |¡ƒ d }t|tjƒr¨|j 	d¡r^|j
r¤t |j| jj ¡ ¡}nFt|jƒdkr‚t tjj|jd¡}n"|j 	d¡r�nt tjj|jd¡}�n.t|tjƒ�rœ|jdkrÔtj|jdgd	�}nÄ|jd
krötj|jdddgd	�}n¢|jdk�r"tj|jdddgdddœd�}nv|j 	d¡�r„| j|j }| jj ¡ }|| jk�r\tdƒ‚|j| j|< tj|||j|j|jd�}nt tjj|jd¡}�n:t|tjƒ�rÞ|j| jk�rÖ| j|j }tj||j|j|jd�}nøt|tjƒ�r0|j}|| j k�r
| j | }n| jj ¡ }|| j |< t !|j|¡}n¦t|tj"ƒ�rLt #|j¡}nŠt|tj$ƒ�r‚| jj ¡ }|| j|j< t %|j|¡}nTt|tj&ƒ�ržt '|j¡}n8t|tjƒ�rÖ| j|j }tjtjj||j(|j|jd�}|�r| j �r| j |¡\}}td |¡ƒ | j) *|¡ d S )Nz	Send: {0}z	com.myappr   zwamp.error.invalid_uriznoreply.zwamp.error.not_authorizedúcom.myapp.procedure1éd   ©Úargsúcom.myapp.procedure2é   é   é   úcom.myapp.procedure3Úbaré   ©ÚfooZbaz©r3   Úkwargszcom.myapp.myproczduplicate invocation)r3   r>   Úreceive_progresszwamp.error.no_such_procedure)r3   r>   ÚprogresszReceive: {0})+r   r   Ú	serializeÚprintÚformatÚ
isinstancer   ZPublishÚtopicÚ
startswithÚacknowledgeZ	PublishedÚrequestr#   Z_request_id_genÚnextÚlenÚErrorZMESSAGE_TYPEÚCallÚ	procedureZResultr   r   r   Z
Invocationr3   r>   r?   ÚYieldr@   Z	Subscriber    Z
SubscribedZUnsubscribeÚUnsubscribedÚRegisterZ
RegisteredÚ
Unregisterr.   Úerrorr   r"   )	r%   r'   ÚpayloadZisbinaryZreplyÚregistrationrH   rE   Zreply_idr(   r(   r)   ÚsendO   s†    

  ü
ûzMockTransport.sendc                 C   s   dS ©NTr(   r,   r(   r(   r)   ÚisOpen£   s    zMockTransport.isOpenc                 C   s   d S r+   r(   r,   r(   r(   r)   Úclose¦   s    zMockTransport.closec                 C   s   d S r+   r(   r,   r(   r(   r)   Úabort©   s    zMockTransport.abortN)
Ú__name__Ú
__module__Ú__qualname__r*   r-   r/   rU   rW   rX   rY   r(   r(   r(   r)   r   0   s   Tr   c                   @   s   e Zd Zdd„ Zdd„ ZdS )Ú	TestClosec                 C   s   t ƒ }t|ƒ | d¡ d S )NF)r
   r   ÚonClose)r%   r&   r(   r(   r)   Útest_server_abort­   s    zTestClose.test_server_abortc                 C   s<   t ƒ }t|ƒ ttƒ ƒ}tdd|i ƒ|jd< | tƒ ¡ d S )Nr5   r<   )r
   r   r   Ú	Exceptionr   Z
_call_reqsÚonLeaver   )r%   r&   Zdeferredr(   r(   r)   Útest_reject_pendingµ   s
    
zTestClose.test_reject_pendingN)rZ   r[   r\   r_   rb   r(   r(   r(   r)   r]   ¬   s   r]   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestRegisterDecoratorc                 C   s„   G dd„ dt ƒ}|ƒ }t ¡ |_|j|dd� |  dt|jjƒ¡ |jjd }|  d|d ¡ | ¡ d d d }|  d|j	¡ d S )	Nc                   @   s   e Zd Ze d¡dd„ ƒZdS )z1TestRegisterDecorator.test_prefix.<locals>.PrefixÚmethod_namec                 S   s   d S r+   r(   r,   r(   r(   r)   Úsome_methodÄ   s    z=TestRegisterDecorator.test_prefix.<locals>.Prefix.some_methodN©rZ   r[   r\   r   Úregisterre   r(   r(   r(   r)   ÚPrefixÂ   s   rh   zcom.example.prefix.©Úprefixr5   r   rU   zcom.example.prefix.method_name©
r
   ÚmockÚMockÚ
_transportrg   ÚassertEqualrJ   Z
mock_callsZ	call_listrM   )r%   rh   ÚsessionÚcallÚregr(   r(   r)   Útest_prefixÀ   s    
z!TestRegisterDecorator.test_prefixc                 C   s„   G dd„ dt ƒ}|ƒ }t ¡ |_|j|dd� |  dt|jjƒ¡ |jjd }|  d|d ¡ | ¡ d d d }|  d|j	¡ d S )	Nc                   @   s   e Zd Ze d¡dd„ ƒZdS )z3TestRegisterDecorator.test_auto_name.<locals>.MagicNc                 S   s   d S r+   r(   r,   r(   r(   r)   re   Ø   s    z?TestRegisterDecorator.test_auto_name.<locals>.Magic.some_methodrf   r(   r(   r(   r)   ÚMagicÖ   s   rt   zcom.example.ri   r5   r   rU   zcom.example.some_methodrk   )r%   rt   rp   rq   rr   r(   r(   r)   Útest_auto_nameÔ   s    
z$TestRegisterDecorator.test_auto_nameN)rZ   r[   r\   rs   ru   r(   r(   r(   r)   rc   ¾   s   rc   c                   @   sô   e Zd Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZed	d
„ ƒZedd„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd „ ƒZed!d"„ ƒZd#d$„ Zed%d&„ ƒZd'd(„ Zd)S )*ÚTestPublisherc                 c   sþ   t ƒ }t|ƒ | d¡V }|  |d ¡ | dddd¡V }|  |d ¡ |jddddddd�V }|  |d ¡ |jdtjdd	�d
�V }|  |d ¡ |jddddddtjddddgd�d�V }|  |d ¡ |jddddddtjddddgdd�d�V }|  |d ¡ d S )Núcom.myapp.topic1r5   r6   r7   r:   Úhello©r<   r9   F)Ú
exclude_me©Úoptionsr1   éÈ   é,  )rz   Úexclude©r<   r9   r|   T)rz   r   Zretain)r
   r   Úpublishro   r   ÚPublishOptions©r%   r&   Úpublicationr(   r(   r)   Útest_publishé   s    *,zTestPublisher.test_publishc              
   c   sŒ   t ƒ }t|ƒ |jdtjdd�d�}tjddd�}| |¡V  z
|V  W n> tk
r† } z |  d|j	¡ |  d|j
¡ W 5 d }~X Y nX d S )Núnoreply.fooT©rG   r{   Útestingúhow are you?©Úreasonr   )r
   r   r�   r   r‚   r   ra   r   ro   rR   r   )r%   r&   r„   ÚdetailsÚer(   r(   r)   Útest_publish_outstanding_errors   s    
þ
z-TestPublisher.test_publish_outstanding_errorsc              
   #   sÆ   t ƒ }t|ƒ tƒ ‰ |jdtjdd�d�}g ‰‡ ‡fdd„}| |¡ tjddd	�}| |¡ |  	d
t
ˆƒ¡ ˆ  d ¡ z
|V  W n> tk
rÀ } z |  	d|j¡ |  	d|j¡ W 5 d }~X Y nX d S )Nr†   Tr‡   r{   c                    s   ˆ  | ¡ ˆ S r+   )Úappend)r   ©Zerror_dZ
got_errorsr(   r)   Úerrback(  s    
zLTestPublisher.test_publish_outstanding_errors_async_errback.<locals>.errbackrˆ   r‰   rŠ   r5   )r
   r   r   r�   r   r‚   Z
addErrbackr   ra   ro   rJ   Úcallbackr   rR   r   )r%   r&   Zpublication_dr‘   rŒ   r�   r(   r�   r)   Ú-test_publish_outstanding_errors_async_errback  s&    
þ



z;TestPublisher.test_publish_outstanding_errors_async_errbackc                 c   s  t ƒ }t|ƒ |jdtjdd�d�V }|  t|jƒtk¡ |jddddtjdd�d�V }|  t|jƒtk¡ |jdddddd	tjdd�d
�V }|  t|jƒtk¡ |jdtjddd�d�V }|  t|jƒtk¡ |jdddddd	tjddddgdd�d
�V }|  t|jƒtk¡ d S )Nrw   Tr‡   r{   r5   r6   r7   r:   rx   r€   F)rz   rG   r1   r}   r~   )rz   r   rG   )	r
   r   r�   r   r‚   Ú
assertTrueÚtyper!   Úintrƒ   r(   r(   r)   Útest_publish_acknowledgedA  s    ",z'TestPublisher.test_publish_acknowledgedc                 c   sN   t ƒ }t|ƒ tjdd�}|  |jd|d�t¡V  |  |jd|d�t¡V  d S ©NTr‡   zde.myapp.topic1r{   Zfoobar)r
   r   r   r‚   ÚassertFailurer�   r   ©r%   r&   r|   r(   r(   r)   Ú test_publish_undefined_exceptionU  s
    z.TestPublisher.test_publish_undefined_exceptionc                 c   sb   t ƒ }t|ƒ tjdd�}| t¡ |  |jd|d�t¡V  | t¡ |  |jd|d�t¡V  d S r˜   )	r
   r   r   r‚   Údefiner   r™   r�   r   rš   r(   r(   r)   Útest_publish_defined_exception_  s    

z,TestPublisher.test_publish_defined_exceptionc              
   c   s¾   t ƒ }t|ƒ | d¡V }|  |d¡ | dddd¡V }|  |d¡ |jddddddd�V }|  |d¡ |jdtjd	d
�d�V }|  |d¡ |jddddddtjd	d
�d�V }|  |d¡ d S )Nr0   r1   r5   r6   r7   r:   rx   ry   i'  )Útimeoutr{   r€   )r
   r   rq   ro   r   ÚCallOptions©r%   r&   Úresr(   r(   r)   Ú	test_calll  s    "zTestPublisher.test_callc                 c   s„   t ƒ }t|ƒ | d¡V }|  |tj¡ |  |jd¡ |  |ji ¡ | d¡V }|  |tj¡ |  |jd¡ |  |jdddœ¡ d S )Nr4   )r5   r6   r7   r8   r9   r:   r;   )	r
   r   rq   ÚassertIsInstancer   Z
CallResultro   ÚresultsZ	kwresultsr    r(   r(   r)   Útest_call_with_complex_result€  s    z+TestPublisher.test_call_with_complex_resultc                 c   sš   t ƒ }t|ƒ dd„ }| |d¡V }|  t|jƒtk¡ |j|dtjdd�d�V }|  t|jƒtk¡ |j|dtjddd�d�V }|  t|jƒtk¡ d S )	Nc                  _   s   t d| |ƒ d S ©Nz	got event©rB   r=   r(   r(   r)   Úon_event”  s    z.TestPublisher.test_subscribe.<locals>.on_eventrw   Zwildcard©Úmatchr{   T)rª   Zget_retained)	r
   r   Ú	subscriber”   r•   r!   r–   r   ÚSubscribeOptions©r%   r&   r¨   Zsubscriptionr(   r(   r)   Útest_subscribe�  s    zTestPublisher.test_subscribec                 #   s¨   t ƒ }t|ƒ tƒ ‰ tƒ ‰| ‡ fdd„d¡V }| ‡fdd„d¡V }|  |j|jk¡ |jdtjddd�d�V }| 	t
 |j|j¡¡ |  ˆ jd	¡ |  ˆjd	¡ d S )
Nc                      s
   ˆ   d¡S ©Né*   ©r’   r(   ©Úevent0r(   r)   Ú<lambda>©  ó    z5TestPublisher.test_double_subscribe.<locals>.<lambda>rw   c                      s
   ˆ   d¡S ©Nr<   r±   r(   ©Úevent1r(   r)   r´   «  rµ   TF©rG   rz   r{   úMissing callback)r
   r   r   r«   r”   r!   r�   r   r‚   r"   r   ÚEventÚcalled)r%   r&   Úsubscription0Úsubscription1r�   r(   )r³   r¸   r)   Útest_double_subscribe   s(    
 ÿ
 ÿþz#TestPublisher.test_double_subscribec                 #   sÆ   t ƒ ‰tˆƒ ‡fdd„}|ˆ_tƒ ‰ tƒ ‰ˆ ‡ fdd„d¡V }ˆ ‡fdd„d¡V }|  |j|jk¡ | ¡ V  ˆjdt	j
ddd	�d
�V }ˆ t |j|j¡¡ |  ˆ jd¡ |  ˆj d¡ dS )z}
            Make sure we correctly deal with unsubscribing one of our handlers
            from the same topic.
            c                    s   t | tjƒrt‚t ˆ | ¡S r+   )rD   r   rO   ÚAssertionErrorr
   r"   ©r'   )r&   r(   r)   r"   È  s    zITestPublisher.test_double_subscribe_single_unsubscribe.<locals>.onMessagec                      s
   ˆ   d¡S r¯   r±   r(   r²   r(   r)   r´   Ò  rµ   zHTestPublisher.test_double_subscribe_single_unsubscribe.<locals>.<lambda>rw   c                      s
   ˆ   d¡S r¶   r±   r(   r·   r(   r)   r´   Ô  rµ   TFr¹   r{   rº   úSecond callback fired.N)r
   r   r"   r   r«   r”   r!   Úunsubscriber�   r   r‚   r   r»   r¼   ©r%   r"   r½   r¾   r�   r(   )r³   r¸   r&   r)   Ú(test_double_subscribe_single_unsubscribe¼  s.    
 ÿ
 ÿ
þz6TestPublisher.test_double_subscribe_single_unsubscribec                 #   s  t ƒ ‰tˆƒ tƒ ‰‡‡fdd„}|ˆ_tƒ ‰ tƒ ‰ˆ ‡ fdd„d¡V }ˆ ‡fdd„d¡V }|  |j|jk¡ | ¡ V  | ¡ V  ˆjs�t	‚ˆj
dtjddd	�d
�V }z$ˆ t |j|j¡¡ |  d¡ W n tk
râ   Y nX |  ˆ j d¡ |  ˆj d¡ dS )z
            If we subscribe twice, and unsubscribe twice, we should then get
            an Unsubscribed message.
            c                    s"   t | tjƒrˆ | ¡ t ˆ | ¡S r+   )rD   r   rO   r’   r
   r"   rÁ   )r&   Úunsubscribed_dr(   r)   r"   ó  s    
zITestPublisher.test_double_subscribe_double_unsubscribe.<locals>.onMessagec                      s
   ˆ   d¡S r¯   r±   r(   r²   r(   r)   r´   ý  rµ   zHTestPublisher.test_double_subscribe_double_unsubscribe.<locals>.<lambda>rw   c                      s
   ˆ   d¡S r¶   r±   r(   r·   r(   r)   r´   ÿ  rµ   TFr¹   r{   zExpected ProtocolErrorzFirst callback fired.rÂ   N)r
   r   r   r"   r«   r”   r!   rÃ   r¼   rÀ   r�   r   r‚   r   r»   r   r   rÄ   r(   )r³   r¸   r&   rÆ   r)   Ú(test_double_subscribe_double_unsubscribeç  s<    
 ÿ
 ÿ


þz6TestPublisher.test_double_subscribe_double_unsubscribec                 #   sÖ   t ƒ }t|ƒ tƒ ‰ tƒ ‰‡‡fdd„}| ‡ fdd„d¡V }| |dtjdd�¡V }ˆ |j|jk¡ |jdtj	dd	d
�d�V }| 
tj|j|jdgd�¡ ˆ ˆ j¡ ˆ ˆj¡ ˆ ˆ jd¡ ˆ ˆjd¡ dS )z²
            Test various error-conditions when we try to add a second
            subscription-handler (its signature must match any
            existing handlers).
            c                     s2   ˆ  d|k¡ ˆ  t|d tjƒ¡ ˆ  | ¡ d S )NÚboom)r”   rD   r   ZEventDetailsr’   )r3   Úkw)r¸   r%   r(   r)   Úsecond)  s    z:TestPublisher.test_double_subscribe_errors.<locals>.secondc                    s
   ˆ   | ¡S r+   r±   ©Úargr²   r(   r)   r´   1  rµ   z<TestPublisher.test_double_subscribe_errors.<locals>.<lambda>rw   rÈ   ©Zdetails_argTFr¹   r{   Úarg0r2   )rÎ   N)r
   r   r   r«   r   r¬   r”   r!   r�   r‚   r"   r   r»   r¼   ro   Úresult)r%   r&   rÊ   r½   r¾   r�   r(   )r³   r¸   r%   r)   Útest_double_subscribe_errors  s4    
 ÿ 
þþÿz*TestPublisher.test_double_subscribe_errorsc                 #   sŽ   t ƒ }t|ƒ tdƒ‰ tƒ ‰‡ ‡fdd„}||_‡ fdd„}| |d¡V }|jdtjddd	�d
�V }t	 
|j|j¡}| |¡ |  ˆj¡ dS )zK
            Ensure we handle an exception from the user code.
            zwe have a problemc                    s   ˆ | j krˆ d¡ d S rV   )Úvaluer’   ©r�   r'   ©Úerror_instanceZ	got_err_dr(   r)   ÚobserverW  s    
z?TestPublisher.test_publish_callback_exception.<locals>.observerc                      s   ˆ ‚d S r+   r(   r(   )rÔ   r(   r)   rÈ   \  s    z;TestPublisher.test_publish_callback_exception.<locals>.boomrw   TFr¹   r{   N)r
   r   ÚRuntimeErrorr   ÚonUserErrorr«   r�   r   r‚   r   r»   r!   r"   r”   r¼   )r%   r&   rÕ   rÈ   Úsubr�   r'   r(   rÓ   r)   Útest_publish_callback_exceptionL  s    þ
z-TestPublisher.test_publish_callback_exceptionc                 c   s2   t ƒ }t|ƒ dd„ }| |d¡V }| ¡ V  d S )Nc                  _   s   t d| |ƒ d S r¦   r§   r=   r(   r(   r)   r¨   s  s    z0TestPublisher.test_unsubscribe.<locals>.on_eventrw   )r
   r   r«   rÃ   r­   r(   r(   r)   Útest_unsubscriben  s
    zTestPublisher.test_unsubscribec                 c   sj   t ƒ }t|ƒ dd„ }| |d¡V }|  t|jƒtk¡ |j|dtjdd�d�V }|  t|jƒtk¡ d S )Nc                  _   s   t d| |ƒ d S ©Nzgot callr§   r=   r(   r(   r)   Úon_call~  s    z,TestPublisher.test_register.<locals>.on_callr0   rj   r©   r{   )	r
   r   rg   r”   r•   r!   r–   r   ÚRegisterOptions©r%   r&   rÜ   rT   r(   r(   r)   Útest_registery  s    zTestPublisher.test_registerc                 c   s2   t ƒ }t|ƒ dd„ }| |d¡V }| ¡ V  d S )Nc                  _   s   t d| |ƒ d S rÛ   r§   r=   r(   r(   r)   rÜ   Œ  s    z.TestPublisher.test_unregister.<locals>.on_callr0   )r
   r   rg   Ú
unregisterrÞ   r(   r(   r)   Útest_unregister‡  s
    zTestPublisher.test_unregisterc              	   C   s\   t jjdk rd S tƒ }t|ƒ}|  t¡�}| t 	dd¡¡ W 5 Q R X |  
dt|jƒ¡ d S )Né   r   iÒ  z3UNREGISTERED received for non-existant registration)ÚtwistedÚversionÚmajorr
   r   ÚassertRaisesr   rU   r   rQ   ÚassertInÚstrÚ	exception)r%   r&   Ú	transportÚctxr(   r(   r)   Ú$test_unregister_no_such_registration’  s    
ÿþz2TestPublisher.test_unregister_no_such_registrationc                 #   sJ   t ƒ }t|ƒ}‡ fdd„‰ dˆ _| ˆ d¡V }| |j¡ |  ˆ j¡ d S )Nc                     s
   dˆ _ d S rV   )r¼   r=   ©rÜ   r(   r)   rÜ   ¦  s    z2TestPublisher.test_unregister_log.<locals>.on_callFr0   )r
   r   r¼   rg   r/   r!   ÚassertFalse)r%   r&   rê   rT   r(   rí   r)   Útest_unregister_log¡  s    z!TestPublisher.test_unregister_logc                    s\   g ‰ G ‡ fdd„dt ƒ}|ƒ }t|ƒ | d¡ |  tˆ ƒd¡ |  tˆ d d tƒ¡ d S )Nc                       s"   e Zd Z‡ fdd„Zddd„ZdS )z7TestPublisher.test_on_disconnect_error.<locals>.AppSessc                    s   ˆ   |j|f¡ d S r+   ©r�   rÑ   )r%   r�   r'   ©Úerrorsr(   r)   r×   ²  s    zCTestPublisher.test_on_disconnect_error.<locals>.AppSess.onUserErrorÚsnarkc                 S   s   t dƒ‚d S )NzThis shouldn't happen)rÖ   )r%   r<   r9   Zquuxr(   r(   r)   ÚonDisconnectµ  s    zDTestPublisher.test_on_disconnect_error.<locals>.AppSess.onDisconnectN)ró   )rZ   r[   r\   r×   rô   r(   rñ   r(   r)   ÚAppSess±  s   rõ   Fr5   r   )r
   r   r^   ro   rJ   r”   rD   Ú	TypeError)r%   rõ   Úsr(   rñ   r)   Útest_on_disconnect_error®  s    
z&TestPublisher.test_on_disconnect_errorN)rZ   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(   r(   r)   rv   ç   sL   


(

	





*
4
/
!





rv   c                   @   s„   e Zd Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZed	d
„ ƒZedd„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZdS )ÚTestInvokerc                 c   s@   t ƒ }t|ƒ dd„ }| |d¡V  | d¡V }|  |d¡ d S )Nc                   S   s   dS ©Nr:   r(   r(   r(   r(   r)   Úmyproc1Ë  s    z(TestInvoker.test_invoke.<locals>.myproc1úcom.myapp.myproc1r:   )r
   r   rg   rq   ro   )r%   r&   rû   r¡   r(   r(   r)   Útest_invokeÆ  s    zTestInvoker.test_invokec                 c   sZ   t ƒ }t|ƒ dd„ }| |d¡V  | d¡}| d¡}t||gƒV }|  |ddg¡ d S )Nc                   S   s   dS rú   r(   r(   r(   r(   r)   rû   Ø  s    z.TestInvoker.test_invoke_twice.<locals>.myproc1rü   ©Tr:   )r
   r   rg   rq   r   ro   )r%   r&   rû   Úd0Úd1r¡   r(   r(   r)   Útest_invoke_twiceÓ  s    

zTestInvoker.test_invoke_twicec           	      #   s®   t ƒ }t ƒ }t|ƒ}t|ƒ}‡fdd„‰|j‰ |j‰‡ ‡fdd„|_‡‡fdd„|_dd„ }| |d¡V  | |d¡V  | d¡}| d¡}t||gƒV }ˆ |d	d	g¡ d
S )zW
            make sure each session independently generates sequential IDs
            c                    s>   t |tjƒrˆ  |jd¡ nt |tjƒr6ˆ  |jd¡ | |ƒS )Nr5   r6   )rD   r   rP   ro   rH   rL   )Úorigr'   r,   r(   r)   Úverify_seq_idî  s
    zCTestInvoker.test_invoke_request_id_sequences.<locals>.verify_seq_idc                    s
   ˆˆ | ƒS r+   r(   rÁ   )Úorig0r  r(   r)   r´   ö  rµ   z>TestInvoker.test_invoke_request_id_sequences.<locals>.<lambda>c                    s
   ˆˆ | ƒS r+   r(   rÁ   )Úorig1r  r(   r)   r´   ÷  rµ   c                   S   s   dS rú   r(   r(   r(   r(   r)   rû   ù  s    z=TestInvoker.test_invoke_request_id_sequences.<locals>.myproc1rü   rþ   N)r
   r   rU   rg   rq   r   ro   )	r%   Zhandler0Zhandler1Ztrans0Ztrans1rû   rÿ   r   r¡   r(   )r  r  r%   r  r)   Ú test_invoke_request_id_sequencesâ  s     

z,TestInvoker.test_invoke_request_id_sequencesc              
   #   sÂ   t ƒ }d|_t|ƒ g ‰ ‡ fdd„}||_tdƒ‰‡fdd„}| |d¡V  z| d¡V  |  d¡ W n2 tk
r˜ } z|  	t
|tƒ¡ W 5 d }~X Y nX |  d	tˆ ƒ¡ |  ˆˆ d
 d
 ¡ d S )NTc                    s   ˆ   | j|f¡ d S r+   rð   rÒ   rñ   r(   r)   Ú	log_error  s    z6TestInvoker.test_invoke_user_raises.<locals>.log_errorr<   c                      s   ˆ ‚d S r+   r(   r(   )Ú
name_errorr(   r)   Úbing  s    z1TestInvoker.test_invoke_user_raises.<locals>.bingzcom.myapp.myproc99zExpected an errorr5   r   )r
   Ztraceback_appr   r×   Ú	NameErrorrg   rq   r   r`   r”   rD   rÖ   ro   rJ   )r%   r&   r  r	  r�   r(   )rò   r  r)   Útest_invoke_user_raises  s     "z#TestInvoker.test_invoke_user_raisesc                 #   s²   t ƒ }t|ƒ td‡fdd„	ƒ}ttdd„ tdƒƒƒ‰ ‡ fdd„}| |dtjd	d
�¡V  |j	dtj
|d�d�V }ˆ d|¡ tdƒD ]&}ˆ ˆ | j¡ ˆ |ˆ | j¡ q†d S )Nc                 3   sL   ˆ   | d k	¡ ˆ   | jd k	¡ tdƒD ]}|  |¡ t|ƒV  q&tdƒ d S )Né
   r°   )r”   r@   Úranger   r   )rŒ   Úir,   r(   r)   r	  *  s    
z8TestInvoker.test_invoke_progressive_result.<locals>.bingc                 S   s   t ƒ S r+   )r   )Ú_r(   r(   r)   r´   3  rµ   z<TestInvoker.test_invoke_progressive_result.<locals>.<lambda>r  c                    s   ˆ |    | ¡ d S r+   r±   rË   )Úprogressiver(   r)   r@   5  s    z<TestInvoker.test_invoke_progressive_result.<locals>.progressúcom.myapp.myproc2rŒ   rÍ   ©Zon_progressr{   r°   )N)r
   r   r   ÚlistÚmapr  rg   r   rÝ   rq   rŸ   ro   r”   r¼   rÏ   )r%   r&   r	  r@   r¡   r  r(   )r  r%   r)   Útest_invoke_progressive_result%  s&    
ý
þz*TestInvoker.test_invoke_progressive_resultc                 #   sØ   t ƒ }t|ƒ td‡fdd„	ƒ}tƒ ‰ tdƒ‰g ‰‡fdd„}||_d‡ ‡‡fdd„	}| |dtjd	d
�¡V  |j	ddtj
|d�dd�V }ˆ d|¡ ˆ ˆ j¡ ˆ dˆ j¡ ˆ dtˆƒ¡ ˆ ˆˆd d ¡ d S )Nc                 3   sZ   ˆ   |d k	¡ ˆ   |jd k	¡ ˆ  |d¡ ˆ  d| ¡ |jddd� tdƒV  tdƒ d S )NÚwordrÌ   ÚlifeÚnothing)Ú	somethingz
meaning ofr°   )r”   r@   ro   r   r   )rÌ   rŒ   Úkeyr,   r(   r)   r	  M  s    
z>TestInvoker.test_invoke_progressive_result_error.<locals>.bingr<   c                    s   ˆ   | j|f¡ d S r+   rð   rÒ   )Úlogged_errorsr(   r)   Ú	got_error[  s    zCTestInvoker.test_invoke_progressive_result_error.<locals>.got_errorc                    s   ˆ  d|¡ ˆ  | ¡ ˆ‚d S )Nr  )ro   r’   )rÌ   r  )Úgot_progressÚprogress_errorr%   r(   r)   r@   _  s    
zBTestInvoker.test_invoke_progressive_result_error.<locals>.progressr  rŒ   rÍ   rÌ   r  r  )r|   r  r°   r  r5   r   )NN)N)r
   r   r   r   r
  r×   rg   r   rÝ   rq   rŸ   ro   r”   r¼   rÏ   rJ   )r%   r&   r	  r  r@   r¡   r(   )r  r  r  r%   r)   Ú$test_invoke_progressive_result_errorH  s4    	
ý
üz0TestInvoker.test_invoke_progressive_result_errorc                 #   s~   t ƒ }t|ƒ td‡fdd„	ƒ}tƒ ‰ ‡ fdd„}| |dtjdd�¡V  |jdtj|d�d	�V }ˆ 	d
|¡ ˆ 
ˆ j¡ d S )Nc                 3   s<   ˆ   | d k	¡ ˆ   | jd k	¡ |  ¡  tdƒV  tdƒ d S )NTr°   ©r”   r@   r   r   ©rŒ   r,   r(   r)   r	  €  s
    
z@TestInvoker.test_invoke_progressive_result_no_args.<locals>.bingc                      s   ˆ   d¡ d S )Nzintentionally left blankr±   r(   ©r  r(   r)   r@   Š  s    zDTestInvoker.test_invoke_progressive_result_no_args.<locals>.progressr  rŒ   rÍ   r  r{   r°   )N)r
   r   r   r   rg   r   rÝ   rq   rŸ   ro   r”   r¼   ©r%   r&   r	  r@   r¡   r(   ©r  r%   r)   Ú&test_invoke_progressive_result_no_args{  s"    
ý
þz2TestInvoker.test_invoke_progressive_result_no_argsc                 #   sŽ   t ƒ }t|ƒ td‡fdd„	ƒ}tƒ ‰ d‡ fdd„	}| |dtjdd�¡V  |jdtj|d�d	�V }ˆ 	d
|¡ ˆ 
ˆ j¡ ˆ 	dˆ j¡ d S )Nc                 3   s@   ˆ   | d k	¡ ˆ   | jd k	¡ | jdd� tdƒV  tdƒ d S )Nr  ©r  Tr°   r   r!  r,   r(   r)   r	     s
    
zDTestInvoker.test_invoke_progressive_result_just_kwargs.<locals>.bingc                    s   ˆ   | ¡ d S r+   r±   r&  r"  r(   r)   r@   ª  s    zHTestInvoker.test_invoke_progressive_result_just_kwargs.<locals>.progressr  rŒ   rÍ   r  r{   r°   r  )N)N)r
   r   r   r   rg   r   rÝ   rq   rŸ   ro   r”   r¼   rÏ   r#  r(   r$  r)   Ú*test_invoke_progressive_result_just_kwargs›  s$    
ý
þz6TestInvoker.test_invoke_progressive_result_just_kwargsc              
   #   sž   t ƒ }t|ƒ tdƒ‰ ‡ fdd„}| |d¡V }z\z| d¡V  |  ¡  W n> tk
rˆ } z |  |t	¡ |  
| ¡ d¡ W 5 d }~X Y nX W 5 | ¡ V  X d S )Nza simple errorc                      s   ˆ ‚d S r+   r(   r(   ©ré   r(   r)   ÚraiserÂ  s    z<TestInvoker.test_call_exception_runtimeerror.<locals>.raiserúcom.myapp.myproc_errorz(wamp.error.runtime_error: a simple error)r
   r   rÖ   rg   rà   rq   r   r`   r£   r   ro   Úerror_message©r%   r&   r)  Zregistration0r�   r(   r(  r)   Ú test_call_exception_runtimeerror¼  s    &z,TestInvoker.test_call_exception_runtimeerrorc              
   #   sŒ   t ƒ }t|ƒ tƒ ‰ ‡ fdd„}| |d¡V }zLz| d¡V  |  ¡  W n. tk
rv } z|  |t¡ W 5 d }~X Y nX W 5 | ¡ V  X d S )Nc                      s   ˆ ‚d S r+   r(   r(   r(  r(   r)   r)  Õ  s    z4TestInvoker.test_call_exception_bare.<locals>.raiserr*  )	r
   r   r`   rg   rà   rq   r   r£   r   r,  r(   r(  r)   Útest_call_exception_bareÏ  s    "z$TestInvoker.test_call_exception_bareN)rZ   r[   r\   r   rý   r  r  r  r  r  r%  r'  r-  r.  r(   r(   r(   r)   rù   Å  s(   


!
 
"
2

 
rù   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestAuthenticatorc              	   C   sh   t t ¡ ƒ}tdddd�}tdddd�}| |¡ |  t¡�}| |¡ W 5 Q R X dt|jƒksdt	‚d S )NZwampcraZaliceZp4ssw0rd)ZauthidZsecretZbobZ
password42Zauthids)
r   rl   rm   r   Úadd_authenticatorræ   Ú
ValueErrorrè   ré   rÀ   )r%   rp   Úauth0Úauth1rë   r(   r(   r)   Útest_inconsistent_authidsó  s    ýý
z+TestAuthenticator.test_inconsistent_authidsc                 C   sd   t t ¡ ƒ}G dd„ dtƒ}|ƒ }dddœ|_i |_|ƒ }dddœ|_i |_| |¡ | |¡ d S )Nc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )zDTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticatorÚtestc                 S   s   t ‚d S r+   ©ÚNotImplementedError©r%   rp   Z	challenger(   r(   r)   Úon_challenge  s    zQTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticator.on_challengec                 S   s   t ‚d S r+   r6  ©r%   Ú	authextrar(   r(   r)   Ú
on_welcome  s    zOTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticator.on_welcomeN©rZ   r[   r\   Únamer9  r<  r(   r(   r(   r)   r/    s   r/  Úvalue0Úvalue1ry   Úwhat)r9   Zqux)r   rl   rm   r   r;  Ú_argsr0  )r%   rp   r/  r2  r3  r(   r(   r)   Útest_two_authenticators  s    
þþ
z)TestAuthenticator.test_two_authenticatorsc              	   C   sŠ   t t ¡ ƒ}G dd„ dtƒ}|ƒ }dddœ|_i |_|ƒ }ddi|_i |_| |¡ |  t¡�}| |¡ W 5 Q R X |  	dt
|jƒ¡ d S )Nc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )zHTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticatorr5  c                 S   s   t ‚d S r+   r6  r8  r(   r(   r)   r9  *  s    zUTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticator.on_challengec                 S   s   t ‚d S r+   r6  r:  r(   r(   r)   r<  -  s    zSTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticator.on_welcomeNr=  r(   r(   r(   r)   r/  &  s   r/  r?  r@  ry   r<   zInconsistent authextra)r   rl   rm   r   r;  rB  r0  ræ   r1  rç   rè   ré   )r%   rp   r/  r2  r3  rë   r(   r(   r)   Útest_inconsistent_authextra#  s     
þ ÿ
z-TestAuthenticator.test_inconsistent_authextraN)rZ   r[   r\   r4  rC  rD  r(   r(   r(   r)   r/  ñ  s   r/  )0ÚosZunittest.mockrl   ÚenvironÚgetZtwisted.internet.deferr   r   r   r   r   r   Ztwisted.trialr   rã   Úautobahnr	   Zautobahn.twisted.wampr
   r   Zautobahn.wampr   r   r   r   r   r   Zautobahn.wamp.requestr   Zautobahn.wamp.exceptionr   r   r   r   Zautobahn.wamp.authr   Zautobahn.wamp.interfacesr   Zautobahn.wamp.typesr   Úobjectr   ÚTestCaser]   rc   rv   rù   r/  r(   r(   r(   r)   Ú<module>   s6    |)   a  .