U
    •uÄcT  ã                   @   sN   d dl Z d dlmZ d dlZd dlmZmZ d dlmZ G dd„ de j	ƒZ
dS )é    N)Úreplace_loop)ÚpatchÚMock)ÚApplicationRunnerc                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚTestApplicationRunnerzA
    Test the autobahn.asyncio.wamp.ApplicationRunner class.
    c                 O   sB   z
| j  W n tk
r$   | j}Y nX | j }|||f|ž|Ž d S )N)ÚassertRaisesRegexÚAttributeErrorÚassertRaisesRegexp)ÚselfÚ	exceptionÚerrorÚargsÚkwÚf© r   úqc:\users\psant\downloads\hotstarbackend\school\venv38\Lib\site-packages\autobahn\asyncio\test\test_wamp_runner.pyÚ_assertRaisesRegex(   s    
z(TestApplicationRunner._assertRaisesRegexc              
   C   s~   t tƒ ƒ�j}tjtd|d��N ttƒ tƒ fd�|_i }tdd|d�}| d¡ |  ||j	j
d d ¡ W 5 Q R X W 5 Q R X d	S )
zµ
        Ensure that loop.create_connection is called with the exact SSL
        context object that is passed (as ssl) to the __init__ method of
        ApplicationRunner.
        Úget_event_loop©Zreturn_valueúws://127.0.0.1:8080/wsÚrealm©ÚsslÚ_unused_é   r   N©r   r   r   ÚobjectÚasyncioÚrun_until_completer   ÚrunÚassertIsÚcreate_connectionÚ	call_args)r
   Úloopr   Úrunnerr   r   r   Útest_explicit_SSLContext1   s    ÿ
z.TestApplicationRunner.test_explicit_SSLContextc              
   C   sv   t tƒ ƒ�b}tjtd|d��F ttƒ tƒ fd�|_tddƒ}| d¡ |  d|j	j
d d ¡ W 5 Q R X W 5 Q R X d	S )
zÏ
        Ensure that loop.create_connection is called with ssl=False
        if no ssl argument is passed to the __init__ method of
        ApplicationRunner and the websocket URL starts with "ws:".
        r   r   r   r   r   Fr   r   Nr   ©r
   r#   r$   r   r   r   Ú test_omitted_SSLContext_insecure@   s    

z6TestApplicationRunner.test_omitted_SSLContext_insecurec              
   C   sx   t tƒ ƒ�d}tjtd|d��H ttƒ tƒ fd�|_tddƒ}| | j¡ |  	d|j
jd d ¡ W 5 Q R X W 5 Q R X dS )	zÏ
        Ensure that loop.create_connection is called with ssl=True
        if no ssl argument is passed to the __init__ method of
        ApplicationRunner and the websocket URL starts with "wss:".
        r   r   zwss://127.0.0.1:8080/wssr   Tr   r   N)r   r   r   r   r   r   r   r   Úfailr    r!   r"   r&   r   r   r   Útest_omitted_SSLContext_secureM   s    
z4TestApplicationRunner.test_omitted_SSLContext_securec              	   C   sR   t tƒ ƒ�>}ttƒ tƒ fd�|_tdddd�}d}|  t||jd¡ W 5 Q R X dS )	zw
        ApplicationRunner must raise an exception if given an ssl value of True
        but only a "ws:" URL.
        r   úws://127.0.0.1:8080/wssr   Tr   úƒ^ssl argument value passed to ApplicationRunner conflicts with the "ws:" prefix of the url argument\. Did you mean to use "wss:"\?$r   N)r   r   r   r   r   Ú	Exceptionr   )r
   r#   r$   r   r   r   r   Ú"test_conflict_SSL_True_with_ws_urlZ   s    ÿz8TestApplicationRunner.test_conflict_SSL_True_with_ws_urlc              	   C   s†   ddl }z
|j W n tk
r*   d}Y n
X | ¡ }ttƒ ƒ�>}ttƒ tƒ fd�|_tdd|d�}d}|  t||j	d	¡ W 5 Q R X dS )
z’
        ApplicationRunner must raise an exception if given an ssl value that is
        an instance of SSLContext, but only a "ws:" URL.
        r   NTr   r*   r   r   r+   r   )
r   Úcreate_default_contextr   r   r   r   r   r   r,   r   )r
   r   Úcontextr#   r$   r   r   r   r   Ú$test_conflict_SSLContext_with_ws_urlh   s    

ÿz:TestApplicationRunner.test_conflict_SSLContext_with_ws_urlN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r%   r'   r)   r-   r0   r   r   r   r   r   $   s   	r   )ÚunittestZtxaio.testutilr   r   Zunittest.mockr   r   Zautobahn.asyncio.wampr   ÚTestCaser   r   r   r   r   Ú<module>   s
   