U
    e»{jY  ã                   @   sŒ   d Z ddlZddlmZmZ ddlZddlmZ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mZ d
d„ ZG dd„ deƒZdS )zï
Test the web profile using Python classes that have been adapted to act like a
web client. We can only put a single test here because only one hub can run
with the web profile active, and the user might want to run the tests in
parallel.
é    N)ÚRequestÚurlopen)ÚSAMPHubServerÚSAMPIntegratedClientÚconf)ÚCLIENT_ACCESS_POLICYÚCROSS_DOMAIN)Úget_readable_fileobjé   )ÚTestStandardProfile)ÚAlwaysApproveWebProfileDialogÚSAMPIntegratedWebClientc                 C   s
   dt _d S )NF)r   Zuse_internet)Úmodule© r   úb/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/samp/tests/test_web_profile.pyÚsetup_module   s    r   c                   @   s0   e Zd Zejdd�dd„ ƒZdd„ Zdd„ Zd	S )
ÚTestWebProfileT)Zautousec                 C   s¾   t ƒ | _tj| jjd�}| ¡  t|ƒ| _t|d ƒ}t| j|ddd�| _	| j	 ¡  t
ƒ | _| jj| j	dd� | j ¡ | _| j ¡ | _tƒ | _| jj| j	jdd� | j ¡ | _| j ¡ | _d S )	N)Útargetz.sampr   r
   )Zweb_profile_dialogÚlockfileÚweb_portÚ	pool_size)Úhubr   é   )r   r   )r   ÚdialogÚ	threadingÚThreadÚpollÚstartÚstrZtmpdirr   r   r   Úclient1ÚconnectZget_public_idZ
client1_idZget_private_keyZclient1_keyr   Úclient2Ú	_web_portZ
client2_idZclient2_key)ÚselfZtmp_pathÚtr   r   r   r   Úsetup_method   s(    
   ÿ
zTestWebProfile.setup_methodc                 C   s<   | j jr| j  ¡  | jjr$| j ¡  | j ¡  | j ¡  d S )N)r   Zis_connectedZ
disconnectr!   r   Ústopr   )r#   r   r   r   Úteardown_method4   s    


zTestWebProfile.teardown_methodc              	   C   sÂ   t d| jj› d�ƒ�}| ¡ tks&t‚W 5 Q R X t d| jj› d�ƒ�}| ¡ tksVt‚W 5 Q R X td| jj› d�ƒ}| dd¡ t	|ƒ}| 
d¡dksšt‚| 
d¡dks¬t‚| 
d	¡d
ks¾t‚d S )Nzhttp://localhost:z/crossdomain.xmlz/clientaccesspolicy.xmlZOriginÚtest_web_profilezAccess-Control-Allow-OriginzAccess-Control-Allow-HeaderszContent-Typez Access-Control-Allow-CredentialsÚtrue)r	   r   r"   Úreadr   ÚAssertionErrorr   r   Ú
add_headerr   Ú	getheader)r#   ÚfÚreqÚrespr   r   r   r(   @   s     ÿÿzTestWebProfile.test_web_profileN)Ú__name__Ú
__module__Ú__qualname__ÚpytestZfixturer%   r'   r(   r   r   r   r   r      s   

r   )Ú__doc__r   Úurllib.requestr   r   r4   Zastropy.sampr   r   r   Zastropy.samp.web_profiler   r   Zastropy.utils.datar	   Ztest_standard_profiler   ZBaseTestStandardProfileZweb_profile_test_helpersr   r   r   r   r   r   r   r   Ú<module>   s   