# Path: incuna_test_utils/compat.py
# DJANGO_GTE_19 = django.VERSION >= (1, 9)
# 
# Path: incuna_test_utils/testcases/integration.py
# class BaseAdminIntegrationTestCase(TestCase):
#     """Base class to test the admin.
# 
#     Provide methods to access `add`, `changelist`, `change` and `delete` pages.
# 
#     Must be subclassed with the following attributes in order to work:
#       * `user_factory` which defines a 'FactoryBoy' User factory to authenticate
#     the client;
#       * `model` which defines the model to test.
#     """
#     def setUp(self):
#         """Create a user and authenticate it on the client."""
#         admin_user = self.user_factory.create()
#         logged_in = self.client.login(
#             username=admin_user.get_username(),
#             password=admin_user.raw_password,
#         )
#         self.assertTrue(logged_in)
# 
#     def get_url_name(self, action):
#         """Generate admin url name for `self.model`."""
#         return 'admin:{app}_{model}_{action}'.format(
#             app=self.model._meta.app_label,
#             model=self.model._meta.object_name.lower(),
#             action=action,
#         )
# 
#     def get_admin_page(self, page, args=None):
#         """Generic method to `GET` an admin page."""
#         url_name = self.get_url_name(page)
#         return self.client.get(reverse(url_name, args=args))
# 
#     def get_admin_add_page(self):
#         """`GET` the add page for the model admin."""
#         return self.get_admin_page('add')
# 
#     def get_admin_changelist_page(self):
#         """`GET` the changelist page for the model admin."""
#         return self.get_admin_page('changelist')
# 
#     def get_admin_change_page(self, obj):
#         """`GET` the object change page for the model admin."""
#         return self.get_admin_page('change', (obj.pk,))
# 
#     def get_admin_delete_page(self, obj):
#         """`GET` the object delete page for the model admin."""
#         return self.get_admin_page('delete', (obj.pk,))
# 
# Path: tests/factories.py
# class AdminFactory(BaseAdminUserFactory):
#     username = factory.Sequence('User {}'.format)
# 
#     class Meta:
#         model = User
# 
# Path: tests/models.py
# class User(models.Model):
#     email = models.CharField(max_length=255)
#     name = models.CharField(max_length=255)
# 
#     USERNAME_FIELD = 'email'


from unittest import skipIf, skipUnless
from incuna_test_utils.compat import DJANGO_GTE_19
from incuna_test_utils.testcases.integration import BaseAdminIntegrationTestCase
from tests.factories import AdminFactory
from tests.models import User
import mock
        super(AdminIntegrationTestCase, self).setUp()
        self.client.get = mock.MagicMock()

    def test_get_url_name(self):
        """Assert url name generated is correct."""
        action = 'cleaning'
        url_name = self.get_url_name(action)
        expected = 'admin:tests_user_cleaning'

        self.assertEqual(url_name, expected)

    def test_get_admin_add_page(self):
        """Assert the right page is called when adding a record."""
        self.get_admin_add_page()
        self.client.get.assert_called_with('/admin/tests/user/add/')

    def test_get_admin_changelist_page(self):
        """Assert the right page is called when listing records."""
        self.get_admin_changelist_page()
        self.client.get.assert_called_with('/admin/tests/user/')

    @skipIf(DJANGO_GTE_19, "Django 1.9 has updated the admin url.")
    def test_get_admin_change_page_django_lte_19(self):
        """Assert the right page is called when changing a record."""
        user = self.user_factory.create()

        self.get_admin_change_page(user)
        expected = '/admin/tests/user/{}/'.format(user.pk)
        self.client.get.assert_called_with(expected)


# Path: incuna_test_utils/compat.py
# DJANGO_GTE_19 = django.VERSION >= (1, 9)
# 
# Path: incuna_test_utils/testcases/integration.py
# class BaseAdminIntegrationTestCase(TestCase):
#     """Base class to test the admin.
# 
#     Provide methods to access `add`, `changelist`, `change` and `delete` pages.
# 
#     Must be subclassed with the following attributes in order to work:
#       * `user_factory` which defines a 'FactoryBoy' User factory to authenticate
#     the client;
#       * `model` which defines the model to test.
#     """
#     def setUp(self):
#         """Create a user and authenticate it on the client."""
#         admin_user = self.user_factory.create()
#         logged_in = self.client.login(
#             username=admin_user.get_username(),
#             password=admin_user.raw_password,
#         )
#         self.assertTrue(logged_in)
# 
#     def get_url_name(self, action):
#         """Generate admin url name for `self.model`."""
#         return 'admin:{app}_{model}_{action}'.format(
#             app=self.model._meta.app_label,
#             model=self.model._meta.object_name.lower(),
#             action=action,
#         )
# 
#     def get_admin_page(self, page, args=None):
#         """Generic method to `GET` an admin page."""
#         url_name = self.get_url_name(page)
#         return self.client.get(reverse(url_name, args=args))
# 
#     def get_admin_add_page(self):
#         """`GET` the add page for the model admin."""
#         return self.get_admin_page('add')
# 
#     def get_admin_changelist_page(self):
#         """`GET` the changelist page for the model admin."""
#         return self.get_admin_page('changelist')
# 
#     def get_admin_change_page(self, obj):
#         """`GET` the object change page for the model admin."""
#         return self.get_admin_page('change', (obj.pk,))
# 
#     def get_admin_delete_page(self, obj):
#         """`GET` the object delete page for the model admin."""
#         return self.get_admin_page('delete', (obj.pk,))
# 
# Path: tests/factories.py
# class AdminFactory(BaseAdminUserFactory):
#     username = factory.Sequence('User {}'.format)
# 
#     class Meta:
#         model = User
# 
# Path: tests/models.py
# class User(models.Model):
#     email = models.CharField(max_length=255)
#     name = models.CharField(max_length=255)
# 
#     USERNAME_FIELD = 'email'


# Path: tests/testcases/test_admin_request.py
from unittest import skipIf, skipUnless
from incuna_test_utils.compat import DJANGO_GTE_19
from incuna_test_utils.testcases.integration import BaseAdminIntegrationTestCase
from tests.factories import AdminFactory
from tests.models import User
import mock

        super(AdminIntegrationTestCase, self).setUp()
        self.client.get = mock.MagicMock()

    def test_get_url_name(self):
        """Assert url name generated is correct."""
        action = 'cleaning'
        url_name = self.get_url_name(action)
        expected = 'admin:tests_user_cleaning'

        self.assertEqual(url_name, expected)

    def test_get_admin_add_page(self):
        """Assert the right page is called when adding a record."""
        self.get_admin_add_page()
        self.client.get.assert_called_with('/admin/tests/user/add/')

    def test_get_admin_changelist_page(self):
        """Assert the right page is called when listing records."""
        self.get_admin_changelist_page()
        self.client.get.assert_called_with('/admin/tests/user/')

    @skipIf(DJANGO_GTE_19, "Django 1.9 has updated the admin url.")
    def test_get_admin_change_page_django_lte_19(self):
        """Assert the right page is called when changing a record."""
        user = self.user_factory.create()

        self.get_admin_change_page(user)
        expected = '/admin/tests/user/{}/'.format(user.pk)
        self.client.get.assert_called_with(expected)


    @skipUnless(DJANGO_GTE_19, "Django 1.9 has updated the admin url.")