U
    {h                     @   sT  d dl 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	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZmZmZ d d
lm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# G dd de!eZ$G dd dZ%G dd de!ee%Z&G dd de!ee%Z'G dd de!eZ(G dd de!ee%Z)G dd de!eZ*dS )    N)settings)get_user_model)views)Group
Permission)PasswordResetTokenGenerator)mail)SimpleUploadedFile)RequestFactoryTestCaseoverride_settings)reverse)WAGTAILADMIN_PROVIDED_LANGUAGESget_available_admin_languagesget_available_admin_time_zones)AccountViewprofile_tab)get_test_image_file)WagtailTestUtils)UserProfilec                   @   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d Z
dd Zdd Zdd ZdS )TestAuthenticationzK
    This tests that users can login and logout of the admin interface
    c                 C   s.   | j td}| |jd | |d dS )zK
        This tests that the login view responds with a login page
        wagtailadmin_login   wagtailadmin/login.htmlNclientgetr   assertEqualstatus_codeassertTemplateUsedselfresponse r#   s/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/admin/tests/test_account_management.pytest_login_view   s    z"TestAuthentication.test_login_viewc                 C   s   | j dddd | jtdtjdkr*dnddtdd}| |td | d	| jj | 	t
| jjd	 t
t jjdd
j dS )z{
        This posts user credentials to the login view and checks that
        the user was logged in successfully
        testtest@email.compasswordusernameemailr(   r   zemailuser.EmailUserwagtailadmin_home)r*   r(   next_auth_user_idr+   N)create_superuserr   postr   r   ZAUTH_USER_MODELassertRedirectsassertInsessionr   strr   objectsr   pkr    r#   r#   r$   test_login_view_post)   s(      z'TestAuthentication.test_login_view_postc                 C   s,   |    | jtd}| |td dS )z
        This tests that a user who is already logged in is automatically
        redirected to the admin dashboard if they try to access the login
        page
        r   r,   N)loginr   r   r   r2   r    r#   r#   r$   test_already_logged_in_redirectJ   s    z2TestAuthentication.test_already_logged_in_redirectc                 C   sJ   | j ddd | jddd | jtd}| |jd | |d dS )z
        This tests that if the user is logged in but hasn't got permission
        to access the admin, they are not redirected to the admin

        This tests issue #431
        unprivileged123r*   r(   r   r   r   N)create_userr9   r   r   r   r   r   r   r    r#   r#   r$   5test_logged_in_as_non_privileged_user_doesnt_redirectY   s
    zHTestAuthentication.test_logged_in_as_non_privileged_user_doesnt_redirectc                 C   s<   |    | jtd}| |td | d| jj dS )z5
        This tests that the user can logout
        Zwagtailadmin_logoutr   r.   N)r9   r   r1   r   r2   assertNotInr4   r    r#   r#   r$   test_logoutk   s    zTestAuthentication.test_logoutc                 C   s0   | j td}| |tdd td  dS )z^
        This tests that a not logged in user is redirected to the
        login page
        r,   r   ?next=N)r   r   r   r2   r    r#   r#   r$   test_not_logged_in_redirect{   s
    z.TestAuthentication.test_not_logged_in_redirectc                 C   s&   | j jtddd}| |jd dS )z\
        This tests that a not logged in user is given a 403 error on AJAX requests
        r,   XMLHttpRequestZHTTP_X_REQUESTED_WITH  N)r   r   r   r   r   r    r#   r#   r$   -test_not_logged_in_gives_403_to_ajax_requests   s
     z@TestAuthentication.test_not_logged_in_gives_403_to_ajax_requestsc              	   C   sV   | j dd | jtd}W 5 Q R X | |jd | |tdd td  dS )z
        This does the same as the above test but checks that it
        redirects to the correct place when the user has not set
        the LOGIN_URL setting correctly
        zdjango.contrib.auth.views.login)Z	LOGIN_URLr,   i.  r   rB   N)r   r   r   r   r   r   r2   r    r#   r#   r$   ,test_not_logged_in_redirect_default_settings   s    z?TestAuthentication.test_not_logged_in_redirect_default_settingsc                 C   s\   | j ddd | jddd | jjtddd}| |tdd td  | |d	 d
S )z
        This tests that a logged in user without admin access permissions is
        redirected to the login page, with an error message
        r;   r<   r=   r,   T)followr   rB   z.You do not have permission to access the adminN)r>   r9   r   r   r   r2   assertContainsr    r#   r#   r$   %test_logged_in_no_permission_redirect   s    z8TestAuthentication.test_logged_in_no_permission_redirectc                 C   sB   | j ddd | jddd | jjtddd}| |jd dS )	z
        This tests that a logged in user without admin access permissions is
        given a 403 error on ajax requests
        r;   r<   r=   r,   rD   rE   rF   N)r>   r9   r   r   r   r   r   r    r#   r#   r$   7test_logged_in_no_permission_gives_403_to_ajax_requests   s     zJTestAuthentication.test_logged_in_no_permission_gives_403_to_ajax_requestsN)__name__
__module____qualname____doc__r%   r8   r:   r?   rA   rC   rG   rH   rK   rL   r#   r#   r#   r$   r      s   !r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestAccountSectionUtilsMixinc                 C   s.   dd |j d  D }| ||d|  d S )Nc                 S   s   h | ]}|D ]
}|j qqS r#   name.0panelsetpanelr#   r#   r$   	<setcomp>   s    zATestAccountSectionUtilsMixin.assertPanelActive.<locals>.<setcomp>panels_by_tabzPanel %s not active in response)contextvaluesr3   r!   r"   rS   Zpanelsr#   r#   r$   assertPanelActive   s    z.TestAccountSectionUtilsMixin.assertPanelActivec                 C   s.   dd |j d  D }| ||d|  d S )Nc                 S   s   h | ]}|D ]
}|j qqS r#   rR   rT   r#   r#   r$   rX      s    zDTestAccountSectionUtilsMixin.assertPanelNotActive.<locals>.<setcomp>rY   zPanel %s active in response)rZ   r[   r@   r\   r#   r#   r$   assertPanelNotActive   s    z1TestAccountSectionUtilsMixin.assertPanelNotActivec                 C   s<   dd| j jddddddddd	}|| | jtd
|S )NZTestZUserfalsetrueesEurope/LondonZdarkdefault)name_email-first_namename_email-last_namename_email-emailz%notifications-submitted_notificationsz$notifications-approved_notificationsz$notifications-rejected_notificationsz,notifications-updated_comments_notificationslocale-preferred_languagelocale-current_time_zonetheme-themetheme-densitywagtailadmin_account)userr+   updater   r1   r   )r!   Zextra_post_data	post_datar#   r#   r$   	post_form   s    
z&TestAccountSectionUtilsMixin.post_formN)rM   rN   rO   r]   r^   ro   r#   r#   r#   r$   rQ      s   rQ   c                   @   s  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	dddd Z
e	dddd Ze	dddd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Ze	d#d$gd%d&d' Zd(d) Ze	d#gd%d*d+ Zeejd,d-d. Zeejd,d/d0 Zeejd,e	d1d2gd3d4d5 Zeejd,d6d7 Zeejd,e	d8gd3d9d: Ze ejd;d<d= Z!eejd,e	d8gd#gd>d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGS )HTestAccountSectionz9
    This tests that the accounts section is working
    c                 C   s   |   | _d S N)r9   rl   r!   r#   r#   r$   setUp   s    zTestAccountSection.setUpc                 C   s   | j td}| |jd | |d | |d | |d | |d | |d | |d | |d	 | |d
 tj	r| |d n| 
|d | |d | |d dS )zO
        This tests that the accounts view responds with an index page
        rk   r   !wagtailadmin/account/account.htmlZ
name_emailnotificationslocalethemer(   ZEmailPreferred languageCurrent time zonezvendor/colorpicker.jsName and EmailN)r   r   r   r   r   r   r]   rJ   r   USE_TZassertNotContainsr    r#   r#   r$   test_account_view   s    z$TestAccountSection.test_account_viewc                 C   sN   |  ddd}| |td | j  | | jjd | | jjd d S )NZFoxZMulder)rd   re   rk   )ro   r2   r   rl   refresh_from_dbr   Z
first_name	last_namer    r#   r#   r$   test_change_name_post  s    
z(TestAccountSection.test_change_name_postc                 C   s<   |  ddi}| |td | j  | | jjd d S )Nrf   r'   rk   )ro   r2   r   rl   r~   r   r+   r    r#   r#   r$   test_change_email_post(  s     
z)TestAccountSection.test_change_email_postc                 C   s^   |  ddi}| |jd | d|jd t d  j  | j	
  | | j	jd d S )Nrf   z
test@emailr   r+   rY   r   )ro   r   r   r3   rZ   r   get_formerrorskeysrl   r~   ZassertNotEqualr+   r    r#   r#   r$   test_change_email_not_valid6  s     
z.TestAccountSection.test_change_email_not_validF)Z WAGTAIL_EMAIL_MANAGEMENT_ENABLEDc                 C   sR   | j td}| |jd | |d | |d | |d | |d d S )Nrk   r   rt   zid_name_email-emailrz   Name)r   r   r   r   r   r   r|   rJ   r    r#   r#   r$   #test_with_email_management_disabledJ  s    z6TestAccountSection.test_with_email_management_disabled)Z#WAGTAIL_PASSWORD_MANAGEMENT_ENABLEDc                 C   s:   | j td}| |jd | |d | |d d S )Nrk   r   rt   zChange password)r   r   r   r   r   r   r|   r    r#   r#   r$   3test_account_view_with_password_management_disabledX  s    zFTestAccountSection.test_account_view_with_password_management_disabledc                 C   s    | j td}| |d d S )Nrk   r(   r   r   r   r^   r    r#   r#   r$   "test_change_password_view_disabledb  s    z5TestAccountSection.test_change_password_view_disabledc                 C   sB   |  dddd}| |td | j  | | jd d S )Nr(   newpasswordzpassword-old_passwordzpassword-new_password1zpassword-new_password2rk   ro   r2   r   rl   r~   
assertTruecheck_passwordr    r#   r#   r$   test_change_passwordg  s    	
z'TestAccountSection.test_change_passwordc                 C   sB   |  dddd}| |td | j  | | jd d S )Nr(   z  whitespaced_password  r   rk   r   r    r#   r#   r$    test_change_password_whitespacedw  s    	
z3TestAccountSection.test_change_password_whitespacedc                 C   s   |  dddd}| |jd d }|jd  D ] }|D ]}|jdkr:|} q2q:q2| }| d|j	  | d|jd  | j
  | | j
d d S )	Nr(   r   badpasswordr   r   rY   new_password2'   The two password fields didn’t match.)ro   r   r   rZ   r[   rS   r   r3   r   r   rl   r~   r   r   )r!   r"   Zpassword_panelrV   rW   Zpassword_formr#   r#   r$   +test_change_password_post_password_mismatch  s*    	

z>TestAccountSection.test_change_password_post_password_mismatchc                 C   sB   |  dddd}| |td | j  | | jd d S )Nr(    r   rk   r   r    r#   r#   r$   9test_ignore_change_password_if_only_old_password_supplied  s    	
zLTestAccountSection.test_ignore_change_password_if_only_old_password_suppliedc                 C   sr   |  ddddd}| |td tt jj| jj	d}| 
|j | 
|j | |j | |j d S )Nr_   r`   )submitted_notificationsapproved_notificationsrejected_notificationsupdated_comments_notificationsrk   )r7   )ro   r2   r   r   get_for_userr   r6   r   rl   r7   assertFalser   r   r   r   r   r!   r"   profiler#   r#   r$   test_change_notifications  s    
z,TestAccountSection.test_change_notificationsc                 C   s`   |  ddi}| |td t| j}|  | |jd | j	
td}| |d d S )Nrg   ra   rk   r,   zA<html lang="es" dir="ltr" class="w-theme-dark w-density-default">)ro   r2   r   r   r   rl   r~   r   preferred_languager   r   rJ   r   r#   r#   r$    test_change_language_preferences  s     z3TestAccountSection.test_change_language_preferencesc                 C   sb   t | j}d|_|  | ddi}| |td |  | 	|jd | 	|
 d d S )Nenrg   r   rk   )r   r   rl   r   savero   r2   r   r~   r   Zget_preferred_languager!   r   r"   r#   r#   r$   test_unset_language_preferences  s     z2TestAccountSection.test_unset_language_preferencesr   ZEnglishra   ZSpanish) WAGTAILADMIN_PERMITTED_LANGUAGESc                 C   s   |  t ddg d S )Nr   r   )assertListEqualr   rr   r#   r#   r$   7test_available_admin_languages_with_permitted_languages  s     zJTestAccountSection.test_available_admin_languages_with_permitted_languagesc                 C   s   |  t t d S rq   )r   r   r   rr   r#   r#   r$   )test_available_admin_languages_by_default  s     z<TestAccountSection.test_available_admin_languages_by_defaultc                 C   s    | j td}| |d d S )Nrk   rx   r   r   r   r|   r    r#   r#   r$   7test_not_show_options_if_only_one_language_is_permitted  s    zJTestAccountSection.test_not_show_options_if_only_one_language_is_permittedzTimezone support is disabledc                 C   sD   |  ddi}| |td t| j}|  | |jd d S )Nrh   zPacific/Fijirk   	ro   r2   r   r   r   rl   r~   r   Zcurrent_time_zoner   r#   r#   r$   test_change_current_time_zone  s     z0TestAccountSection.test_change_current_time_zonec                 C   sD   |  ddi}| |td t| j}|  | |jd d S )Nrh   r   rk   r   r   r#   r#   r$   test_unset_current_time_zone  s     z/TestAccountSection.test_unset_current_time_zoneAfrica/Addis_AbabaAmerica/Argentina/Buenos_Aires)WAGTAIL_USER_TIME_ZONESc                 C   s   |  t ddg d S )Nr   r   )r   r   rr   r#   r#   r$   9test_available_admin_time_zones_with_permitted_time_zones.  s    zLTestAccountSection.test_available_admin_time_zones_with_permitted_time_zonesc                 C   s   |  t tj d S rq   )r   r   pytzZcommon_timezonesrr   r#   r#   r$   *test_available_admin_time_zones_by_default8  s    z=TestAccountSection.test_available_admin_time_zones_by_defaultrb   c                 C   s    | j td}| |d d S Nrk   ry   r   r    r#   r#   r$   8test_not_show_options_if_only_one_time_zone_is_permitted<  s    zKTestAccountSection.test_not_show_options_if_only_one_time_zone_is_permittedzTimezone support is enabledc                 C   s    | j td}| |d d S r   r   r    r#   r#   r$   2test_not_show_options_if_timezone_support_disabledB  s    zETestAccountSection.test_not_show_options_if_timezone_support_disabled)r   r   c                 C   s    | j td}| |d d S )Nrk   rv   r   r    r#   r#   r$   Otest_doesnt_render_locale_panel_when_only_one_timezone_and_one_locale_permittedG  s    zbTestAccountSection.test_doesnt_render_locale_panel_when_only_one_timezone_and_one_locale_permittedc                 C   sD   |  ddi}| |td t| j}|  | |jd d S )Nri   Zlightrk   )	ro   r2   r   r   r   rl   r~   r   rw   r   r#   r#   r$   test_change_theme_postR  s     z)TestAccountSection.test_change_theme_postc                 C   sD   |  ddi}| |td t| j}|  | |jd d S )Nrj   Zsnugrk   )	ro   r2   r   r   r   rl   r~   r   Zdensityr   r#   r#   r$   test_change_density_posta  s     z+TestAccountSection.test_change_density_postc                 C   sF   t  jdi d}| j|_t | | t|d | |jd d S )Nrk   )datasensitive_post_parametersZ__ALL__)	r
   r1   rl   r   Zas_viewr   hasattrr   r   )r!   requestr#   r#   r$   test_sensitive_post_parametersp  s
    z1TestAccountSection.test_sensitive_post_parametersN)&rM   rN   rO   rP   rs   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   unittestZ
skipUnlessr   r{   r   r   r   r   r   ZskipIfr   r   r   r   r   r#   r#   r#   r$   rp      sf    

	
 







rp   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestAccountUploadAvatarc                 C   s   |   | _t | _t | _d S rq   )r9   rl   r   avatarother_avatarrr   r#   r#   r$   rs   y  s    
zTestAccountUploadAvatar.setUpc                 C   s.   | j td}| |jd | |d dS )z]
        This tests that the account view renders a "Upload a profile picture" field
        rk   r   zUpload a profile pictureN)r   r   r   r   r   rJ   r    r#   r#   r$   r}   ~  s    z)TestAccountUploadAvatar.test_account_viewc                 C   sT   |  dtd| jj i}| |td t| j	}|
  | d|jj d S Nzavatar-avatarz	other.pngrk   )ro   r	   r   filegetvaluer2   r   r   r   rl   r~   r3   r   urlr   r#   r#   r$   3test_set_custom_avatar_stores_and_get_custom_avatar  s      
zKTestAccountUploadAvatar.test_set_custom_avatar_stores_and_get_custom_avatarc              	   C   s   t | j}| j|_|  |jj}| dtd| jj	
 i}| |td |  | d|jj | t t| W 5 Q R X d S r   )r   r   rl   r   r   pathro   r	   r   r   r   r2   r   r~   r3   r   ZassertRaisesFileNotFoundErroropen)r!   r   Zold_avatar_pathr"   r#   r#   r$   3test_user_upload_another_image_removes_previous_one  s"      
zKTestAccountUploadAvatar.test_user_upload_another_image_removes_previous_onec                 C   sR   t | j}| j|_|  | i }| |td |  | 	d|jj
 dS )S
        Tests that submitting a blank value for avatar doesn't remove it.
        rk   test.pngNr   r   rl   r   r   ro   r2   r   r~   r3   r   r   r#   r#   r$   &test_no_value_preserves_current_avatar  s    
z>TestAccountUploadAvatar.test_no_value_preserves_current_avatarc                 C   sV   t | j}| j|_|  | ddi}| |td |  | 	d|jj
 dS )r   zavatar-clearonrk   r   Nr   r   r#   r#   r$   !test_clear_removes_current_avatar  s    z9TestAccountUploadAvatar.test_clear_removes_current_avatarN)	rM   rN   rO   rs   r}   r   r   r   r   r#   r#   r#   r$   r   x  s   	r   c                   @   s    e Zd ZdZdd Zdd ZdS )$TestAccountManagementForNonModeratorz4
    Tests of reduced-functionality for editors
    c                 C   s:   |  ddd| _| jjtjjdd | jddd d S )N	submitterzsubmitter@example.comr(   ZEditorsrR   r=   )r>   r   groupsaddr   r6   r   r9   rr   r#   r#   r$   rs     s      z*TestAccountManagementForNonModerator.setUpc                 C   s   | j td}d}|jd  D ] }|D ]}|jdkr*|} q"q*q"| }| d|j	  | d|j	  | 
d|j	  | d|j	  dS )	z
        This tests that a user without publish permissions is not shown the
        notification preference for 'submitted' items
        rk   NrY   ru   r   r   r   r   )r   r   r   rZ   r[   rS   r   r3   fieldsr   r@   )r!   r"   Znotifications_panelrV   rW   Znotifications_formr#   r#   r$   >test_notification_preferences_panel_reduced_for_non_moderators  s    
 zcTestAccountManagementForNonModerator.test_notification_preferences_panel_reduced_for_non_moderatorsN)rM   rN   rO   rP   rs   r   r#   r#   r#   r$   r     s   	r   c                   @   s    e Zd ZdZdd Zdd ZdS )%TestAccountManagementForAdminOnlyUserzA
    Tests for users with no edit/publish permissions at all
    c                 C   sT   t jjdd}|jtjjdd | ddd| _| jj	| | j
ddd d S )	Nz
Admin OnlyrR   Zaccess_admin)codenameadmin_only_userzadmin_only_user@example.comr(   r=   )r   r6   createZpermissionsr   r   r   r>   r   r   r9   )r!   Zadmin_only_groupr#   r#   r$   rs      s      z+TestAccountManagementForAdminOnlyUser.setUpc                 C   s    | j td}| |d dS )zT
        Test that the user is not shown the notification preferences panel
        rk   ru   Nr   r    r#   r#   r$   ?test_notification_preferences_not_rendered_for_admin_only_users  s    zeTestAccountManagementForAdminOnlyUser.test_notification_preferences_not_rendered_for_admin_only_usersN)rM   rN   rO   rP   rs   r   r#   r#   r#   r$   r     s   r   c                   @   sp   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d Z
dd Zdd Zdd Zdd Zdd ZdS )TestPasswordResetz7
    This tests that the password reset is working
    c                 C   s   | j dddd d S )Nr&   r'   r(   r)   )r0   rr   r#   r#   r$   rs     s
      zTestPasswordReset.setUpc                 C   s.   | j td}| |jd | |d dS )zW
        This tests that the password reset view returns a password reset page
        wagtailadmin_password_resetr   z-wagtailadmin/account/password_reset/form.htmlNr   r    r#   r#   r$   test_password_reset_view!  s     z*TestPasswordReset.test_password_reset_viewc                 C   sj   ddi}| j td|}| |td | ttjd | tjd jdg | tjd j	d dS )	z
        This posts an email address to the password reset view and
        checks that a password reset email was sent
        r+   r'   r    wagtailadmin_password_reset_done   r   zPassword resetN)
r   r1   r   r2   r   lenr   outboxtosubjectr!   rn   r"   r#   r#   r$   test_password_reset_view_post.  s     z/TestPasswordReset.test_password_reset_view_postc                 C   s@   ddi}| j td|}| |td | ttjd dS )z
        This posts an unknown email address to the password reset view and
        checks that the password reset form raises a validation error
        r+   zunknown@email.comr   r   r   N)r   r1   r   r2   r   r   r   r   r   r#   r#   r$   +test_password_reset_view_post_unknown_emailA  s     z=TestPasswordReset.test_password_reset_view_post_unknown_emailc                 C   sn   ddi}| j td|}| |jd | d|jd j  | d|jd jd  | t	t
jd dS )	z
        This posts an invalid email address to the password reset view and
        checks that the password reset form raises a validation error
        r+   zHello world!r   r   formzEnter a valid email address.r   N)r   r1   r   r   r   r3   rZ   r   r   r   r   r   r   r#   r#   r$   +test_password_reset_view_post_invalid_emailQ  s      z=TestPasswordReset.test_password_reset_view_post_invalid_emailc                 C   s   ddl m}m} ddlm} t jjdd| _t	 
| j| _|||| jj| _tjj}| j|d| _| jj}|tj| ji |  d S )Nr   )force_bytes	force_str)urlsafe_base64_encoder'   r/   Zuidb64token)Zdjango.utils.encodingr   r   Zdjango.utils.httpr   r   r6   r   rl   r   Z
make_tokenZpassword_reset_tokenr7   password_reset_uid
auth_viewsZPasswordResetConfirmViewZreset_url_token
url_kwargsr   r4   rm   ZINTERNAL_RESET_SESSION_TOKENr   )r!   r   r   r   r   sr#   r#   r$   "setup_password_reset_confirm_testsg  s      z4TestPasswordReset.setup_password_reset_confirm_testsc                 C   sr   |    | jdd| _| jtd| jd}| |jd | |d | 	|j
d  | |d | |d	 d
S )zg
        This tests that the password reset view shows an error message if the link is invalid
        zinvalid-tokenr   #wagtailadmin_password_reset_confirmkwargsr   0wagtailadmin/account/password_reset/confirm.htmlZ	validlinkzOThe password reset link was invalid, possibly because it has already been used.zRequest a new password resetN)r   r   r   r   r   r   r   r   r   r   rZ   rJ   r    r#   r#   r$   -test_password_reset_confirm_view_invalid_link  s      z?TestPasswordReset.test_password_reset_confirm_view_invalid_linkc                 C   s<   |    | jtd| jd}| |jd | |d dS )zg
        This tests that the password reset confirm view returns a password reset confirm page
        r   r   r   r   N)r   r   r   r   r   r   r   r   r    r#   r#   r$    test_password_reset_confirm_view  s     z2TestPasswordReset.test_password_reset_confirm_viewc                 C   sZ   |    ddd}| jtd| jd|}| |td | t jj	dd
d dS )	z
        This posts a new password to the password reset confirm view and checks
        that the users password was changed
        r   Znew_password1r   r   r   $wagtailadmin_password_reset_completer'   r/   N)r   r   r1   r   r   r2   r   r   r6   r   r   r   r#   r#   r$   %test_password_reset_confirm_view_post  s     z7TestPasswordReset.test_password_reset_confirm_view_postc                 C   s   |    ddd}| jtd| jd|}| |jd | d|jd j	
  | d	|jd j	d  | t jjd
dd dS )z
        This posts a two passwords that don't match to the password reset
        confirm view and checks that a validation error was raised
        r   r   r   r   r   r   r   r   r   r'   r/   r(   N)r   r   r1   r   r   r   r   r3   rZ   r   r   r   r   r6   r   r   r   r#   r#   r$   7test_password_reset_confirm_view_post_password_mismatch  s*    zITestPasswordReset.test_password_reset_confirm_view_post_password_mismatchc                 C   s.   | j td}| |jd | |d dS )za
        This tests that the password reset done view returns a password reset done page
        r   r   z-wagtailadmin/account/password_reset/done.htmlNr   r    r#   r#   r$   test_password_reset_done_view  s     z/TestPasswordReset.test_password_reset_done_viewc                 C   s.   | j td}| |jd | |d dS )zi
        This tests that the password reset complete view returns a password reset complete page
        r   r   z1wagtailadmin/account/password_reset/complete.htmlNr   r    r#   r#   r$   !test_password_reset_complete_view  s     z3TestPasswordReset.test_password_reset_complete_viewN)rM   rN   rO   rP   rs   r   r   r   r   r   r   r   r  r  r  r  r#   r#   r#   r$   r     s   "r   )+r   r   Zdjango.confr   Zdjango.contrib.authr   r   r   Zdjango.contrib.auth.modelsr   r   Zdjango.contrib.auth.tokensr   Zdjango.corer   Zdjango.core.files.uploadedfiler	   Zdjango.testr
   r   r   Zdjango.urlsr   Zwagtail.admin.localizationr   r   r   Zwagtail.admin.views.accountr   r   Zwagtail.images.tests.utilsr   Zwagtail.test.utilsr   Zwagtail.users.modelsr   r   rQ   rp   r   r   r   r   r#   r#   r#   r$   <module>   s<    5#   [&
  