U
    {hR                     @   s   d dl mZ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 ed	d
dgdG dd deeeZG dd deZG dd deZG dd deZdS )    )ContextRequestContextTemplateengines)TestCase)override_settings)get_dummy_request)Site)WagtailTestUtils   )GenericSettingsTestMixinZ
testserver	localhostother)ZALLOWED_HOSTSc                   @   s   e Zd ZdddZdS )GenericSettingTemplateTestCaseNc                 C   s   t |}t||}||S )N)r   r   render)selfrequeststringcontexttemplate r   }/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/contrib/settings/tests/generic/test_templates.pyr      s    
z%GenericSettingTemplateTestCase.render)N)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )&GenericSettingContextProcessorTestCasec                 C   s$   |   }| | |d| jj dS )&Check that the context processor works-{{ settings.tests.TestGenericSetting.title }}Nget_requestassertEqualr   default_settingstitler   r   r   r   r   test_accessing_setting   s
    
z=GenericSettingContextProcessorTestCase.test_accessing_settingc                 C   sl   |   }| | |d| jj | | |d| jj | | |d| jj | | |d| jj dS )&Model names should be case insensitive-{{ settings.tests.testgenericsetting.title }}z-{{ settings.tests.TESTGENERICSETTING.title }}r   z-{{ settings.tests.tEstgEnerICsEttIng.title }}Nr   r#   r   r   r   test_model_case_insensitive   s"    



zBGenericSettingContextProcessorTestCase.test_model_case_insensitivec                 C   sx   |   }d}t| | dN tddD ]<}| j|d& | | ||| | jj	|  W 5 Q R X q,W 5 Q R X dS )zAccessing a setting should only hit the DB once per request instance,
        even if using that request to rendering multiple timesr&   r      )attemptN)
r   r	   find_for_requestassertNumQueriesrangeZsubTestr    r   r!   r"   )r   r   	get_titleir   r   r   test_models_cached3   s    

z9GenericSettingContextProcessorTestCase.test_models_cachedN)r   r   r   r$   r'   r/   r   r   r   r   r      s   r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
!GenericSettingTemplateTagTestCasec                 C   s$   t d}t }| ||d dS )z{
        Assert that not running the context processor means settings are not in
        the context, as expected.
        r    N)r   r   r    r   )r   r   r   r   r   r   test_no_context_processorF   s    z;GenericSettingTemplateTagTestCase.test_no_context_processorc                 C   s6   |   }td|i}td}| ||| jj dS )z+Check that the {% get_settings %} tag worksr   ^{% load wagtailsettings_tags %}{% get_settings %}{{ settings.tests.testgenericsetting.title }}Nr   r   r   r    r   r!   r"   r   r   r   r   r   r   r   !test_get_settings_request_contextO   s    zCGenericSettingTemplateTagTestCase.test_get_settings_request_contextc                 C   s(   t  }td}| ||| jj dS )z;Check that the {% get_settings %} tag works with no requestr3   N)r   r   r    r   r!   r"   r   r   r   r   r   r   test_get_settings_no_request\   s
    z>GenericSettingTemplateTagTestCase.test_get_settings_no_requestc                 C   sP   |   }td|i}td}| ||| jj td}| ||d dS )z
        Check that assigning the setting to a context variable with
        {% get_settings as wagtail_settings %} works.
        r   zz{% load wagtailsettings_tags %}{% get_settings as wagtail_settings %}{{ wagtail_settings.tests.testgenericsetting.title }}zr{% load wagtailsettings_tags %}{% get_settings as wagtail_settings %}{{ settings.tests.testgenericsetting.title }}r1   Nr4   r5   r   r   r   5test_get_settings_variable_assignment_request_contexth   s    zWGenericSettingTemplateTagTestCase.test_get_settings_variable_assignment_request_contextN)r   r   r   r2   r6   r8   r9   r   r   r   r   r0   E   s   	r0   c                       sF   e Zd Z fddZdddZdd Zd	d
 Zdd Zdd Z  Z	S )+GenericSettingJinjaContextProcessorTestCasec                    s   t    td | _d S )NZjinja2)supersetUpr   enginer   	__class__r   r   r<      s    
z1GenericSettingJinjaContextProcessorTestCase.setUpNTc                 C   sB   |d kri }|r,t jjdd}t|d|d< | j|}||S )NT)Zis_default_site)siter   )r	   objectsgetr   r=   from_stringr   )r   r   r   request_contextrA   r   r   r   r   r      s    z2GenericSettingJinjaContextProcessorTestCase.renderc                 C   s   |  | d| jj dS )r   0{{ settings("tests.TestGenericSetting").title }}Nr    r   r!   r"   r>   r   r   r   r$      s    zBGenericSettingJinjaContextProcessorTestCase.test_accessing_settingc                 C   s\   |  | d| jj |  | d| jj |  | d| jj |  | d| jj dS )r%   0{{ settings("tests.testgenericsetting").title }}z0{{ settings("tests.TESTGENERICSETTING").title }}rF   z0{{ settings("tests.tEstgEnerICsEttIng").title }}NrG   r>   r   r   r   r'      s     zGGenericSettingJinjaContextProcessorTestCase.test_model_case_insensitivec              
   C   sr   d}|   }t| tddD ]L}| d8 d|i}| j|| }| ||| j	j
|  W 5 Q R X q dS )z:Accessing a setting should only hit the DB once per renderrH   r   r(   r   N)r   r	   r*   r,   r+   r=   rD   r    r   r!   r"   )r   r-   r   r.   r   r   r   r   r   r/      s    
 
z>GenericSettingJinjaContextProcessorTestCase.test_models_cachedc                 C   s(   i }d}|  | j||dd| jj dS )zu
        Check that {{ settings }} does not throw an error if it can not find a
        request to work with
        rH   F)rE   NrG   r7   r   r   r   test_settings_no_request   s    zDGenericSettingJinjaContextProcessorTestCase.test_settings_no_request)NT)
r   r   r   r<   r   r$   r'   r/   rI   __classcell__r   r   r?   r   r:      s   
r:   N)Zdjango.templater   r   r   r   Zdjango.testr   Zdjango.test.utilsr   Zwagtail.coreutilsr   Zwagtail.modelsr	   Zwagtail.test.utilsr
   baser   r   r   r0   r:   r   r   r   r   <module>   s   
  	/: