U
    {h                    @   sD  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	m
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 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m Z  d dl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* d dl+m,Z, d dl-m.Z.m/Z/ G dd de	Z0G dd de	Z1G dd de,e	Z2G dd de,e	Z3e
ddG dd de,e	Z4G dd  d e,e	Z5G d!d" d"e,e	Z6G d#d$ d$e,e	Z7G d%d& d&e,e	Z8G d'd( d(e,e	Z9G d)d* d*e,e	Z:G d+d, d,e,e	Z;G d-d. d.e,e	Z<G d/d0 d0e,e	Z=G d1d2 d2e,e	Z>G d3d4 d4e,e	Z?G d5d6 d6e,e	Z@dS )7    N)BytesIO)settings)AnonymousUser)RequestFactoryTestCaseoverride_settings)reverse)escape)	urlencode)load_workbook)WagtailAdminPageForm)get_form_for_model)FormSubmission)FormSubmissionsPanel)make_form_page%make_form_page_with_custom_submission)LocalePage)	CustomFormPageSubmissionExtendedFormField	FormFieldFormFieldForCustomListViewPageFormFieldWithCustomSubmissionFormPageFormPageWithCustomFormBuilderFormPageWithCustomSubmission$FormPageWithCustomSubmissionListView)WagtailTestUtils)inline_formsetnested_form_datac                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestFormResponsesPanelc                 C   sh   t  d| _t }|| j_t | _ttt	dddddgd| _
t t}|j| j| 
 | jd| _d S 	N/titleslug
to_addressfrom_addresssubjectZ
form_classfieldsinstanceformrequest)r   getr-   r   userr   	form_pager   r   r   FormPageFormr   bind_to_modelget_bound_panelpanelselfr/   r4    r7   n/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/contrib/forms/tests/test_views.pysetUp%   s      zTestFormResponsesPanel.setUpc              	   C   sf   | j dddddddd | | j  | j }td| jjfd}d	| d
}| 	|| dS )TShow the panel with the count of submission and a link to the list_submissions view.z/contact-us/zbob@example.comzhello world foobarbaz
your_emailyour_messageZyour_choiceswagtailforms:list_submissionsargs	<a href="">1</a>N)
clientpost
assertTruer4   is_shownrender_htmlr   r0   idassertIn)r6   resulturllinkr7   r7   r8   test_render_with_submissions7   s    
	
z3TestFormResponsesPanel.test_render_with_submissionsc                 C   s   |  | j  dS zBThe panel should not be shown if the number of submission is zero.NZassertFalser4   rK   r6   r7   r7   r8   test_render_without_submissionsJ   s    z6TestFormResponsesPanel.test_render_without_submissionsN__name__
__module____qualname__r9   rR   rV   r7   r7   r7   r8   r    $   s   r    c                   @   s   e Zd Zdd Zdd ZdS )!TestFormResponsesPanelWithNewPagec                 C   sh   t  d| _t }|| j_t | _tttdddddgd| _	t
 t}|j| j| 	 | jd| _d S r!   )r   r.   r-   r   r/   r   r0   r   r   r1   r   r2   r3   r4   r5   r7   r7   r8   r9   P   s      z'TestFormResponsesPanelWithNewPage.setUpc                 C   s   |  | j  dS rS   rT   rU   r7   r7   r8   rV   b   s    zATestFormResponsesPanelWithNewPage.test_render_without_submissionsN)rX   rY   rZ   r9   rV   r7   r7   r7   r8   r[   O   s   r[   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )/TestFormResponsesPanelWithCustomSubmissionClassc                 C   sx   t  d| _t }|| j_t | _ttt	dddddgd| _
| jdd	d
| _t t}|j| j| 
 | jd| _d S )Nr"   r#   r$   r%   r&   r'   r(   zuser-n1kola123usernamepasswordr*   )r   r.   r-   r   r/   r   r0   r   r   r   r1   create_user	test_userr   r2   r3   r4   r5   r7   r7   r8   r9   h   s       z5TestFormResponsesPanelWithCustomSubmissionClass.setUpc              	   C   s|   t jj| j| jdddddddd}d|_|  | | j	  | j
 }td| jjfd	}d
| d}| || dS )r:   zemail@domain.comzhi joer;   r<   r@   r/   page	form_dataz2017-08-29T12:00:00.000ZrC   rD   rF   rG   N)r   objectscreaterb   r0   submit_timesaverJ   r4   rK   rL   r   rM   rN   )r6   new_form_submissionrO   rP   rQ   r7   r7   r8   rR   }   s    
	
zLTestFormResponsesPanelWithCustomSubmissionClass.test_render_with_submissionsc                 C   s   |  | j  dS rS   rT   rU   r7   r7   r8   rV      s    zOTestFormResponsesPanelWithCustomSubmissionClass.test_render_without_submissionsNrW   r7   r7   r7   r8   r\   g   s   r\   c                   @   sZ   e Zd Zdg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 )TestFormsIndex	test.jsonc                 C   s"   | j ddd tjjdd| _d S N
siteeditorr`   r^   /home/contact-us/Zurl_pathloginr   rf   r.   r0   rU   r7   r7   r8   r9      s    zTestFormsIndex.setUpc                 C   s:   t dD ],}| jjtdt| dt| ddd qdS )
        This makes 100 form pages and adds them as children to 'contact-us'
        This is used to test pagination on the forms index
        d   Form form-T)r#   r$   liver+   N)ranger0   	add_childr   str)r6   ir7   r7   r8   make_form_pages   s    
 
 zTestFormsIndex.make_form_pagesc                 C   s.   | j td}| |jd | |d d S )Nwagtailforms:index   wagtailforms/index.html)rH   r.   r   assertEqualstatus_codeassertTemplateUsedr6   responser7   r7   r8   test_forms_index   s    zTestFormsIndex.test_forms_indexc                 C   sP   |    | jtdddi}| |jd | |d | |jd jd d S )Nr~   p   r   r   page_obj)	r}   rH   r.   r   r   r   r   contextnumberr   r7   r7   r8   test_forms_index_pagination   s
    z*TestFormsIndex.test_forms_index_paginationc                 C   s0   |    | jtdddi}| |jd d S )Nr~   r   zHello world!  r}   rH   r.   r   r   r   r   r7   r7   r8   #test_forms_index_pagination_invalid   s    z2TestFormsIndex.test_forms_index_pagination_invalidc                 C   s0   |    | jtdddi}| |jd d S )Nr~   r   韆 r   r   r   r7   r7   r8   (test_forms_index_pagination_out_of_range   s    z7TestFormsIndex.test_forms_index_pagination_out_of_rangec                 C   s6   | j ddd | jtd}| | j|jd  d S )Neventeditorr`   r^   r~   
form_pages)rr   rH   r.   r   assertNotInr0   r   r   r7   r7   r8   (test_cannot_see_forms_without_permission   s    z7TestFormsIndex.test_cannot_see_forms_without_permissionc                 C   s(   | j td}| | j|jd  d S )Nr~   r   )rH   r.   r   rN   r0   r   r   r7   r7   r8   "test_can_see_forms_with_permission   s    z1TestFormsIndex.test_can_see_forms_with_permissionc              	   C   sl   dd }| j td}| | j|jd  | d| | j td}W 5 Q R X | | j|jd  d S )Nc                 S   s   | j s| }|S N)Zis_superusernoner/   Zquerysetr7   r7   r8   construct_forms_for_user   s    zpTestFormsIndex.test_cant_see_forms_after_filter_form_submissions_for_user_hook.<locals>.construct_forms_for_userr~   r    filter_form_submissions_for_user)rH   r.   r   rN   r0   r   register_hookr   r6   r   r   r7   r7   r8   ?test_cant_see_forms_after_filter_form_submissions_for_user_hook   s     zNTestFormsIndex.test_cant_see_forms_after_filter_form_submissions_for_user_hookN)rX   rY   rZ   fixturesr9   r}   r   r   r   r   r   r   r   r7   r7   r7   r8   rk      s   

	rk   TZWAGTAIL_I18N_ENABLEDc                   @   sF   e Zd ZdgZdd ZdddZdd	 Zd
d Zedddd Z	dS )%TestFormsIndexWithLocalisationEnabledrl   c                 C   sd   | j ddd tjjdd| _t | _tjjdd| _	| jj
| j	dd	| _| j  td
| _d S )N	superuserr`   r^   ro   rp   fr)language_codeT)Zcopy_parentsr~   )rr   r   rf   r.   r0   r   get_defaultZ	en_localerg   	fr_localeZcopy_for_translationfr_form_pageri   r   forms_index_urlrU   r7   r7   r8   r9      s    
 
z+TestFormsIndexWithLocalisationEnabled.setUprt   Nc                 C   sd   |dkr| j }t|D ]H}| d|j  d}|jtd| d| d|j d|jdd	 qdS )
rs   Nz []ru   rv   -T)r#   r$   rw   	locale_idrx   )r0   ry   localeZget_display_namerz   r   r   )r6   numparentr|   suffixr7   r7   r8   r}   
  s    z5TestFormsIndexWithLocalisationEnabled.make_form_pagesc                 C   sf   | j | j}| |jd | |j}|d}dd |D }| t|d | |dddg d S )	Nr   zinput[name="locale"]c                 S   s   g | ]}|j d qS value)attrsr.   ).0inputr7   r7   r8   
<listcomp>%  s     zJTestFormsIndexWithLocalisationEnabled.test_forms_index.<locals>.<listcomp>   r;   enr   )	rH   r.   r   r   r   Zget_soupcontentselectlen)r6   r   Zsoupinputsvaluesr7   r7   r8   r     s    
z6TestFormsIndexWithLocalisationEnabled.test_forms_indexc                 C   s  | j | jdd | j | jdd | j| jddi}| |jd | |d | |j	d j
d | j| jddi}| |jd | |j	d j
d | t|j	d jd | j| jdd	i}| |jd
 | j| jd| jjd}| |jd | |j	d j
d d S )N   )r   r   r   r   r   r   r   r      r   )r   r   )r}   r0   r   rH   r.   r   r   r   r   r   r   r   Zobject_listr   r   r   r7   r7   r8   r   )  s$     zATestFormsIndexWithLocalisationEnabled.test_forms_index_paginationFr   c                 C   s   | j | j}| |d d S )Nzdata-locale-selector)rH   r.   r   ZassertNotContainsr   r7   r7   r8   ,test_switcher_doesnt_show_with_i18n_disabledK  s    zRTestFormsIndexWithLocalisationEnabled.test_switcher_doesnt_show_with_i18n_disabled)rt   N)
rX   rY   rZ   r   r9   r}   r   r   r   r   r7   r7   r7   r8   r      s   
"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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 )TestFormsSubmissionsListc                 C   sf   t  | _tjj| jddddgdd}d|_|  tjj| jdd	d
d}d|_|  |   d S )Nnew@example.comthis is a fairly new messager=   r?   r@   rd   re   2014-01-01T12:00:00.000Zold@example.comthis is a really old messagerA   rB   2013-01-01T12:00:00.000Z)r   r0   r   rf   rg   rh   ri   rr   )r6   rj   old_form_submissionr7   r7   r8   r9   S  s&    zTestFormsSubmissionsList.setUpc              
   C   sv   t d| jjfd}| j|ddi}dD ]H}| j|d2 td|d}| d| }| |t| W 5 Q R X q(d S )	NrC   rD   nameZAlice)xlsxcsv)format)r   export?)	r   r0   rM   rH   r.   subTestr
   assertContainsr	   )r6   Zlist_urlr   r   paramsZexpected_urlr7   r7   r8    test_export_urls_include_filterst  s    z9TestFormsSubmissionsList.test_export_urls_include_filtersc                 C   s,   t dD ]}t| jddid}|  qdS )]
        This makes 100 submissions to test pagination on the forms submissions page
        rt   ZhelloZworldr   N)ry   r   r0   ri   r6   r|   
submissionr7   r7   r8   make_list_submissions  s     z.TestFormsSubmissionsList.make_list_submissionsc                 C   sZ   | j td| jjfd}| |jd | |d | t|j	d d | 
|d d S )NrC   rD   r   #wagtailforms/submissions_index.html	data_rowsr   foo, bazrH   r.   r   r0   rM   r   r   r   r   r   r   r   r7   r7   r8   test_list_submissions  s    z.TestFormsSubmissionsList.test_list_submissionsc              	   C   s   dd }| j td| jjfd}| |jd | |d | t|j	d d | 
d	|  | j td| jjfd}W 5 Q R X | |d
 d S )Nc                 S   s   |  S r   r   r   r7   r7   r8   r     s    z|TestFormsSubmissionsList.test_list_submissions_after_filter_form_submissions_for_user_hook.<locals>.construct_forms_for_userrC   rD   r   r   r   r   r   /admin/)rH   r.   r   r0   rM   r   r   r   r   r   r   assertRedirectsr   r7   r7   r8   Atest_list_submissions_after_filter_form_submissions_for_user_hook  s     zZTestFormsSubmissionsList.test_list_submissions_after_filter_form_submissions_for_user_hookc                 C   sT   | j td| jjfdddi}| |jd | |d | t|j	d d d S )	NrC   rD   	date_from
01/01/2014r   r   r      
rH   r.   r   r0   rM   r   r   r   r   r   r   r7   r7   r8   )test_list_submissions_filtering_date_from  s    zBTestFormsSubmissionsList.test_list_submissions_filtering_date_fromc                 C   sT   | j td| jjfdddi}| |jd | |d | t|j	d d d S )	NrC   rD   date_to
12/31/2013r   r   r   r   r   r   r7   r7   r8   'test_list_submissions_filtering_date_to  s    z@TestFormsSubmissionsList.test_list_submissions_filtering_date_toc                 C   sV   | j td| jjfdddd}| |jd | |d | t|j	d d	 d S )
NrC   rD   r   
01/02/2014r   r   r   r   r   r   r   r   r7   r7   r8   %test_list_submissions_filtering_range  s    z>TestFormsSubmissionsList.test_list_submissions_filtering_rangec                 C   sZ   |    | jtd| jjfdddi}| |jd | |d | |j	d j
d d S )NrC   rD   r   r   r   r   r   )r   rH   r.   r   r0   rM   r   r   r   r   r   r   r7   r7   r8    test_list_submissions_pagination  s    z9TestFormsSubmissionsList.test_list_submissions_paginationc                 C   s:   |    | jtd| jjfdddi}| |jd d S NrC   rD   r   zHello World!r   r   rH   r.   r   r0   rM   r   r   r   r7   r7   r8   (test_list_submissions_pagination_invalid  s    zATestFormsSubmissionsList.test_list_submissions_pagination_invalidc                 C   s:   |    | jtd| jjfdddi}| |jd d S NrC   rD   r   r   r   r   r   r7   r7   r8   -test_list_submissions_pagination_out_of_range  s    zFTestFormsSubmissionsList.test_list_submissions_pagination_out_of_rangec                 C   s<   | j td| jjfd}|jd d d }| d| d S )NrC   rD   r   r   r)   r   rH   r.   r   r0   rM   r   rN   r6   r   first_row_valuesr7   r7   r8   #test_list_submissions_default_order  s
    z<TestFormsSubmissionsList.test_list_submissions_default_orderc                 C   sB   | j td| jjfdddi}|jd d d }| d| d S )	NrC   rD   order_byz-submit_timer   r   r)   r   r   r   r7   r7   r8   6test_list_submissions_url_params_ordering_recent_first  s    zOTestFormsSubmissionsList.test_list_submissions_url_params_ordering_recent_firstc                 C   sB   | j td| jjfdddi}|jd d d }| d| d S )	NrC   rD   r   rh   r   r   r)   r   r   r   r7   r7   r8   6test_list_submissions_url_params_ordering_oldest_first  s    zOTestFormsSubmissionsList.test_list_submissions_url_params_ordering_oldest_firstN)rX   rY   rZ   r9   r   r   r   r   r   r   r   r   r   r   r   r   r   r7   r7   r7   r8   r   R  s   !
	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d Z	dd Z
dd Zdd ZdS )TestFormsSubmissionsExportc                 C   s   t  | _tjj| jddddgdd}tjr4d|_nd|_|  tjj| jd	d
dd}tjrhd|_nd|_|  | 	  d S )Nr   r   r=   r?   r@   r   r   2013-01-01T12:00:00r   r   r   r   2014-01-01T12:00:00)
r   r0   r   rf   rg   r   USE_TZrh   ri   rr   r6   r   rj   r7   r7   r8   r9     s.    z TestFormsSubmissionsExport.setUpc                 C   s   | j td| jjfdddi}| |jd |  	d}| |d d t
jrx| |d	 d
 | |d d n | |d	 d | |d d d S )NrC   rD   r   r   r   
r   5Submission date,Your email,Your message,Your choicesr   R2013-01-01 12:00:00+00:00,old@example.com,this is a really old message,"foo, baz"r   H2014-01-01 12:00:00+00:00,new@example.com,this is a fairly new message,L2013-01-01 12:00:00,old@example.com,this is a really old message,"foo, baz"B2014-01-01 12:00:00,new@example.com,this is a fairly new message,rH   r.   r   r0   rM   r   r   getvaluedecodesplitr   r   r6   r   
data_linesr7   r7   r8    test_list_submissions_csv_export3  s6     z;TestFormsSubmissionsExport.test_list_submissions_csv_exportc              
   C   s   | j td| jjfdddi}| |jd | }tt	|dd }dd	 |j
D }| |d
 ddddg | |d tddddd
dddg | |d tddddd
ddd g | t|d d S )NrC   rD   r   r   r   )filenameZSheet1c                 S   s   g | ]}d d |D qS )c                 S   s   g | ]
}|j qS r7   r   )r   cellr7   r7   r8   r   \  s     z[TestFormsSubmissionsExport.test_list_submissions_xlsx_export.<locals>.<listcomp>.<listcomp>r7   )r   rowr7   r7   r8   r   \  s     zPTestFormsSubmissionsExport.test_list_submissions_xlsx_export.<locals>.<listcomp>r   zSubmission date
Your emailzYour messagezYour choicesr   i     r   r   r   r   i  r   r   r   )rH   r.   r   r0   rM   r   r   r  r   r   rowsdatetimer   )r6   r   Zworkbook_dataZ	worksheetZ
cell_arrayr7   r7   r8   !test_list_submissions_xlsx_exportS  s:    
		z<TestFormsSubmissionsExport.test_list_submissions_xlsx_exportc                 C   s   t dD ]@}tjj| jd| d| dd}tjr:d|_nd|_|  q| j	
td| jjfd	d
di}| |jd |  d}| dt| d S )Nrt   znew@example-%s.comzI like things x %s)
your-emailyour-messager   r   r   rC   rD   r   r   r   r   h   )ry   r   rf   rg   r0   r   r   rh   ri   rH   r.   r   rM   r   r   r  r  r  r   )r6   r|   rj   r   r	  r7   r7   r8   &test_list_submissions_csv_large_exportu  s$    
zATestFormsSubmissionsExport.test_list_submissions_csv_large_exportc              	   C   s   dd }| j td| jjfdddi}| |jd |  	d}| |d	 d
 t
jr| |d d | |d d n | |d d | |d d | d|& | j td| jjfdddi}W 5 Q R X | |d d S )Nc                 S   s   |  S r   r   r   r7   r7   r8   r     s    zTestFormsSubmissionsExport.test_list_submissions_csv_export_after_filter_form_submissions_for_user_hook.<locals>.construct_forms_for_userrC   rD   r   r   r   r   r   r   r   r   r   r  r  r  r   r   )rH   r.   r   r0   rM   r   r   r  r  r  r   r   r   r   )r6   r   r   r	  r7   r7   r8   Ltest_list_submissions_csv_export_after_filter_form_submissions_for_user_hook  sJ      zgTestFormsSubmissionsExport.test_list_submissions_csv_export_after_filter_form_submissions_for_user_hookc                 C   s~   | j td| jjfdddd}| |jd |  	d}| |d d	 t
jrj| |d
 d n| |d
 d d S )NrC   rD   r   r   r   r   r   r   r   r   r   r  r  r  r  r7   r7   r8   9test_list_submissions_csv_export_with_date_from_filtering  s&     zTTestFormsSubmissionsExport.test_list_submissions_csv_export_with_date_from_filteringc                 C   s~   | j td| jjfdddd}| |jd |  	d}| |d d	 t
jrj| |d
 d n| |d
 d d S )NrC   rD   r   r   r   r   r   r   r   r   r   r   r  r  r  r7   r7   r8   7test_list_submissions_csv_export_with_date_to_filtering  s&     zRTestFormsSubmissionsExport.test_list_submissions_csv_export_with_date_to_filteringc                 C   s   | j td| jjfddddd}| |jd |  	d}| |d	 d
 t
jrl| |d d n| |d d d S )NrC   rD   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r7   r7   r8   5test_list_submissions_csv_export_with_range_filtering  s&    
 zPTestFormsSubmissionsExport.test_list_submissions_csv_export_with_range_filteringc                 C   s~   t jj| jdddd}d|_|  | jtd| jj	fddd	d
}| 
|jd | ddd }| d| d S )Nunicode@example.com   こんにちは、世界r   r   2014-01-02T12:00:00.000ZrC   rD   r   r   r   r   r   utf-8r   r   )r   rf   rg   r0   rh   ri   rH   r.   r   rM   r   r   r  r  r  rN   r6   unicode_form_submissionr   Z	data_liner7   r7   r8   ;test_list_submissions_csv_export_with_unicode_in_submission  s    zVTestFormsSubmissionsExport.test_list_submissions_csv_export_with_unicode_in_submissionc              	   C   s   t jj| jddddddd tjj| jdd	d
dd}d|_|  | jt	d| jj
fdddd}| |jd | dd}| d|d  | d
|d  d S )Nr   V   Выберите самую любимую IDE для разработке на PythonE   Вы можете выбрать только один вариантradioTPyCharm,vim,nanord   
sort_orderlabel	help_text
field_typerequiredchoicesr  We don't need unicode herevim)rA   rB   ڿu0412u044bu0431u0435u0440u0438u0442u0435_u0441u0430u043cu0443u044e_u043bu044eu0431u0438u043cu0443u044e_ide_u0434u043bu044f_u0440u0430u0437u0440u0430u0431u043eu0442u043au0435_u043du0430_pythonr   r   rC   rD   r   r   r!  r   r"  r   r   r   )r   rf   rg   r0   r   rh   ri   rH   r.   r   rM   r   r   r  r  r  rN   r6   r$  r   r	  r7   r7   r8   6test_list_submissions_csv_export_with_unicode_in_field  s:    	 zQTestFormsSubmissionsExport.test_list_submissions_csv_export_with_unicode_in_fieldN)rX   rY   rZ   r9   r
  r  r  r  r  r  r  r%  r5  r7   r7   r7   r8   r     s   # "1r   c                   @   sL   e 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S ) TestCustomFormsSubmissionsExportc                 C   s   | j |ddS Nr]   r^   ra   r6   r_   r7   r7   r8   create_test_user_without_adminA  s    z?TestCustomFormsSubmissionsExport.create_test_user_without_adminc                 C   s   t  | _tjj| d| jdddd}tjr6d|_nd|_|	  tjj| d| jd	d
dd}tjrrd|_nd|_|	  | 
  d S )N	user-johnr   r   r   rc   r   r   user-m1kolar   r   r   r   )r   r0   r   rf   rg   r:  r   r   rh   ri   rr   r   r7   r7   r8   r9   D  s0    z&TestCustomFormsSubmissionsExport.setUpc                 C   s   | j td| jjfdddi}| |jd |  	d}| |d d t
jrx| |d	 d
 | |d d n | |d	 d | |d d d S )NrC   rD   r   r   r   r   r   @User email,Submission date,Your email,Your message,Your choicesr   ^user-john@example.com,2013-01-01 12:00:00+00:00,old@example.com,this is a really old message,r   `user-m1kola@example.com,2014-01-01 12:00:00+00:00,new@example.com,this is a fairly new message,Xuser-john@example.com,2013-01-01 12:00:00,old@example.com,this is a really old message,Zuser-m1kola@example.com,2014-01-01 12:00:00,new@example.com,this is a fairly new message,r  r  r7   r7   r8   r
  h  s6    zATestCustomFormsSubmissionsExport.test_list_submissions_csv_exportc                 C   s~   | j td| jjfdddd}| |jd |  	d}| |d d	 t
jrj| |d
 d n| |d
 d d S )NrC   rD   r   r   r  r   r   r   r=  r   r?  rA  r  r  r7   r7   r8   r    s&    zZTestCustomFormsSubmissionsExport.test_list_submissions_csv_export_with_date_from_filteringc                 C   s~   | j td| jjfdddd}| |jd |  	d}| |d d	 t
jrj| |d
 d n| |d
 d d S )NrC   rD   r   r   r  r   r   r   r=  r   r>  r@  r  r  r7   r7   r8   r    s&    zXTestCustomFormsSubmissionsExport.test_list_submissions_csv_export_with_date_to_filteringc                 C   s   | j td| jjfddddd}| |jd |  	d}| |d	 d
 t
jrl| |d d n| |d d d S )NrC   rD   r   r   r   r  r   r   r   r=  r   r?  rA  r  r  r7   r7   r8   r    s&    
zVTestCustomFormsSubmissionsExport.test_list_submissions_csv_export_with_range_filteringc                 C   s   t jj| d| jdddd}d|_|  | jt	d| jj
fdd	d
d}| |jd | ddd }| d| d S )Nuser-bobr  r  r   rc   r   rC   rD   r   r   r!  r   r"  r   r   )r   rf   rg   r:  r0   rh   ri   rH   r.   r   rM   r   r   r  r  r  rN   r#  r7   r7   r8   r%    s     z\TestCustomFormsSubmissionsExport.test_list_submissions_csv_export_with_unicode_in_submissionc              	   C   s   t jj| jddddddd tjj| d| jd	d
ddd}d|_|  | j	t
d| jjfdddd}| |jd | dd}| d|d  | d|d  d S )Nr   r&  r'  r(  Tr)  r*  rB  r  r1  r2  )r  r  r3  rc   r   rC   rD   r   r   r!  r   r"  r   r   r   )r   rf   rg   r0   r   r:  rh   ri   rH   r.   r   rM   r   r   r  r  r  rN   r4  r7   r7   r8   r5    s<    		 zWTestCustomFormsSubmissionsExport.test_list_submissions_csv_export_with_unicode_in_fieldN)rX   rY   rZ   r:  r9   r
  r  r  r  r%  r5  r7   r7   r7   r8   r6  @  s   $!r6  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d Z	dd Z
dd Zdd ZdS )TestCustomFormsSubmissionsListc                 C   s   | j |ddS r7  r8  r9  r7   r7   r8   r:    s    z=TestCustomFormsSubmissionsList.create_test_user_without_adminc                 C   sp   t  | _tjj| d| jdddd}d|_|  tjj| d| jdd	dd}d
|_|  |   d S )Nr;  r   r   r   rc   r   r<  r   r   r   )	r   r0   r   rf   rg   r:  rh   ri   rr   r   r7   r7   r8   r9     s(    z$TestCustomFormsSubmissionsList.setUpc                 C   sB   t dD ]4}t| d| | jd| d| dd}|  qdS )r   rt   zgenerated-username-%szgenerated-your-email-%szgenerated-your-message-%sr   rc   N)ry   r   r:  r0   ri   r   r7   r7   r8   r   1  s    z4TestCustomFormsSubmissionsList.make_list_submissionsc                 C   s~   | j td| jjfd}| |jd | |d | t|j	d d | j
|ddd	 | j
|d
dd	 | j
|ddd	 d S )NrC   rD   r   r   r   r   +<th id="useremail" class="">User email</th>Thtml <td>user-m1kola@example.com</td><td>user-john@example.com</td>r   r   r7   r7   r8   r   @  s      z4TestCustomFormsSubmissionsList.test_list_submissionsc                 C   st   | j td| jjfdddi}| |jd | |d | t|j	d d | j
|d	d
d | j
|dd
d d S )NrC   rD   r   r   r   r   r   r   rD  TrE  rG  r   r   r7   r7   r8   r   Q  s      zHTestCustomFormsSubmissionsList.test_list_submissions_filtering_date_fromc                 C   st   | j td| jjfdddi}| |jd | |d | t|j	d d | j
|d	d
d | j
|dd
d d S )NrC   rD   r   r   r   r   r   r   rD  TrE  rH  r   r   r7   r7   r8   r   b  s      zFTestCustomFormsSubmissionsList.test_list_submissions_filtering_date_toc                 C   sv   | j td| jjfdddd}| |jd | |d | t|j	d d	 | j
|d
dd | j
|ddd d S )NrC   rD   r   r   r   r   r   r   r   rD  TrE  rG  r   r   r7   r7   r8   r   s  s      zDTestCustomFormsSubmissionsList.test_list_submissions_filtering_rangec                 C   sz   |    | jtd| jjfdddi}| |jd | |d | |j	d j
d | j|dd	d
 | j|ddd d S )NrC   rD   r   r   r   r   r   rD  TrE  zgenerated-username-r   count)r   rH   r.   r   r0   rM   r   r   r   r   r   r   r   r7   r7   r8   r     s      z?TestCustomFormsSubmissionsList.test_list_submissions_paginationc                 C   s:   |    | jtd| jjfdddi}| |jd d S r   r   r   r7   r7   r8   r     s    zGTestCustomFormsSubmissionsList.test_list_submissions_pagination_invalidc                 C   s:   |    | jtd| jjfdddi}| |jd d S r   r   r   r7   r7   r8   r     s    zLTestCustomFormsSubmissionsList.test_list_submissions_pagination_out_of_rangeN)rX   rY   rZ   r:  r9   r   r   r   r   r   r   r   r   r7   r7   r7   r8   rC    s   rC  c                   @   sB   e Zd ZdgZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )TestDeleteFormSubmissionrl   c                 C   s"   | j ddd tjjdd| _d S rm   rq   rU   r7   r7   r8   r9     s    zTestDeleteFormSubmission.setUpc                 C   sN   | j td| jjfddtj j  }| |d | 	tj
 d d S )Nwagtailforms:delete_submissionsrD   ?selected-submissions= wagtailforms/confirm_delete.htmlr   )rH   r.   r   r0   rM   r   rf   firstr   r   rJ  r   r7   r7   r8   (test_delete_submission_show_confirmation  s    zATestDeleteFormSubmission.test_delete_submission_show_confirmationc                 C   s\   | j td| jjfddtj j  }| tj	 d | 
|td| jjfd d S )NrL  rD   rM  r   rC   )rH   rI   r   r0   rM   r   rf   rO  r   rJ  r   r   r7   r7   r8   'test_delete_submission_with_permissions  s    z@TestDeleteFormSubmission.test_delete_submission_with_permissionsc                 C   sf   | j td| jjfddtj jtj	 j }| 
tj d | |td| jjfd d S NrL  rD   z0?selected-submissions={}&selected-submissions={}r   rC   )rH   rI   r   r0   rM   r   r   rf   rO  lastr   rJ  r   r   r7   r7   r8   1test_delete_multiple_submissions_with_permissions  s    
 
zJTestDeleteFormSubmission.test_delete_multiple_submissions_with_permissionsc                 C   s\   | j ddd | jtd| jjfddtj j  }| 	|d | 
tj d d S )	Nr   r`   r^   rL  rD   rM  r   r   )rr   rH   rI   r   r0   rM   r   rf   rO  r   r   rJ  r   r7   r7   r8   &test_delete_submission_bad_permissions  s    z?TestDeleteFormSubmission.test_delete_submission_bad_permissionsc              	   C   s   dd }|  d|2 | jtd| jjfddtj j  }W 5 Q R X | 	|d | 
tj d | jtd| jjfdd	tj j }| 
tj d
 | 	|td| jjfd d S )Nc                 S   s   |  S r   r   r   r7   r7   r8   r     s    z}TestDeleteFormSubmission.test_delete_submission_after_filter_form_submissions_for_user_hook.<locals>.construct_forms_for_userr   rL  rD   rM  r   r   ?selected-submissions={}r   rC   )r   rH   rI   r   r0   rM   r   rf   rO  r   r   rJ  r   r   r   r7   r7   r8   Btest_delete_submission_after_filter_form_submissions_for_user_hook  s0     
z[TestDeleteFormSubmission.test_delete_submission_after_filter_form_submissions_for_user_hookN)
rX   rY   rZ   r   r9   rP  rQ  rT  rU  rW  r7   r7   r7   r8   rK    s   rK  c                   @   s:   e Zd ZdgZdd Zdd Zdd Zdd	 Zd
d ZdS )TestDeleteCustomFormSubmissionrl   c                 C   s"   | j ddd tjjdd| _d S )Nrn   r`   r^   z/home/contact-us-one-more-time/rp   rq   rU   r7   r7   r8   r9     s    z$TestDeleteCustomFormSubmission.setUpc                 C   sN   | j td| jjfddtj j }| 	|d | 
tj d d S )NrL  rD   rV  rN  r   )rH   r.   r   r0   rM   r   r   rf   rO  r   r   rJ  r   r7   r7   r8   rP    s    
zGTestDeleteCustomFormSubmission.test_delete_submission_show_confirmationc                 C   s\   | j td| jjfddtj j }| 	tj
 d | |td| jjfd d S )NrL  rD   rV  r   rC   )rH   rI   r   r0   rM   r   r   rf   rO  r   rJ  r   r   r7   r7   r8   rQ  "  s    
zFTestDeleteCustomFormSubmission.test_delete_submission_with_permissionsc                 C   sf   | j td| jjfddtj jtj	 j }| 
tj d | |td| jjfd d S rR  )rH   rI   r   r0   rM   r   r   rf   rO  rS  r   rJ  r   r   r7   r7   r8   rT  2  s    

	zPTestDeleteCustomFormSubmission.test_delete_multiple_submissions_with_permissionsc                 C   s\   | j ddd | jtd| jjfddtj	 j }| 
|d | tj d d S )	Nr   r`   r^   rL  rD   rV  r   r   )rr   rH   rI   r   r0   rM   r   r   rf   rO  r   r   rJ  r   r7   r7   r8   rU  C  s    
zETestDeleteCustomFormSubmission.test_delete_submission_bad_permissionsN)	rX   rY   rZ   r   r9   rP  rQ  rT  rU  r7   r7   r7   r8   rX    s   rX  c                   @   sD   e 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S )"TestFormsWithCustomSubmissionsListc                 C   s   | j |ddS r7  r8  r9  r7   r7   r8   r:  U  s    zATestFormsWithCustomSubmissionsList.create_test_user_without_adminc              	   C   sL  t jjdd}|jtddddddd	| _tjj| jd
dddd tjj| jddddd tjj| jddddd ddddg| _tjj| jddddd	| jd | 
d| _| 
d| _tjj| j| jd d!d"| jd d#d$}tjrd%|_nd&|_|  tjj| j| jd'd(d)| jd* d#d$}tjr2d+|_nd,|_|  |   d S )-N/home/rp   zWilly Wonka Chocolate Ideaszwilly-wonka-chocolate-ideaszwilly@wonka.comzinfo@wonka.comzChocolate Idea Submitted!r#   r$   r%   r&   r'   rx   r   r  emailTrd   r+  r,  r.  r/  r   Z	Chocolate
singleliner   ZIngredients	multilinezWhat is chocolate?ZMediocreMuch excitementWet my pants excited!r   zYour Excitementr(  ,)rd   r+  r,  r.  r/  r0  zuser-chocolate-maniaczuser-chocolate-guyr   White ChocolatezWhite colouringrA   	chocolateZingredientsyour_excitementrd   r/   re   z2017-10-01T12:00:00.000Zz2017-10-01T12:00:00r   Dark ChocolateZCharcoalr   z2017-01-01T12:00:00.000Zz2017-01-01T12:00:00)r   rf   r.   rz   r   r0   r   rg   r0  joinr:  test_user_1Ztest_user_2r   r   r   rh   ri   rr   )r6   	home_pagerj   r   r7   r7   r8   r9   X  s    	
	

z(TestFormsWithCustomSubmissionsList.setUpc                 C   sB   t dD ]4}t| j| jd| d| | jd dd}|  qdS )zEMake 100 submissions to test pagination on the forms submissions pagex   zfoo-%s@bar.comzChocolate No.%sr   )rA   re  rf  rg  N)ry   r   r0   rj  r0  ri   r   r7   r7   r8   r     s    	z8TestFormsWithCustomSubmissionsList.make_list_submissionsc                 C   sr   | j td| jjfd}| |jd | |d | t|j	d d | 
|d | 
|d | 
|d	 d S )
NrC   rD   r   r   r   r   r`  rc  rh  r   r   r7   r7   r8   r     s    z8TestFormsWithCustomSubmissionsList.test_list_submissionsc                 C   sv   |    | jtd| jjfdddi}| |jd | |d | 	|d | j	|dd	d
 | |j
d jd d S )NrC   rD   r   r   r   r   zPage 2 of 3ra  2   rI  r   )r   rH   r.   r   r0   rM   r   r   r   r   r   r   r   r7   r7   r8   r     s    zCTestFormsWithCustomSubmissionsList.test_list_submissions_paginationc                 C   s   | j td| jjfdddi}| |jd |  	d}| 
d| jj |d | |d	 d
 tjr| |d d | |d d n | |d d | |d d d S )NrC   rD   r   r   r   r   zfilename="%s-exportzContent-Dispositionr   zLUser email,Submission date,Your email,Chocolate,Ingredients,Your Excitementr   z|user-chocolate-maniac@example.com,2017-10-01 12:00:00+00:00,new@example.com,White Chocolate,White colouring,Much excitementr   ztuser-chocolate-guy@example.com,2017-01-01 12:00:00+00:00,old@example.com,Dark Chocolate,Charcoal,What is chocolate?zvuser-chocolate-maniac@example.com,2017-10-01 12:00:00,new@example.com,White Chocolate,White colouring,Much excitementznuser-chocolate-guy@example.com,2017-01-01 12:00:00,old@example.com,Dark Chocolate,Charcoal,What is chocolate?)rH   r.   r   r0   rM   r   r   r  r  r  rN   r$   r   r   r  r7   r7   r8   r
    s>    
zCTestFormsWithCustomSubmissionsList.test_list_submissions_csv_exportc                 C   st   t jj| j| dddd| jd dd}d|_|  | j	t
d	| jjfd
}|jd d d }| d| d S )Nzuser-aaa-aaar   zOld chocolate ideaZSugarr   rd  rg  z2016-01-01T12:00:00.000ZrC   rD   r   r   r)   )r   rf   rg   r0   r:  r0  rh   ri   rH   r.   r   rM   r   rN   )r6   Zform_submissionr   r   r7   r7   r8   test_list_submissions_ordering  s     
zATestFormsWithCustomSubmissionsList.test_list_submissions_orderingN)
rX   rY   rZ   r:  r9   r   r   r   r
  rn  r7   r7   r7   r8   rY  T  s   W%rY  c                   @   s   e Zd Zdd Zdd ZdS )-TestFormsWithCustomFormBuilderSubmissionsListc                 C   s   t jjdd}|jtddddddd	}tjj|d
dddd tjj|d
dddd tdD ]*}tjj|d| d| dd}|	  q\|| _
|   d S )NrZ  rp   zSupport Requestzsupport-requestzit@jenkins.comzsupport@jenkins.comzSupport Request Submittedr[  rx   r   Namer^  Tr]  zDevice IP Address	ipaddressr   zJohn %sz
192.0.2.%s)r   Zdevice_ip_addressr   )r   rf   r.   rz   r   r   rg   ry   r   ri   r0   rr   )r6   rk  r0   r|   r   r7   r7   r8   r9     sD    	
z3TestFormsWithCustomFormBuilderSubmissionsList.setUpc                 C   sf   | j td| jjfd}| |jd | |d | t|j	d d | 
|d | 
|d d S )	NrC   rD   r   r   r   r   z	192.0.2.1z
192.0.2.15r   r   r7   r7   r8   r   ?  s    zCTestFormsWithCustomFormBuilderSubmissionsList.test_list_submissionsN)rX   rY   rZ   r9   r   r7   r7   r7   r8   ro    s   'ro  c                   @   s>   e Zd ZdZdgZdd Zdd Zdd Zd	d
 Zdd Z	dS )TestDuplicateFormFieldLabelsz
    If a user creates two fields with the same label, data cannot be saved correctly.
    See: https://github.com/wagtail/wagtail/issues/585
    rl   c                 C   s"   | j ddd tjjdd| _d S )Nr   r`   r^   r   rM   )rr   r   rf   r.   	root_pagerU   r7   r7   r8   r9   V  s    z"TestDuplicateFormFieldLabels.setUpc                 C   sf   dddddddddd	ddd	dd
d	d}| j tddd| jjfd|}| |jd | j|dd d S )N
Form page!Some content
contact-us301000r;   r=   r^  r>   r#   r   r$   form_fields-TOTAL_FORMSform_fields-INITIAL_FORMSform_fields-MIN_NUM_FORMSform_fields-MAX_NUM_FORMSform_fields-0-idform_fields-0-labelform_fields-0-field_typezform_fields-1-idzform_fields-1-labelzform_fields-1-field_typezform_fields-2-idzform_fields-2-labelzform_fields-2-field_typewagtailadmin_pages:addtestsformpagerD   r   zEThere is another field with the label foo, please change one of them.textrH   rI   r   rt  rM   r   r   r   r6   	post_datar   r7   r7   r8   !test_adding_duplicate_form_labels[  s:     z>TestDuplicateFormFieldLabels.test_adding_duplicate_form_labelsc                 C   sf   dddddddddd	dd
d	ddd	d}| j tddd| jjfd|}| |jd | j|dd dS )z
        Ensure form submission fails when attempting to create labels that will resolve
        to the same internal clean_name on the form field.
        ru  rv  rw  rx  ry  rz  r;   zLOW EARTH ORBITr^  zlow earth orbitr>   r{  r  r  r  rD   r   zQThere is another field with the label LOW EARTH ORBIT, please change one of them.r  Nr  r  r7   r7   r8   1test_adding_duplicate_form_labels_as_cleaned_name|  s:     zNTestDuplicateFormFieldLabels.test_adding_duplicate_form_labels_as_cleaned_namec                 C   sf   dddddddddd	dd
d	ddd	d}| j tddd| jjfd|}| |jd | j|dd dS )z
        Ensure form submission fails when attempting to create labels that will resolve
        to the same clean_name that already exists when using a custom `get_field_clean_name` method
        ru  rv  rw  rx  ry  rz  r;   zduplicate 1r^  zduplicate 2r>   r{  r  r  ZformpagewithcustomformbuilderrD   r   zMThere is another field with the label duplicate 1, please change one of them.r  Nr  r  r7   r7   r8   ;test_adding_duplicate_form_labels_using_override_clean_name  s:    zXTestDuplicateFormFieldLabels.test_adding_duplicate_form_labels_using_override_clean_namec              	   C   s   t dtdddgd}| jj|d tddt|j jddd	d
ddd	gdddd}| j	
td|jgd|}| |jd | j|dd dS )zLEnsure duplicate field names are checked against existing field clean_names.ru  z
Test fieldr^  )r,  r.  )r#   form_fieldsrx   z	form-pagezOther field)rM   r,  r.  r;   r   )initialaction-publish)r#   r$   r  r  wagtailadmin_pages:editrD   r   zLThere is another field with the label Test field, please change one of them.r  N)r   r   rt  rz   r   r   r  rO  pkrH   rI   r   r   r   r   )r6   r0   r  r   r7   r7   r8   Etest_rename_existing_field_and_add_new_field_with_clashing_clean_name  s:    

 zbTestDuplicateFormFieldLabels.test_rename_existing_field_and_add_new_field_with_clashing_clean_nameN)
rX   rY   rZ   __doc__r   r9   r  r  r  r  r7   r7   r7   r8   rr  N  s   !&'rr  c                   @   s>   e Zd Zdddddddddd	d

Zdd Zdd Zdd ZdS )TestPreviewru  rv  rw  1ry  rz  r;   	Field Oner^  )
r#   r   r$   r|  r}  r~  r  r  r  r  c                 C   s   |    tjjdd| _d S Nr   rs  )rr   r   rf   r.   homepagerU   r7   r7   r8   r9      s    zTestPreview.setUpc                 C   s   t ddd| jjfd}| j|| j}| |jd | |j	
 ddd | j|}| |d | |d	 | |d
 d S )N!wagtailadmin_pages:preview_on_addr  r  rD   r   TZis_validZis_availablez*<form action="/contact-us/" method="post">z+<label for="id_field_one">Field One</label>zF<input type="text" name="field_one" maxlength="255" id="id_field_one">)r   r  r  rH   rI   r  r   r   assertJSONEqualr   r  r.   r   )r6   preview_urlr   r7   r7   r8   test_form_is_rendered  s"    z!TestPreview.test_form_is_renderedc              
   C   s   t ddd| jjfd}| jj|| jd}| |jd | |j	
 ddd d	d
dg}|D ]L\}}| j||d0 | j|| }| |jd | || W 5 Q R X q\d S )Nr  r  r  rD   )datar   Tr  )r;   tests/form_page.html)z
?mode=formr  )z?mode=landingztests/form_page_landing.html)r   template)r   r  r  rH   rI   r  r   r   r  r   r  r   r.   r   )r6   r  r   Zcasesr   r  r7   r7   r8   test_preview_modes  s&    zTestPreview.test_preview_modesN)rX   rY   rZ   r  r9   r  r  r7   r7   r7   r8   r    s   r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestFormPageCreatec                 C   s   t jjdd| _|  | _d S r  )r   rf   r.   rt  rr   r/   rU   r7   r7   r8   r9   6  s    zTestFormPageCreate.setUpc                 C   s0   | j tddd| jjfd}| |jd d S )Nr  r  r  rD   r   )rH   r.   r   rt  rM   r   r   r   r7   r7   r8   test_get_creation_form=  s    z)TestFormPageCreate.test_get_creation_formc              
   C   sb   dddddddddd		}| j td
dd| jjfd|}tjjdd}| |td|jfd d S )Nru  rw  r  ry  rz  r;   r  r^  	r#   r$   r|  r}  r~  r  r  r  r  r  r  r  rD   r$   r  )	rH   rI   r   rt  rM   r   rf   r.   r   r6   r  r   rd   r7   r7   r8   test_post_creation_formF  s,     z*TestFormPageCreate.test_post_creation_formN)rX   rY   rZ   r9   r  r  r7   r7   r7   r8   r  5  s   	r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestFormPageEditc                 C   s   t  | _|  | _d S r   )r   r0   rr   r/   rU   r7   r7   r8   r9   c  s    zTestFormPageEdit.setUpc                 C   s,   | j td| jjfd}| |jd d S )Nr  rD   r   )rH   r.   r   r0   rM   r   r   r   r7   r7   r8   test_get_edit_formi  s    z#TestFormPageEdit.test_get_edit_formc              
   C   sr   dddddddddd		}| j td
| jjfd|}| |td
| jjfd tjjdd	 }| 
|jd d S )NzUpdated form pagerw  r  ry  rz  r;   r  r^  r  r  rD   r  )rH   rI   r   r0   rM   r   r   rf   r.   Zget_latest_revision_as_objectr   r#   r  r7   r7   r8   test_post_edit_formo  s(     z$TestFormPageEdit.test_post_edit_formN)rX   rY   rZ   r9   r  r  r7   r7   r7   r8   r  b  s   r  )Ar  ior   Zdjango.confr   Zdjango.contrib.auth.modelsr   Zdjango.testr   r   r   Zdjango.urlsr   Zdjango.utils.htmlr	   Zdjango.utils.httpr
   Zopenpyxlr   Zwagtail.admin.formsr   Zwagtail.admin.panelsr   Zwagtail.contrib.forms.modelsr   Zwagtail.contrib.forms.panelsr   Z!wagtail.contrib.forms.tests.utilsr   r   Zwagtail.modelsr   r   Zwagtail.test.testapp.modelsr   r   r   r   r   r   r   r   r   Zwagtail.test.utilsr   Zwagtail.test.utils.form_datar   r   r    r[   r\   rk   r   r   r   r6  rC  rK  rX  rY  ro  rr  r  r  r  r7   r7   r7   r8   <module>   sT   ,+1aX >  3 P "]G D7 %C-