o
    h                     @   sb  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# d dl$m%Z% G dd de!eZ&G dd dZ'G dd de#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)AdminTemplateTestUtils)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   .   | 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%   k/var/www/html/ndineBlogger/venv/lib/python3.10/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   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   r5   r"   r%   r%   r&   test_already_logged_in_redirectK   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_userr<   r   r   r   r   r    r!   r"   r%   r%   r&   5test_logged_in_as_non_privileged_user_doesnt_redirectZ   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
        wagtailadmin_logoutr   r0   N)r<   r   r3   r   r5   assertNotInr7   r"   r%   r%   r&   test_logoutl   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   r5   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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   sj   | j dd | jtd}W d   n1 sw   Y  | |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)	LOGIN_URLr.   Ni.  r   rF   )r   r   r   r   r   r    r5   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   rF   z.You do not have permission to access the adminN)rA   r<   r   r   r   r5   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.   rH   rI   rK   N)rA   r<   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'   r;   r=   rB   rE   rG   rL   rN   rQ   rR   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   .   dd |j d  D }| ||d|  d S )Nc                 S      h | ]
}|D ]}|j qqS r%   name.0panelsetpanelr%   r%   r&   	<setcomp>       zATestAccountSectionUtilsMixin.assertPanelActive.<locals>.<setcomp>panels_by_tabzPanel %s not active in response)contextvaluesr6   r#   r$   r[   panelsr%   r%   r&   assertPanelActive      z.TestAccountSectionUtilsMixin.assertPanelActivec                 C   rX   )Nc                 S   rY   r%   rZ   r\   r%   r%   r&   r`      ra   zDTestAccountSectionUtilsMixin.assertPanelNotActive.<locals>.<setcomp>rb   zPanel %s active in response)rc   rd   rD   re   r%   r%   r&   assertPanelNotActive   rh   z1TestAccountSectionUtilsMixin.assertPanelNotActivec                 C   s>   dd| j jddddddddd	d
}|| | jtd|S )NTestUserfalsetrueesEurope/Londondarkdefaultsystem)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theme-contrastwagtailadmin_account)userr-   updater   r3   r   )r#   extra_post_data	post_datar%   r%   r&   	post_form   s   
z&TestAccountSectionUtilsMixin.post_formN)rS   rT   rU   rg   ri   r   r%   r%   r%   r&   rW      s    rW   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*d+d,d- Ze	d#gd%d.d/ Zeejd0d1d2 Zeejd0d3d4 Zeejd0e	d5d6gd7d8d9 Zeejd0d:d; Zeejd0e	d<gd7d=d> Z e!ejd?d@dA Z"eejd0e	d<gd#gdBdCdD Z#dEdF Z$dGdH Z%dIdJ Z&dKdL Z'dMS )NTestAccountSectionz9
    This tests that the accounts section is working
    c                 C   s   |   | _t  d S N)r<   r|   r   cache_clear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	rI| |d n| 
|d | |d | |d | |d | |j}| dddg|j |d}| | | |j d dS )zO
        This tests that the accounts view responds with an index page
        r{   r   !wagtailadmin/account/account.html
name_emailnotificationslocalethemer*   EmailPreferred languageCurrent time zonezvendor/colorpicker.jszenctype="multipart/form-data"Name and Email Account)urllabelzmain h2N)r   r   r   r   r    r!   rg   rP   r   USE_TZassertNotContainsget_soupcontentassertBreadcrumbsItemsRendered
select_oneassertIsNotNonetextstrip)r#   r$   soupheadingr%   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 )NFoxMulder)rs   rt   r{   )r   r5   r   r|   refresh_from_dbr   
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 )Nru   r)   r{   )r   r5   r   r|   r   r   r-   r"   r%   r%   r&   test_change_email_post8  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 )Nru   z
test@emailr   r-   rb   r   )r   r   r    r6   rc   r   get_formerrorskeysr|   r   assertNotEqualr-   r"   r%   r%   r&   test_change_email_not_validF  s   
z.TestAccountSection.test_change_email_not_validF) WAGTAIL_EMAIL_MANAGEMENT_ENABLEDc                 C   sR   | j td}| |jd | |d | |d | |d | |d d S )Nr{   r   r   zid_name_email-emailr   Name)r   r   r   r   r    r!   r   rP   r"   r%   r%   r&   #test_with_email_management_disabledZ  s   z6TestAccountSection.test_with_email_management_disabled)#WAGTAIL_PASSWORD_MANAGEMENT_ENABLEDc                 C   s:   | j td}| |jd | |d | |d d S )Nr{   r   r   zChange password)r   r   r   r   r    r!   r   r"   r%   r%   r&   3test_account_view_with_password_management_disabledh  s   zFTestAccountSection.test_account_view_with_password_management_disabledc                 C       | j td}| |d d S )Nr{   r*   r   r   r   ri   r"   r%   r%   r&   "test_change_password_view_disabledr     z5TestAccountSection.test_change_password_view_disabledc                 C   B   |  dddd}| |td | j  | | jd d S )Nr*   newpasswordzpassword-old_passwordzpassword-new_password1zpassword-new_password2r{   r   r5   r   r|   r   
assertTruecheck_passwordr"   r%   r%   r&   test_change_passwordw     	
z'TestAccountSection.test_change_passwordc                 C   r   )Nr*   z  whitespaced_password  r   r{   r   r"   r%   r%   r&    test_change_password_whitespaced  r   z3TestAccountSection.test_change_password_whitespacedc                 C   s   |  dddd}| |jd d }|jd  D ]}|D ]}|jdkr(|} nqq| }| d|j	  | d|jd  | j
  | | j
d d S )	Nr*   r   badpasswordr   r   rb   new_password2'   The two password fields didn’t match.)r   r   r    rc   rd   r[   r   r6   r   r   r|   r   r   r   )r#   r$   password_panelr^   r_   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   r   r{   r   r"   r%   r%   r&   9test_ignore_change_password_if_only_old_password_supplied  r   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 )Nrl   rm   )submitted_notificationsapproved_notificationsrejected_notificationsupdated_comments_notificationsr{   )r:   )r   r5   r   r   get_for_userr   r9   r   r|   r:   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 )Nrv   rn   r{   r.   zS<html lang="es" dir="ltr" class="w-theme-dark w-density-default w-contrast-system">)r   r5   r   r   r   r|   r   r   preferred_languager   r   rP   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enrv   r   r{   )r   r   r|   r   saver   r5   r   r   r   get_preferred_languager#   r   r$   r%   r%   r&   test_unset_language_preferences  s   z2TestAccountSection.test_unset_language_preferencesr   Englishrn   Spanish) WAGTAILADMIN_PERMITTED_LANGUAGESc                 C      |  t ddg d S )Nr   r   )assertListEqualr   r   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 r   )r   r   r   r   r%   r%   r&   )test_available_admin_languages_by_default  s   z<TestAccountSection.test_available_admin_languages_by_defaultid)LANGUAGE_CODEc                 C   sT   | j td}| |jd | |j}|d}| | | |j	
 d d S )Nr{   r   z9select[name="locale-preferred_language"] option[value=""]z%Use server language: Bahasa Indonesia)r   r   r   r   r    r   r   r   r   r   r   )r#   r$   r   optionr%   r%   r&   ,test_default_language_follows_server_setting  s   
z?TestAccountSection.test_default_language_follows_server_settingc                 C   r   )Nr{   r   r   r   r   r   r"   r%   r%   r&   7test_not_show_options_if_only_one_language_is_permitted"  r   zJTestAccountSection.test_not_show_options_if_only_one_language_is_permittedzTimezone support is disabledc                 C   D   |  ddi}| |td t| j}|  | |jd d S )Nrw   zPacific/Fijir{   	r   r5   r   r   r   r|   r   r   current_time_zoner   r%   r%   r&   test_change_current_time_zone'     z0TestAccountSection.test_change_current_time_zonec                 C   r   )Nrw   r   r{   r   r   r%   r%   r&   test_unset_current_time_zone8  r   z/TestAccountSection.test_unset_current_time_zoneAfrica/Addis_AbabaAmerica/Argentina/Buenos_Aires)WAGTAIL_USER_TIME_ZONESc                 C   r   )Nr   r   )r   r   r   r%   r%   r&   9test_available_admin_time_zones_with_permitted_time_zonesI  s   zLTestAccountSection.test_available_admin_time_zones_with_permitted_time_zonesc                 C   s   |  t tt  | jtd}| |j	d | 
|j}|d}| | | |dd | |dd | |dtj d S )	Nr{   r   z'select[name="locale-current_time_zone"]zdata-controllerzw-init w-localezdata-actionz.w-init:ready->w-locale#localizeTimeZoneOptionsz$data-w-locale-server-time-zone-param)r   r   sortedzoneinfoavailable_timezonesr   r   r   r   r    r   r   r   r   r   	TIME_ZONE)r#   r$   r   selectr%   r%   r&   *test_available_admin_time_zones_by_defaultS  s$   


z=TestAccountSection.test_available_admin_time_zones_by_defaultro   c                 C   r   Nr{   r   r   r"   r%   r%   r&   8test_not_show_options_if_only_one_time_zone_is_permittedj  s   zKTestAccountSection.test_not_show_options_if_only_one_time_zone_is_permittedzTimezone support is enabledc                 C   r   r   r   r"   r%   r%   r&   2test_not_show_options_if_timezone_support_disabledp  r   zETestAccountSection.test_not_show_options_if_timezone_support_disabled)r   r   c                 C   r   )Nr{   r   r   r"   r%   r%   r&   Otest_doesnt_render_locale_panel_when_only_one_timezone_and_one_locale_permittedu  s   zbTestAccountSection.test_doesnt_render_locale_panel_when_only_one_timezone_and_one_locale_permittedc                 C   r   )Nrx   lightr{   )	r   r5   r   r   r   r|   r   r   r   r   r%   r%   r&   test_change_theme_post     z)TestAccountSection.test_change_theme_postc                 C   r   )Nrz   more_contrastr{   )	r   r5   r   r   r   r|   r   r   contrastr   r%   r%   r&   test_change_contrast_post  r   z,TestAccountSection.test_change_contrast_postc                 C   r   )Nry   snugr{   )	r   r5   r   r   r   r|   r   r   densityr   r%   r%   r&   test_change_density_post  r   z+TestAccountSection.test_change_density_postc                 C   sF   t  jdi d}| j|_t | | t|d | |jd d S )Nr{   )datasensitive_post_parameters__ALL__)	r
   r3   r|   r   as_viewr   hasattrr   r  )r#   requestr%   r%   r&   test_sensitive_post_parameters  s
   z1TestAccountSection.test_sensitive_post_parametersN)(rS   rT   rU   rV   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   unittest
skipUnlessr   r   r   r   r   r   r   skipIfr   r   r   r   r   r  r%   r%   r%   r&   r      sn    +

	
 









r   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 r   )r<   r|   r   avatarother_avatarr   r%   r%   r&   r     s   
zTestAccountUploadAvatar.setUpc                 C   r   )z]
        This tests that the account view renders a "Upload a profile picture" field
        r{   r   zUpload a profile pictureN)r   r   r   r   r    rP   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.pngr{   )r   r	   r  filegetvaluer5   r   r   r   r|   r   r6   r  r   r   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 d    d S 1 sIw   Y  d S r  )r   r   r|   r  r   pathr   r	   r  r  r  r5   r   r   r6   r   assertRaisesFileNotFoundErroropen)r#   r   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.
        r{   test.pngNr   r   r|   r  r   r   r5   r   r   r6   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onr{   r  Nr  r   r%   r%   r&   !test_clear_removes_current_avatar  s   z9TestAccountUploadAvatar.test_clear_removes_current_avatarN)	rS   rT   rU   r   r   r  r  r  r  r%   r%   r%   r&   r
    s    	r
  c                   @       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*   EditorsrZ   r@   )rA   r  groupsaddr   r9   r   r<   r   r%   r%   r&   r     s
   z*TestAccountManagementForNonModerator.setUpc                 C   s   | j td}d}|jd  D ]}|D ]}|jdkr |} n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
        r{   Nrb   r   r   r   r   r   )r   r   r   rc   rd   r[   r   r6   fieldsr   rD   )r#   r$   notifications_panelr^   r_   notifications_formr%   r%   r&   >test_notification_preferences_panel_reduced_for_non_moderators  s    

zcTestAccountManagementForNonModerator.test_notification_preferences_panel_reduced_for_non_moderatorsN)rS   rT   rU   rV   r   r&  r%   r%   r%   r&   r    s    	r  c                   @   r  )%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 OnlyrZ   access_admin)codenameadmin_only_userzadmin_only_user@example.comr*   r@   )r   r9   createpermissionsr"  r   r   rA   r*  r!  r<   )r#   admin_only_groupr%   r%   r&   r   =  s   z+TestAccountManagementForAdminOnlyUser.setUpc                 C   s    | j td}| |d dS )zT
        Test that the user is not shown the notification preferences panel
        r{   r   Nr   r"   r%   r%   r&   ?test_notification_preferences_not_rendered_for_admin_only_usersK  s   zeTestAccountManagementForAdminOnlyUser.test_notification_preferences_not_rendered_for_admin_only_usersN)rS   rT   rU   rV   r   r.  r%   r%   r%   r&   r'  6  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+   )r2   r   r%   r%   r&   r   X  s   
zTestPasswordReset.setUpc                 C   r   )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^  
   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)   r0   wagtailadmin_password_reset_done   r   zPassword resetN)
r   r3   r   r5   r   lenr   outboxtosubjectr#   r   r$   r%   r%   r&   test_password_reset_view_postk  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.comr0  r3  r   N)r   r3   r   r5   r   r5  r   r6  r9  r%   r%   r&   +test_password_reset_view_post_unknown_email~  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!r0  r   formzEnter a valid email address.r   N)r   r3   r   r   r    r6   rc   r   r   r5  r   r6  r9  r%   r%   r&   +test_password_reset_view_post_invalid_email  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)   r1   uidb64token)django.utils.encodingr>  r?  django.utils.httpr@  r   r9   r   r|   r   
make_tokenpassword_reset_tokenr:   password_reset_uid
auth_viewsPasswordResetConfirmViewreset_url_token
url_kwargsr   r7   r}   INTERNAL_RESET_SESSION_TOKENr   )r#   r>  r?  r@  rC  sr%   r%   r&   "setup_password_reset_confirm_tests  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-tokenrA  #wagtailadmin_password_reset_confirmkwargsr   0wagtailadmin/account/password_reset/confirm.html	validlinkzOThe password reset link was invalid, possibly because it has already been used.zRequest a new password resetN)rO  rH  rL  r   r   r   r   r    r!   r   rc   rP   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
        rP  rQ  r   rS  N)rO  r   r   r   rL  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   new_password1r   rP  rQ  $wagtailadmin_password_reset_completer)   r1   N)rO  r   r3   r   rL  r5   r   r   r9   r   r   r9  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   rW  rP  rQ  r   r   r<  r   r)   r1   r*   N)rO  r   r3   r   rL  r   r    r6   rc   r   r   r   r   r9   r   r   r9  r%   r%   r&   7test_password_reset_confirm_view_post_password_mismatch  s(   zITestPasswordReset.test_password_reset_confirm_view_post_password_mismatchc                 C   r   )za
        This tests that the password reset done view returns a password reset done page
        r3  r   z-wagtailadmin/account/password_reset/done.htmlNr   r"   r%   r%   r&   test_password_reset_done_view)  r2  z/TestPasswordReset.test_password_reset_done_viewc                 C   r   )zi
        This tests that the password reset complete view returns a password reset complete page
        rY  r   z1wagtailadmin/account/password_reset/complete.htmlNr   r"   r%   r%   r&   !test_password_reset_complete_view6  r2  z3TestPasswordReset.test_password_reset_complete_viewN)rS   rT   rU   rV   r   r1  r:  r;  r=  rO  rU  rV  rZ  r[  r\  r]  r%   r%   r%   r&   r/  S  s    "r/  )-r  r   django.confr   django.contrib.authr   r   rI  django.contrib.auth.modelsr   r   django.contrib.auth.tokensr   django.corer   django.core.files.uploadedfiler	   django.testr
   r   r   django.urlsr   wagtail.admin.localizationr   r   r   wagtail.admin.views.accountr   r   wagtail.images.tests.utilsr   wagtail.test.utilsr   !wagtail.test.utils.template_testsr   wagtail.users.modelsr   r   rW   r   r
  r  r'  r/  r%   r%   r%   r&   <module>   s@     5
$   F[
&