o
    >h                     @   sd  d dl Z d dlmZ e jddrd 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 dS )    N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)brokerdealer)_log_handlerr   JsonSerializer_serializer_registrations_invocations_subscription_topicsonOpenr
   id_my_session_idr   RoleBrokerFeaturesRoleDealerFeaturesr   Welcome	onMessager   _fake_router_sessionr   _transport_details)selfhandlerrolesmsg r2   /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/autobahn/wamp/test/test_wamp_protocol.py__init__2   s   

zMockTransport.__init__c                 C   s   | j S N)r-   r.   r2   r2   r3   transport_detailsG   s   zMockTransport.transport_detailsc                 C   s   | j td| d S )Nr   )r   r+   r   Unregistered)r.   reg_idr2   r2   r3   drop_registrationJ   s   
zMockTransport.drop_registrationc           	      C   s  | j r| j|\}}td| d }t|tjrW|j	dr0|j
r.t|j| jj }n4t|jdkrCttjj|jd}n!|j	drKnttjj|jd}nt|tjr|jdkrltj|jdgd	}n|jd
kr|tj|jg dd	}n|jdkrtj|jg ddddd}n|j	dr| j|j }| jj }|| jv rtd|j| j|< tj|||j|j|jd}nttjj|jd}nt|tjr|j| jv r| j|j }tj||j|j|jd}n{t|tjr|j}|| j v r| j | }n| jj }|| j |< t!|j|}nSt|tj"rt#|j}nEt|tj$r:| jj }|| j|j< t%|j|}n*t|tj&rHt'|j}nt|tjrd| j|j }tjtjj||j(|j|jd}|r| j rz| j|\}}td| | j)*| d S d S )Nz	Send: {0}z	com.myappr   zwamp.error.invalid_uriznoreply.zwamp.error.not_authorizedcom.myapp.procedure1d   argscom.myapp.procedure2         com.myapp.procedure3bar   foobazr>   kwargszcom.myapp.myproczduplicate invocation)r>   rK   receive_progresszwamp.error.no_such_procedure)r>   rK   progresszReceive: {0})+r   r!   	serializeprintformat
isinstancer   Publishtopic
startswithacknowledge	Publishedrequestr,   _request_id_gennextlenErrorMESSAGE_TYPECall	procedureResultr"   r#   r   
Invocationr>   rK   rL   YieldrM   	Subscriber$   
SubscribedUnsubscribeUnsubscribedRegister
Registered
Unregisterr8   errorr   r+   )	r.   r1   payloadisbinaryreplyregistrationrW   rS   reply_idr2   r2   r3   sendO   s   





zMockTransport.sendc                 C      dS NTr2   r6   r2   r2   r3   isOpen      zMockTransport.isOpenc                 C      d S r5   r2   r6   r2   r2   r3   close   rs   zMockTransport.closec                 C   rt   r5   r2   r6   r2   r2   r3   abort   rs   zMockTransport.abortN)
__name__
__module____qualname__r4   r7   r:   ro   rr   ru   rv   r2   r2   r2   r3   r   0   s    Tr   c                   @      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/   r2   r2   r3   test_server_abort   s   zTestClose.test_server_abortc                 C   s<   t  }t| tt }tdd|i |jd< |t  d S )NrA   rH   )r   r   r   	Exceptionr   
_call_reqsonLeaver   )r.   r/   deferredr2   r2   r3   test_reject_pending   s
   
zTestClose.test_reject_pendingN)rw   rx   ry   r}   r   r2   r2   r2   r3   r{      s    r{   c                   @   rz   )TestRegisterDecoratorc                 C      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   rt   r5   r2   r6   r2   r2   r3   some_method      z=TestRegisterDecorator.test_prefix.<locals>.Prefix.some_methodNrw   rx   ry   r   registerr   r2   r2   r2   r3   Prefix       r   zcom.example.prefix.prefixrA   r   ro   zcom.example.prefix.method_name
r   mockMock
_transportr   assertEqualrZ   
mock_calls	call_listr^   )r.   r   sessioncallregr2   r2   r3   test_prefix   s   
z!TestRegisterDecorator.test_prefixc                 C   r   )	Nc                   @   s   e Zd Zeddd ZdS )z3TestRegisterDecorator.test_auto_name.<locals>.MagicNc                 S   rt   r5   r2   r6   r2   r2   r3   r      r   z?TestRegisterDecorator.test_auto_name.<locals>.Magic.some_methodr   r2   r2   r2   r3   Magic   r   r   zcom.example.r   rA   r   ro   zcom.example.some_methodr   )r.   r   r   r   r   r2   r2   r3   test_auto_name   s   
z$TestRegisterDecorator.test_auto_nameN)rw   rx   ry   r   r   r2   r2   r2   r3   r      s    r   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g dddV }| |d  |jddddddtjdg ddddV }| |d  d S )Ncom.myapp.topic1rA   rB   rC   rF   hellorH   rE   F)
exclude_meoptionsr<      i,  )r   excluderH   rE   r   T)r   r   retain)r   r   publishr   r   PublishOptionsr.   r/   publicationr2   r2   r3   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 d S  tyG } z| d|j	 | d|j
 W Y d }~d S d }~ww )Nnoreply.fooTrU   r   testinghow are you?reasonr   )r   r   r   r   r   r   r   r   r   ri   r   )r.   r/   r   detailser2   r2   r3   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 d S  tyd } z| 	d|j | 	d|j W Y d }~d S d }~ww )Nr   Tr   r   c                    s    |   S r5   )append)r   error_d
got_errorsr2   r3   errback(  s   
zLTestPublisher.test_publish_outstanding_errors_async_errback.<locals>.errbackr   r   r   rA   )r   r   r   r   r   r   
addErrbackr   r   r   rZ   callbackr   ri   r   )r.   r/   publication_dr   r   r   r2   r   r3   -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g dddd
V }| t|jtk d S )Nr   Tr   r   rA   rB   rC   rF   r   r   F)r   rU   r   )r   r   rU   )	r   r   r   r   r   
assertTruetyper&   intr   r2   r2   r3   test_publish_acknowledgedA  s   "*z'TestPublisher.test_publish_acknowledgedc                 c   sP    t  }t| tjdd}| |jd|dtV  | |jd|dtV  d S NTr   zde.myapp.topic1r   foobar)r   r   r   r   assertFailurer   r   r.   r/   r   r2   r2   r3    test_publish_undefined_exceptionU  s   z.TestPublisher.test_publish_undefined_exceptionc                 c   sd    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   r2   r2   r3   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 )Nr;   r<   rA   rB   rC   rF   r   r   i'  )timeoutr   r   )r   r   r   r   r   CallOptionsr.   r/   resr2   r2   r3   	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 )Nr?   r@   rD   rE   rF   rG   )	r   r   r   assertIsInstancer   
CallResultr   results	kwresultsr   r2   r2   r3   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                  _      t d| | d S Nz	got eventrO   rJ   r2   r2   r3   on_event     z.TestPublisher.test_subscribe.<locals>.on_eventr   wildcardmatchr   T)r   get_retained)	r   r   	subscriber   r   r&   r   r   SubscribeOptionsr.   r/   r   subscriptionr2   r2   r3   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                      
     dS N*   r   r2   event0r2   r3   <lambda>     
 z5TestPublisher.test_double_subscribe.<locals>.<lambda>r   c                      r   NrH   r   r2   event1r2   r3   r     r   TFrU   r   r   Missing callback)r   r   r   r   r   r&   r   r   r   r+   r   Eventcalled)r.   r/   subscription0subscription1r   r2   )r   r   r3   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J t | S r5   )rQ   r   re   r   r+   r1   )r/   r2   r3   r+     s   zITestPublisher.test_double_subscribe_single_unsubscribe.<locals>.onMessagec                      r   r   r   r2   r   r2   r3   r     r   zHTestPublisher.test_double_subscribe_single_unsubscribe.<locals>.<lambda>r   c                      r   r   r   r2   r   r2   r3   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   r2   )r   r   r/   r3   (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sIJ j	dt
jddd	d
V }zt|j|j | d W n	 tyq   Y nw |  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 r5   )rQ   r   re   r   r   r+   r   )r/   unsubscribed_dr2   r3   r+     s   
zITestPublisher.test_double_subscribe_double_unsubscribe.<locals>.onMessagec                      r   r   r   r2   r   r2   r3   r     r   zHTestPublisher.test_double_subscribe_double_unsubscribe.<locals>.<lambda>r   c                      r   r   r   r2   r   r2   r3   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   r2   )r   r   r/   r   r3   (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|v   t|d tj  |  d S )Nboom)r   rQ   r   EventDetailsr   )r>   kw)r   r.   r2   r3   second)  s   z:TestPublisher.test_double_subscribe_errors.<locals>.secondc                    s
     | S r5   r   argr   r2   r3   r   1  r   z<TestPublisher.test_double_subscribe_errors.<locals>.<lambda>r   r   details_argTFr   r   arg0r=   )r  N)r   r   r   r   r   r   r   r&   r   r   r+   r   r   r   r   result)r.   r/   r   r   r   r   r2   )r   r   r.   r3   test_double_subscribe_errors  s2   
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 d S rq   )valuer   r   r1   error_instance	got_err_dr2   r3   observerW  s   
z?TestPublisher.test_publish_callback_exception.<locals>.observerc                          r5   r2   r2   )r  r2   r3   r   \  rs   z;TestPublisher.test_publish_callback_exception.<locals>.boomr   TFr   r   N)r   r   RuntimeErrorr   onUserErrorr   r   r   r   r   r   r&   r+   r   r   )r.   r/   r
  r   subr   r1   r2   r  r3   test_publish_callback_exceptionL  s    
z-TestPublisher.test_publish_callback_exceptionc                 c   4    t  }t| dd }||dV }| V  d S )Nc                  _   r   r   r   rJ   r2   r2   r3   r   s  r   z0TestPublisher.test_unsubscribe.<locals>.on_eventr   )r   r   r   r   r   r2   r2   r3   test_unsubscriben     zTestPublisher.test_unsubscribec                 c   sl    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                  _   r   Nzgot callr   rJ   r2   r2   r3   on_call~  r   z,TestPublisher.test_register.<locals>.on_callr;   r   r   r   )	r   r   r   r   r   r&   r   r   RegisterOptionsr.   r/   r  rm   r2   r2   r3   test_registery  s   zTestPublisher.test_registerc                 c   r  )Nc                  _   r   r  r   rJ   r2   r2   r3   r    r   z.TestPublisher.test_unregister.<locals>.on_callr;   )r   r   r   
unregisterr  r2   r2   r3   test_unregister  r  zTestPublisher.test_unregisterc                 C   sp   t jjdk rd S t }t|}| t}|t	dd W d    n1 s(w   Y  | 
dt|j d S )N   r   i  z3UNREGISTERED received for non-existant registration)twistedversionmajorr   r   assertRaisesr   ro   r   rh   assertInstr	exception)r.   r/   	transportctxr2   r2   r3   $test_unregister_no_such_registration  s   
z2TestPublisher.test_unregister_no_such_registrationc                 #   sL    t  }t|} fdd d _| dV }||j |  j d S )Nc                     s
   d _ d S rq   )r   rJ   r  r2   r3   r    s   
z2TestPublisher.test_unregister_log.<locals>.on_callFr;   )r   r   r   r   r:   r&   assertFalse)r.   r/   r"  rm   r2   r%  r3   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 r5   r   r  )r.   r   r1   errorsr2   r3   r       zCTestPublisher.test_on_disconnect_error.<locals>.AppSess.onUserErrorsnarkc                 S   s   t d)NzThis shouldn't happen)r  )r.   rH   rE   quuxr2   r2   r3   onDisconnect  s   zDTestPublisher.test_on_disconnect_error.<locals>.AppSess.onDisconnectN)r,  )rw   rx   ry   r  r.  r2   r)  r2   r3   AppSess  s    r/  FrA   r   )r   r   r|   r   rZ   r   rQ   	TypeError)r.   r/  sr2   r)  r3   test_on_disconnect_error  s   
z&TestPublisher.test_on_disconnect_errorN)rw   rx   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r$  r'  r2  r2   r2   r2   r3   r      sN    


(

	





*
4
/
!





r   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   sB    t  }t| dd }||dV  |dV }| |d d S )Nc                   S   rp   NrF   r2   r2   r2   r2   r3   myproc1  rs   z(TestInvoker.test_invoke.<locals>.myproc1com.myapp.myproc1rF   )r   r   r   r   r   )r.   r/   r5  r   r2   r2   r3   test_invoke  s   zTestInvoker.test_invokec                 c   s\    t  }t| dd }||dV  |d}|d}t||gV }| |ddg d S )Nc                   S   rp   r4  r2   r2   r2   r2   r3   r5    rs   z.TestInvoker.test_invoke_twice.<locals>.myproc1r6  TrF   )r   r   r   r   r   r   )r.   r/   r5  d0d1r   r2   r2   r3   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                    sD   t |tjr |jd | |S t |tjr |jd | |S )NrA   rB   )rQ   r   rf   r   rW   r]   )origr1   r6   r2   r3   verify_seq_id  s   zCTestInvoker.test_invoke_request_id_sequences.<locals>.verify_seq_idc                    
    | S r5   r2   r   )orig0r=  r2   r3   r     r   z>TestInvoker.test_invoke_request_id_sequences.<locals>.<lambda>c                    r>  r5   r2   r   )orig1r=  r2   r3   r     r   c                   S   rp   r4  r2   r2   r2   r2   r3   r5    rs   z=TestInvoker.test_invoke_request_id_sequences.<locals>.myproc1r6  r8  N)r   r   ro   r   r   r   r   )	r.   handler0handler1trans0trans1r5  r9  r:  r   r2   )r?  r@  r.   r=  r3    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 n tyN } z| 	t
|t W Y d }~nd }~ww | d	t  |  d
 d
  d S )NTc                         | j|f d S r5   r(  r  r)  r2   r3   	log_error  r+  z6TestInvoker.test_invoke_user_raises.<locals>.log_errorrH   c                      r  r5   r2   r2   )
name_errorr2   r3   bing  rs   z1TestInvoker.test_invoke_user_raises.<locals>.bingzcom.myapp.myproc99zExpected an errorrA   r   )r   traceback_appr   r  	NameErrorr   r   r   r~   r   rQ   r  r   rZ   )r.   r/   rG  rI  r   r2   )r*  rH  r3   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 qDd S )Nc                 3   sN      | d u   | jd u tdD ]}| | t|V  qtd d S )N
   r   )r   rM   ranger   r   )r   ir6   r2   r3   rI  *  s   
z8TestInvoker.test_invoke_progressive_result.<locals>.bingc                 S   s   t  S r5   )r   )_r2   r2   r3   r   3  s    z<TestInvoker.test_invoke_progressive_result.<locals>.<lambda>rM  c                    s    |   |  d S r5   r   r   )progressiver2   r3   rM   5  s   z<TestInvoker.test_invoke_progressive_result.<locals>.progresscom.myapp.myproc2r   r   on_progressr   r   r5   )r   r   r   listmaprN  r   r   r  r   r   r   r   r   r  )r.   r/   rI  rM   r   rO  r2   )rQ  r.   r3   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   s\      |d u   |jd u  |d  d|  |jddd tdV  td d S )Nwordr   lifenothing)	somethingz
meaning ofr   )r   rM   r   r   r   )r   r   keyr6   r2   r3   rI  M  s   
z>TestInvoker.test_invoke_progressive_result_error.<locals>.bingrH   c                    rF  r5   r(  r  )logged_errorsr2   r3   	got_error[  r+  zCTestInvoker.test_invoke_progressive_result_error.<locals>.got_errorc                    s    d|  |  )NrZ  )r   r   )r   r[  )got_progressprogress_errorr.   r2   r3   rM   _  s   
zBTestInvoker.test_invoke_progressive_result_error.<locals>.progressrR  r   r   r   rS  rX  )r   r\  r   rY  rA   r   )NNr5   )r   r   r   r   rK  r  r   r   r  r   r   r   r   r   r  rZ   )r.   r/   rI  r^  rM   r   r2   )r_  r]  r`  r.   r3   $test_invoke_progressive_result_errorH  s6   	

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 u   | jd u |   tdV  td d S )NTr   r   rM   r   r   r   r6   r2   r3   rI    s   
z@TestInvoker.test_invoke_progressive_result_no_args.<locals>.bingc                      s     d d S )Nzintentionally left blankr   r2   r_  r2   r3   rM        zDTestInvoker.test_invoke_progressive_result_no_args.<locals>.progressrR  r   r   rS  r   r   r5   )r   r   r   r   r   r   r  r   r   r   r   r   r.   r/   rI  rM   r   r2   r_  r.   r3   &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   sB      | d u   | jd u | jdd tdV  td d S )NrX  r\  Tr   rb  rc  r6   r2   r3   rI    s   
zDTestInvoker.test_invoke_progressive_result_just_kwargs.<locals>.bingc                    s     |  d S r5   r   ri  rd  r2   r3   rM     re  zHTestInvoker.test_invoke_progressive_result_just_kwargs.<locals>.progressrR  r   r   rS  r   r   rX  r5   )r   r   r   r   r   r   r  r   r   r   r   r   r  rf  r2   rg  r3   *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yF } z| |t | 	|
 d W Y d }~nd }~ww W | V  d S W | V  d S | V  w )Nza simple errorc                      r  r5   r2   r2   r!  r2   r3   raiser  rs   z<TestInvoker.test_call_exception_runtimeerror.<locals>.raisercom.myapp.myproc_errorz(wamp.error.runtime_error: a simple error)r   r   r  r   r   r   r~   r   r   r   error_messager  r.   r/   rl  registration0r   r2   rk  r3    test_call_exception_runtimeerror  s$   z,TestInvoker.test_call_exception_runtimeerrorc              
   #   s    t  }t| t   fdd}||dV }z5z|dV  |   W n ty= } z| |t W Y d }~nd }~ww W | V  d S W | V  d S | V  w )Nc                      r  r5   r2   r2   rk  r2   r3   rl    rs   z4TestInvoker.test_call_exception_bare.<locals>.raiserrm  )	r   r   r~   r   r   r   r   r   r  ro  r2   rk  r3   test_call_exception_bare  s"   z$TestInvoker.test_call_exception_bareN)rw   rx   ry   r   r7  r;  rE  rL  rW  ra  rh  rj  rq  rr  r2   r2   r2   r3   r3    s*    


!
 
"
2

 
r3  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestAuthenticatorc                 C   s|   t t }tdddd}tdddd}|| | t}|| W d    n1 s.w   Y  dt|jv s<J d S )Nwampcraalicep4ssw0rd)authidsecretbob
password42authids)	r   r   r   r   add_authenticatorr  
ValueErrorr   r!  )r.   r   auth0auth1r#  r2   r2   r3   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                   @       e Zd ZdZdd Zdd ZdS )zDTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticatortestc                 S      t r5   NotImplementedErrorr.   r   	challenger2   r2   r3   on_challenge  rs   zQTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticator.on_challengec                 S   r  r5   r  r.   	authextrar2   r2   r3   
on_welcome  rs   zOTestAuthenticator.test_two_authenticators.<locals>.TestAuthenticator.on_welcomeNrw   rx   ry   namer  r  r2   r2   r2   r3   rs        rs  value0value1r   what)rE   qux)r   r   r   r   r  _argsr|  )r.   r   rs  r~  r  r2   r2   r3   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 d    n1 s?w   Y  | 	dt
|j d S )Nc                   @   r  )zHTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticatorr  c                 S   r  r5   r  r  r2   r2   r3   r  *  rs   zUTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticator.on_challengec                 S   r  r5   r  r  r2   r2   r3   r  -  rs   zSTestAuthenticator.test_inconsistent_authextra.<locals>.TestAuthenticator.on_welcomeNr  r2   r2   r2   r3   rs  &  r  rs  r  r  r   rH   zInconsistent authextra)r   r   r   r   r  r  r|  r  r}  r  r   r!  )r.   r   rs  r~  r  r#  r2   r2   r3   test_inconsistent_authextra#  s    

z-TestAuthenticator.test_inconsistent_authextraN)rw   rx   ry   r  r  r  r2   r2   r2   r3   rs    s    rs  )0osunittest.mockr   environgettwisted.internet.deferr   r   r   r   r   r   twisted.trialr	   r  autobahnr
   autobahn.twisted.wampr   r   autobahn.wampr   r   r   r   r   r   autobahn.wamp.requestr   autobahn.wamp.exceptionr   r   r   r   autobahn.wamp.authr   autobahn.wamp.interfacesr   autobahn.wamp.typesr   objectr   TestCaser{   r   r   r3  rs  r2   r2   r2   r3   <module>   sH    |)   a  .       