o
    >hT                     @   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AttributeErrorassertRaisesRegexp)self	exceptionerrorargskwf r   /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/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    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.   r1   r   r   r   r   r   $   s    	r   )unittesttxaio.testutilr   r   unittest.mockr   r   autobahn.asyncio.wampr   TestCaser   r   r   r   r   <module>   s   