o
    h                     @   s  d dl Z d dlmZmZ d dlmZ d dlmZ d dlm	Z	 d dl
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mZ d dlmZ e
jdddge
jdddge
jdg ddd Zdd Ze
jdddge
jdejdfejdfgdd ZdS )    N)ANYpatch)get_user_model)AnonymousUser)reverse)assertTemplateUsed)"AUTHENTICATION_METHODS_SESSION_KEY)context)complete_social_login)SocialAccountSocialToken)AuthProcesswith_emailaddressFTauto_connectsetting)off	on-globalon-providerc
              
   C   s  d|_ d|_d|_dh|_d|_d|_d|_|dkrd|_n|dkr1t	|j
|_
d|j
d d< nd|_||_||	d	}
|
 sBJ ||
jd
dd}|d}t |_t|5 td!}td}t||}W d   n1 srw   Y  W d   n1 sw   Y  W d   n1 sw   Y  |
  |dkr|d tdksJ |jrJ |jrJ dS |	r|d dksJ |
 sJ n|
 rJ |d tdksJ t j dksJ tjj|
jd |ksJ tjj|
jd |ksJ |j|ksJ |jrJ dS )zyTests that when an already existing email is given at the social signup
    form, enumeration preventation kicks in.
    TFemail	mandatoryr   r   openid_connectEMAIL_AUTHENTICATION)r   unittest-server)r   provider
with_token/z9allauth.socialaccount.signals.social_account_updated.sendz7allauth.socialaccount.signals.social_account_added.sendNr   locationaccount_email_verification_sentz/accounts/profile/   )user)account__user) ACCOUNT_EMAIL_REQUIREDACCOUNT_UNIQUE_EMAILACCOUNT_USERNAME_REQUIREDACCOUNT_LOGIN_METHODSACCOUNT_EMAIL_VERIFICATIONSOCIALACCOUNT_AUTO_SIGNUPSOCIALACCOUNT_STORE_TOKENS"SOCIALACCOUNT_EMAIL_AUTHENTICATIONcopydeepcopySOCIALACCOUNT_PROVIDERS/SOCIALACCOUNT_EMAIL_AUTHENTICATION_AUTO_CONNECThas_usable_passwordr   getr   r   r	   request_contextr   r
   refresh_from_dbr   calledr   objectscountr   filterpkexistsr   )dbr   settingsuser_factorysociallogin_factoryclientrequest_factory
mailoutboxr   r   r   socialloginrequestupdated_signaladded_signalresp rC   a/var/www/html/env_mimamsha/lib/python3.10/site-packages/allauth/socialaccount/tests/test_login.pytest_email_authentication   sp   


rE   c                 C   s*   |  td}|jdksJ t|d d S )Nsocialaccount_login_cancelled   z"socialaccount/login_cancelled.html)r.   r   status_coder   )r;   rB   rC   rC   rD   test_login_cancelledc   s   rI   store_tokenszprocess,did_recordc	                 C   s   ||_ |ddd}	||	jd< t|	jjddd|	_tjj|ddd |	d}
t
 |
_t|
 t|
|	 W d    n1 s?w   Y  |rX|
jt t|	jjd	dd
gksWJ nt|
jvs_J tjjdddd |ksnJ d S )Nr   123)r   uidprocess456)apptokentoken_secret)r   rL   r   r   socialaccount)atr   methodrL   )account__uidrP   rQ   )r'   stater   r   rO   rP   r   r2   creater.   r   r   r	   r/   r
   sessionr   r   accountr4   r6   )r7   r:   r;   r<   r   rM   
did_recordrJ   r8   r>   r?   rC   rC   rD   test_record_authenticationi   s6   


	r[   )r)   unittest.mockr   r   django.contrib.authr   django.contrib.auth.modelsr   django.urlsr   pytestpytest_django.assertsr   allauth.account.authenticationr   allauth.corer	   allauth.socialaccount.helpersr
   allauth.socialaccount.modelsr   r   $allauth.socialaccount.providers.baser   markparametrizerE   rI   LOGINCONNECTr[   rC   rC   rC   rD   <module>   s2    N