U
    ^~Hj(
  ã                   @   s|   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d	d
„ ZG dd„ deƒZdS )é    )Úpartial)ÚDaphneProcess)ÚASGIStaticFilesHandler)ÚImproperlyConfigured)Úconnections)ÚTransactionTestCase)Úmodify_settings©Úget_default_applicationc                 C   s   t ƒ }| d k	r| |ƒ}|S ©Nr	   )Ústatic_wrapperZapplication© r   ú9/tmp/pip-unpacked-wheel-a46u9ts2/channels/testing/live.pyÚmake_application   s    r   c                       s\   e Zd ZdZdZeZeZdZ	e
dd„ ƒZe
dd„ ƒZ‡ fdd	„Z‡ fd
d„Zdd„ Z‡  ZS )ÚChannelsLiveServerTestCasezì
    Does basically the same as TransactionTestCase but also launches a
    live Daphne server in a separate process, so
    that the tests may use another test framework, such as Selenium,
    instead of the built-in dummy client.
    Ú	localhostTc                 C   s   d| j | jf S )Nzhttp://%s:%s©ÚhostÚ_port©Úselfr   r   r   Úlive_server_url"   s    z*ChannelsLiveServerTestCase.live_server_urlc                 C   s   d| j | jf S )Nz
ws://%s:%sr   r   r   r   r   Úlive_server_ws_url&   s    z-ChannelsLiveServerTestCase.live_server_ws_urlc                    s˜   t  ¡ D ]}|  |¡rtdƒ‚qtt| ƒ ¡  td| jid�| _	| j	 
¡  tt| jrZ| jnd d�}|  | j|¡| _| j ¡  | jj ¡  | jjj| _d S )NzBChannelLiveServerTestCase can not be used with in memory databasesÚappend)ZALLOWED_HOSTS)r   )r   ÚallÚ_is_in_memory_dbr   Úsuperr   Ú
_pre_setupr   r   Ú_live_server_modified_settingsÚenabler   r   Úserve_staticr   ÚProtocolServerProcessÚ_server_processÚstartÚreadyÚwaitÚportÚvaluer   )r   Ú
connectionZget_application©Ú	__class__r   r   r   *   s$    
ÿÿ
þ
z%ChannelsLiveServerTestCase._pre_setupc                    s0   | j  ¡  | j  ¡  | j ¡  tt| ƒ ¡  d S r   )r"   Ú	terminateÚjoinr   Údisabler   r   Ú_post_teardownr   r)   r   r   r.   A   s    


z)ChannelsLiveServerTestCase._post_teardownc                 C   s   |j dkr| ¡ S dS )zD
        Check if DatabaseWrapper holds in memory database.
        ZsqliteN)ÚvendorZis_in_memory_db)r   r(   r   r   r   r   G   s    
z+ChannelsLiveServerTestCase._is_in_memory_db)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r!   r   r   r    Úpropertyr   r   r   r.   r   Ú__classcell__r   r   r)   r   r      s   

r   N)Ú	functoolsr   Zdaphne.testingr   Z#django.contrib.staticfiles.handlersr   Zdjango.core.exceptionsr   Z	django.dbr   Zdjango.test.testcasesr   Zdjango.test.utilsr   Zchannels.routingr
   r   r   r   r   r   r   Ú<module>   s   