o
    èó·iT  ã                   @   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   sF   z| j  W n ty   | j}Y nw | j }|||g|¢R i |¤Ž d S )N)ÚassertRaisesRegexÚAttributeErrorZassertRaisesRegexp)ÚselfÚ	exceptionÚerrorÚargsÚkwÚf© r   úlC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\autobahn/asyncio/test/test_wamp_runner.pyÚ_assertRaisesRegex(   s   

ÿz(TestApplicationRunner._assertRaisesRegexc              	   C   s¸   t tƒ ƒ�M}tjtd|d��, ttƒ tƒ fd�|_i }tdd|d�}| d¡ |  ||j	j
d d ¡ W d	  ƒ n1 s=w   Y  W d	  ƒ d	S W d	  ƒ d	S 1 sUw   Y  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©Ú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   s°   t tƒ ƒ�I}tjtd|d��( ttƒ tƒ fd�|_tddƒ}| d¡ |  d|j	j
d d ¡ W d	  ƒ n1 s9w   Y  W d	  ƒ d	S W d	  ƒ d	S 1 sQw   Y  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   s²   t tƒ ƒ�J}tjtd|d��) ttƒ tƒ fd�|_tddƒ}| | j¡ |  	d|j
jd d ¡ W d  ƒ n1 s:w   Y  W d  ƒ dS W d  ƒ dS 1 sRw   Y  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   Zfailr    r!   r"   r&   r   r   r   Útest_omitted_SSLContext_secureM   s   
üÿ"ÿz4TestApplicationRunner.test_omitted_SSLContext_securec                 C   sh   t tƒ ƒ�%}ttƒ tƒ fd�|_tdddd�}d}|  t||jd¡ W d  ƒ dS 1 s-w   Y  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y   d}Y nw | ¡ }ttƒ ƒ�%}ttƒ tƒ fd�|_tdd|d�}d}|  t||j	d	¡ W d  ƒ dS 1 sFw   Y  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,   r/   r   r   r   r   r   $   s    	r   )ZunittestZtxaio.testutilr   r   Zunittest.mockr   r   Zautobahn.asyncio.wampr   ZTestCaser   r   r   r   r   Ú<module>   s   