# 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 django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import PermissionDenied
from django.test import override_settings
from django.urls import reverse
from .base import BreadTestCase
        # Can't do it when logged in but no permission, get 403
        with self.assertRaises(PermissionDenied):
            if self.expects_pk:
                self.view(self.request, pk=self.item.pk)
            else:
                self.view(self.request)
        if self.include_post:
            with self.assertRaises(PermissionDenied):
                if self.expects_pk:
                    self.view(self.post_request, pk=self.item.pk)
                else:
                    self.view(self.post_request)


class BreadBrowsePermissionTest(BreadPermissionTestMixin, BreadTestCase):
    view_name = "browse"
    expects_pk = False


class BreadReadPermissionTest(BreadPermissionTestMixin, BreadTestCase):
    view_name = "read"
    expects_pk = True


class BreadEditPermissionTest(BreadPermissionTestMixin, BreadTestCase):
    view_name = "edit"
    expects_pk = True
    include_post = True



# 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_permissions.py
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import PermissionDenied
from django.test import override_settings
from django.urls import reverse
from .base import BreadTestCase

        # Can't do it when logged in but no permission, get 403
        with self.assertRaises(PermissionDenied):
            if self.expects_pk:
                self.view(self.request, pk=self.item.pk)
            else:
                self.view(self.request)
        if self.include_post:
            with self.assertRaises(PermissionDenied):
                if self.expects_pk:
                    self.view(self.post_request, pk=self.item.pk)
                else:
                    self.view(self.post_request)


class BreadBrowsePermissionTest(BreadPermissionTestMixin, BreadTestCase):
    view_name = "browse"
    expects_pk = False


class BreadReadPermissionTest(BreadPermissionTestMixin, BreadTestCase):
    view_name = "read"
    expects_pk = True


class BreadEditPermissionTest(BreadPermissionTestMixin, BreadTestCase):
    view_name = "edit"
    expects_pk = True
    include_post = True



class BreadAddPermissionTest(BreadPermissionTestMixin, BreadTestCase):