# Path: basic_cms/checks.py
# @register()
# def page_templates_loading_check(app_configs, **kwargs):
#     """ Check if any page template can't be loaded. """
#     errors = []
# 
#     for page_template in settings.PAGE_TEMPLATES:
#         try:
#             loader.get_template(page_template[0])
#         except template.TemplateDoesNotExist:
#             errors.append(checks.Warning(
#                     'Django cannot find template %s' % page_template[0],
#                     obj=page_template, id='basic_cms.W001'))
# 
#     return errors


from basic_cms.checks import page_templates_loading_check
from django.test import TestCase
from django.core.checks import Warning
from django.template import TemplateSyntaxError



class PageTemplatesLoadingCheckTestCase(TestCase):
    def test_check_detects_unexistant_template(self):
        unexistant = ('does_not_exists.html', 'foo')
        with self.settings(PAGE_TEMPLATES=[unexistant]):
            errors = page_templates_loading_check([])
        
        self.assertEqual(errors, [Warning(
            'Django cannot find template does_not_exists.html',
            obj=unexistant, id='basic_cms.W001')])

    def test_check_doesnt_warn_on_existing_templates(self):
        with self.settings(PAGE_TEMPLATES=[('pages/base.html', 'bas')]):
            errors = page_templates_loading_check([])

        self.assertEquals(errors, [])

    def test_template_syntax_error_is_not_silenced(self):
        with self.settings(PAGE_TEMPLATES=[('syntax_error.html', 'fail')]):
            with self.assertRaises(TemplateSyntaxError):

# Path: basic_cms/checks.py
# @register()
# def page_templates_loading_check(app_configs, **kwargs):
#     """ Check if any page template can't be loaded. """
#     errors = []
# 
#     for page_template in settings.PAGE_TEMPLATES:
#         try:
#             loader.get_template(page_template[0])
#         except template.TemplateDoesNotExist:
#             errors.append(checks.Warning(
#                     'Django cannot find template %s' % page_template[0],
#                     obj=page_template, id='basic_cms.W001'))
# 
#     return errors


# Path: basic_cms/tests/test_checks.py
from basic_cms.checks import page_templates_loading_check
from django.test import TestCase
from django.core.checks import Warning
from django.template import TemplateSyntaxError




class PageTemplatesLoadingCheckTestCase(TestCase):
    def test_check_detects_unexistant_template(self):
        unexistant = ('does_not_exists.html', 'foo')
        with self.settings(PAGE_TEMPLATES=[unexistant]):
            errors = page_templates_loading_check([])
        
        self.assertEqual(errors, [Warning(
            'Django cannot find template does_not_exists.html',
            obj=unexistant, id='basic_cms.W001')])

    def test_check_doesnt_warn_on_existing_templates(self):
        with self.settings(PAGE_TEMPLATES=[('pages/base.html', 'bas')]):
            errors = page_templates_loading_check([])

        self.assertEquals(errors, [])

    def test_template_syntax_error_is_not_silenced(self):
        with self.settings(PAGE_TEMPLATES=[('syntax_error.html', 'fail')]):
            with self.assertRaises(TemplateSyntaxError):

                page_templates_loading_check([])