U
    |h                     @   s   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 d dlmZ d dlmZ G d	d
 d
eeZedejg dG dd deZdS )    )mock)TestCase)reverse)get_dummy_request)PageSite)
SimplePage)WagtailTestUtils)servec                   @   s2   e Zd ZdgZdd Zdd Zdd Zdd	 Zd
S )TestLoginView	test.jsonc                 C   s   |   | _tjjdd| _d S )Nz/home/events/)Zurl_path)Zcreate_test_useruserr   objectsgetevents_index)self r   `/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/tests/test_views.pysetUp   s    
zTestLoginView.setUpc                 C   s:   | j td}| |jd | |d | |d d S )Nwagtailcore_login   <h1>Log in</h1>A<p>Your username and password didn't match. Please try again.</p>)clientr   r   assertEqualstatus_codeassertContainsZassertNotContainsr   responser   r   r   test_get   s    zTestLoginView.test_getc                 C   sH   | j tddd| jjd}| |jd | |d | |d d S )Nr   test@email.comZwrongpasswordusernamepasswordnextr   r   r   )r   postr   r   urlr   r   r   r   r   r   r   test_post_incorrect_password   s    z*TestLoginView.test_post_incorrect_passwordc                 C   s2   | j tddd| jjd}| || jj d S )Nr   r    r#   r!   )r   r%   r   r   r&   ZassertRedirectsr   r   r   r   test_post_correct_password-   s    z(TestLoginView.test_post_correct_passwordN)__name__
__module____qualname__fixturesr   r   r'   r(   r   r   r   r   r      s
   	r   zwagtail.hooks.get_hooks)Zreturn_valuec                   @   s"   e Zd ZdgZdd Zdd ZdS )TestServeViewr   c              
   C   sz   t  }t| t||j\}}}tjj|d|j	d8}| 
d t	|d W 5 Q R X |j|f|| W 5 Q R X d S )Nr
   wrapsr   /)r   r   Zfind_for_requestr   route_for_requestpathr   patchobjectr
   assertNumQueriesZassert_called_once_with)r   requestpageargskwargsmr   r   r   test_serve_query_count=   s    
z$TestServeView.test_serve_query_countc                 C   s   d}t j }|jjtddddd}tjjt	dt	j
d}| jd	d
id | | | jd}W 5 Q R X | |jd | |jd d|_|   |  | | | jd}W 5 Q R X | |jd | |jd W 5 Q R X W 5 Q R X d S )N   zSimple pagesimpleZSimple)titleZslugcontent)instancer1   r.   prependz;wagtail.test.middleware.SimplePageViewInterceptorMiddleware)Z
MIDDLEWAREz/simple/s   



<!DOCTYPE HTML>
<html lang="en" dir="ltr">
    <head>
        <title>Simple page</title>
    </head>
    <body>
        
        <h1>Simple page</h1>
        
    <h2>Simple page</h2>

    </body>
</html>
   zIntercept mes   Intercepted   )r   r   r   Z	root_pageZ	add_childr   r   r3   r4   r   r1   Zmodify_settingsr5   r   r   r?   Z
call_countZsave_revisionpublishZ
reset_mock)r   Zexpected_query_countsiter7   r:   Z
response_aZ
response_br   r   r   %test_process_view_by_page_query_countF   s<    
   z3TestServeView.test_process_view_by_page_query_countN)r)   r*   r+   r,   r;   rF   r   r   r   r   r-   9   s   	r-   N)Zunittestr   Zdjango.testr   Zdjango.urlsr   Zwagtail.coreutilsr   Zwagtail.modelsr   r   Zwagtail.test.testapp.modelsr   Zwagtail.test.utilsr	   Zwagtail.viewsr
   r   r3   ZMockr-   r   r   r   r   <module>   s   ,