o
    gëf	  ã                   @   sÔ   d dl Z zd dlZW n ey)   zd dlZW n ey&   d dlmZ Y nw Y nw d dlmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZ G d	d
„ d
eƒZG dd„ deƒZG dd„ de
ƒZdS )é    N)Ú
simplejson)Úsettings)ÚAnonymousUser)ÚClientÚRequestFactory)Úimport_module)Úpatch)Úcompletec                   @   s"   e Zd ZdZddd„Zdd„ ZdS )ÚDumbResponsez4
    Response from a call to, urllib2.urlopen()
    Nc                 C   s   || _ || _d S ©N)Údata_strÚurl)Úselfr   r   © r   úY/var/www/html/humari/django-venv/lib/python3.10/site-packages/social_auth/tests/client.pyÚ__init__   s   
zDumbResponse.__init__c                 C   s   | j S r   )r   )r   r   r   r   Úread   s   zDumbResponse.readr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r
      s    
r
   c                   @   s   e Zd ZdZdS )ÚNoBackendErrorzF
    Used when a client attempts to login with a invalid backend.
    N)r   r   r   r   r   r   r   r   r      s    r   c                   @   s*   e Zd ZdZedƒedƒddd„ƒƒZdS )	ÚSocialClientzw
    Test client to login/register a user
    Does so by mocking api posts/responses.

    Only supports facebook.
    z2social_auth.backends.facebook.FacebookAuth.enabledzsocial_auth.utils.urlopenÚfacebookc              
   C   sD  d}t  |ddœ¡t |¡ft |dddœ¡t |¡ft  ||ddddœ¡t  ||ddd	œ¡d
jdi |¤Žfdœ}||vrCtd| ƒ‚	 dd„ || D ƒ|_d|_tƒ }| 	ddddœ¡}t
tjƒ}	| jrj| j|_n|	 ¡ |_tƒ |_d|jd< t||ƒ}
|j ¡  tj}|jj| j|< ddtjtjp”dddœ}| j|  |¡ dS )a
  
        Login or Register a facebook user.

        If the user has never logged in then they get registered and logged in.
        If the user has already registered, then they are logged in.

        user: dict
        backend: 'facebook'

        example user:
        {
            'first_name': 'Django',
            'last_name': 'Reinhardt',
            'verified': True,
            'name': 'Django Reinhardt',
            'locale': 'en_US',
            'hometown': {
                'id': '12345678',
                'name': 'Any Town, Any State'
            },
            'expires': '4812',
            'updated_time': '2012-01-29T19:27:32+0000',
            'access_token': 'dummyToken',
            'link': 'http://www.facebook.com/profile.php?id=1234',
            'location': {
                'id': '108659242498155',
                'name': 'Chicago, Illinois'
            },
            'gender': 'male',
            'timezone': -6,
            'id': '1234',
            'email': 'user@domain.com'
        }
        Ú
dummyTokeni  )Úaccess_tokenÚexpiresÚBearer)r   Ú
token_typeÚ
expires_inÚtruez,https://api.linkedin.com/uas/oauth/authorize)Úoauth_tokenÚoauth_token_secretÚoauth_callback_confirmedÚxoauth_request_auth_urlÚoauth_expires_in)r!   r"   r%   Úoauth_authorization_expires_inzÑ<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<person>
  <id>{id}</id>
  <email-address>{email}</email-address>
  <first-name>{first_name}</first-name>
  <last-name>{last_name}</last-name>
</person>
)r   ÚgoogleÚlinkedinz%s is not supportedc                 S   s   g | ]}t |ƒ‘qS r   )r
   )Ú.0Úrr   r   r   Ú
<listcomp>†   s    ÿz&SocialClient.login.<locals>.<listcomp>TÚ Údummy)ÚcodeÚredirect_stateÚfacebook_stateNú/)zmax-ageÚpathÚdomainÚsecurer   r   )ÚurllibÚ	urlencoder   ÚdumpsÚformatr   Úside_effectÚreturn_valuer   Úpostr   r   ÚSESSION_ENGINEÚsessionÚSessionStorer   Úuserr	   ÚsaveÚSESSION_COOKIE_NAMEÚsession_keyÚcookiesÚSESSION_COOKIE_DOMAINÚSESSION_COOKIE_SECUREÚupdate)r   r?   Úmock_urlopenÚmock_facebook_enabledÚbackendÚtokenÚbackendsÚfactoryÚrequestÚengineÚredirectÚsession_cookieÚcookie_datar   r   r   Úlogin.   s~   &þû	ýú
úüúúñî+ÿÿ





ûzSocialClient.loginN)r   )r   r   r   r   r   rR   r   r   r   r   r   &   s
    r   )r5   Újsonr   ÚImportErrorÚdjango.utilsÚdjango.confr   Údjango.contrib.auth.modelsr   Údjango.test.clientr   r   Údjango.utils.importlibr   Úmockr   Úsocial_auth.viewsr	   Úobjectr
   Ú	Exceptionr   r   r   r   r   r   Ú<module>   s(    ÿ€ý