# Path: tests/base.py
# class BreadTestCase(TestCase):
#     url_namespace = ""
#     extra_bread_attributes = {}
# 
#     def setUp(self):
#         self.username = "joe"
#         self.password = "random"
#         User = get_user_model()
#         self.user = User.objects.create_user(username=self.username)
#         self.user.set_password(self.password)
#         self.user.save()
#         assert self.client.login(username=self.username, password=self.password)
#         self.model = BreadTestModel
#         self.model_name = self.model._meta.model_name
#         self.model_factory = BreadTestModelFactory
#         self.request_factory = RequestFactory()
# 
#         class ReadClass(ReadView):
#             columns = [
#                 ("Name", "name"),
#                 ("Text", "other__text"),
#                 (
#                     "Model1",
#                     "model1",
#                 ),
#             ]
# 
#         class BrowseClass(BrowseView):
#             columns = [
#                 ("Name", "name"),
#                 ("Text", "other__text"),
#                 (
#                     "Model1",
#                     "model1",
#                 ),
#             ]
# 
#         class BreadTestClass(Bread):
#             model = self.model
#             base_template = "bread/empty.html"
#             browse_view = BrowseClass
#             namespace = self.url_namespace
#             plural_name = "testmodels"
# 
#             def get_additional_context_data(self):
#                 context = super(BreadTestClass, self).get_additional_context_data()
#                 context["bread_test_class"] = True
#                 return context
# 
#         for k, v in self.extra_bread_attributes.items():
#             setattr(BreadTestClass, k, v)
# 
#         self.BreadTestClass = BreadTestClass
#         self.bread = BreadTestClass()
# 
#     def tearDown(self):
#         global urlpatterns
#         urlpatterns = None
# 
#     def set_urls(self, bread):
#         # Given a bread instance, set its URLs on the test urlconf
#         global urlpatterns
#         urlpatterns = bread.get_urls()
# 
#     def get_permission(self, short_name):
#         """Return a Permission object for the test model.
#         short_name should be browse, read, edit, add, or delete.
#         """
#         return Permission.objects.get_or_create(
#             content_type=ContentType.objects.get_for_model(self.model),
#             codename="%s_%s" % (short_name, self.model_name),
#         )[0]
# 
#     def give_permission(self, short_name):
#         self.user.user_permissions.add(self.get_permission(short_name))


from .base import BreadTestCase

class BreadTemplateResolutionTest(BreadTestCase):
    def setUp(self):
        super(BreadTemplateResolutionTest, self).setUp()
        # skip 'add' since it uses 'edit' template
        self.bread_names = ["browse", "read", "edit", "delete"]
        self.app_name = self.model._meta.app_label

    def test_default_template_resolution(self):
        for bread_name in self.bread_names:
            vanilla_template_name = "%s/%s_%s.html" % (
                self.app_name,
                self.model_name,
                bread_name,
            )
            default_bread_template_name = "bread/%s.html" % (bread_name,)
            expected_templates = [
                vanilla_template_name,
                default_bread_template_name,
            ]
            get_method_name = "%s_view" % (bread_name,)
            view_class = getattr(self.bread, get_method_name)
            view = view_class(bread=self.bread, model=self.bread.model)
            self.assertEqual(view.get_template_names(), expected_templates)

    def test_customized_template_resolution(self):
        self.bread.template_name_pattern = "mysite/bread/{view}.html"

        for bread_name in self.bread_names:
            vanilla_template_name = "%s/%s_%s.html" % (

# Path: tests/base.py
# class BreadTestCase(TestCase):
#     url_namespace = ""
#     extra_bread_attributes = {}
# 
#     def setUp(self):
#         self.username = "joe"
#         self.password = "random"
#         User = get_user_model()
#         self.user = User.objects.create_user(username=self.username)
#         self.user.set_password(self.password)
#         self.user.save()
#         assert self.client.login(username=self.username, password=self.password)
#         self.model = BreadTestModel
#         self.model_name = self.model._meta.model_name
#         self.model_factory = BreadTestModelFactory
#         self.request_factory = RequestFactory()
# 
#         class ReadClass(ReadView):
#             columns = [
#                 ("Name", "name"),
#                 ("Text", "other__text"),
#                 (
#                     "Model1",
#                     "model1",
#                 ),
#             ]
# 
#         class BrowseClass(BrowseView):
#             columns = [
#                 ("Name", "name"),
#                 ("Text", "other__text"),
#                 (
#                     "Model1",
#                     "model1",
#                 ),
#             ]
# 
#         class BreadTestClass(Bread):
#             model = self.model
#             base_template = "bread/empty.html"
#             browse_view = BrowseClass
#             namespace = self.url_namespace
#             plural_name = "testmodels"
# 
#             def get_additional_context_data(self):
#                 context = super(BreadTestClass, self).get_additional_context_data()
#                 context["bread_test_class"] = True
#                 return context
# 
#         for k, v in self.extra_bread_attributes.items():
#             setattr(BreadTestClass, k, v)
# 
#         self.BreadTestClass = BreadTestClass
#         self.bread = BreadTestClass()
# 
#     def tearDown(self):
#         global urlpatterns
#         urlpatterns = None
# 
#     def set_urls(self, bread):
#         # Given a bread instance, set its URLs on the test urlconf
#         global urlpatterns
#         urlpatterns = bread.get_urls()
# 
#     def get_permission(self, short_name):
#         """Return a Permission object for the test model.
#         short_name should be browse, read, edit, add, or delete.
#         """
#         return Permission.objects.get_or_create(
#             content_type=ContentType.objects.get_for_model(self.model),
#             codename="%s_%s" % (short_name, self.model_name),
#         )[0]
# 
#     def give_permission(self, short_name):
#         self.user.user_permissions.add(self.get_permission(short_name))


# Path: tests/test_templates.py
from .base import BreadTestCase


class BreadTemplateResolutionTest(BreadTestCase):
    def setUp(self):
        super(BreadTemplateResolutionTest, self).setUp()
        # skip 'add' since it uses 'edit' template
        self.bread_names = ["browse", "read", "edit", "delete"]
        self.app_name = self.model._meta.app_label

    def test_default_template_resolution(self):
        for bread_name in self.bread_names:
            vanilla_template_name = "%s/%s_%s.html" % (
                self.app_name,
                self.model_name,
                bread_name,
            )
            default_bread_template_name = "bread/%s.html" % (bread_name,)
            expected_templates = [
                vanilla_template_name,
                default_bread_template_name,
            ]
            get_method_name = "%s_view" % (bread_name,)
            view_class = getattr(self.bread, get_method_name)
            view = view_class(bread=self.bread, model=self.bread.model)
            self.assertEqual(view.get_template_names(), expected_templates)

    def test_customized_template_resolution(self):
        self.bread.template_name_pattern = "mysite/bread/{view}.html"

        for bread_name in self.bread_names:
            vanilla_template_name = "%s/%s_%s.html" % (

                self.app_name,