# Path: tests/utils.py
# class SharedSchemaTenantsTestCase(TestCase):
# 
#     def setUp(self):
#         self.tenant = mommy.make('shared_schema_tenants.Tenant')
#         set_current_tenant(self.tenant.slug)
#         self.user = User.objects.create_user(
#             first_name='test', last_name='test',
#             username='test', email='test@sharedschematenants.com',
#             password='test')
#         self.relationship = create_relationship(self.tenant, self.user,
#                                                 groups=create_default_tenant_groups())
#         self.tenant_site = mommy.make('shared_schema_tenants.TenantSite',
#                                       tenant=self.tenant)
# 
# Path: shared_schema_tenants/permissions.py
# class DjangoTenantModelPermissions(DjangoModelPermissions):
# 
#     def has_object_permission(self, request, view, obj):
#         if hasattr(obj, 'tenant'):
#             kwargs = {'tenant': obj.tenant}
#         elif hasattr(obj, 'tenants'):
#             kwargs = {'tenant__in': obj.tenants.all()}
#         else:
#             return True
# 
#         return request.user.relationships.filter(**kwargs).exists()


import mock
from django.test import RequestFactory
from model_mommy import mommy
from tests.utils import SharedSchemaTenantsTestCase
from shared_schema_tenants.permissions import DjangoTenantModelPermissions
    from django.urls import reverse
    from django.core.urlresolvers import reverse


try:
except ImportError:


class DjangoTenantModelPermissionsTests(SharedSchemaTenantsTestCase):

    def setUp(self):
        super(DjangoTenantModelPermissionsTests, self).setUp()
        factory = RequestFactory()
        self.request = factory.post(reverse('shared_schema_tenants:tenant_list'))
        self.request.user = self.user
        self.permission = DjangoTenantModelPermissions()


# Path: tests/utils.py
# class SharedSchemaTenantsTestCase(TestCase):
# 
#     def setUp(self):
#         self.tenant = mommy.make('shared_schema_tenants.Tenant')
#         set_current_tenant(self.tenant.slug)
#         self.user = User.objects.create_user(
#             first_name='test', last_name='test',
#             username='test', email='test@sharedschematenants.com',
#             password='test')
#         self.relationship = create_relationship(self.tenant, self.user,
#                                                 groups=create_default_tenant_groups())
#         self.tenant_site = mommy.make('shared_schema_tenants.TenantSite',
#                                       tenant=self.tenant)
# 
# Path: shared_schema_tenants/permissions.py
# class DjangoTenantModelPermissions(DjangoModelPermissions):
# 
#     def has_object_permission(self, request, view, obj):
#         if hasattr(obj, 'tenant'):
#             kwargs = {'tenant': obj.tenant}
#         elif hasattr(obj, 'tenants'):
#             kwargs = {'tenant__in': obj.tenants.all()}
#         else:
#             return True
# 
#         return request.user.relationships.filter(**kwargs).exists()


# Path: shared_schema_tenants/tests/test_permissions.py
import mock
from django.test import RequestFactory
from model_mommy import mommy
from tests.utils import SharedSchemaTenantsTestCase
from shared_schema_tenants.permissions import DjangoTenantModelPermissions
    from django.urls import reverse
    from django.core.urlresolvers import reverse



try:
except ImportError:


class DjangoTenantModelPermissionsTests(SharedSchemaTenantsTestCase):

    def setUp(self):
        super(DjangoTenantModelPermissionsTests, self).setUp()
        factory = RequestFactory()
        self.request = factory.post(reverse('shared_schema_tenants:tenant_list'))
        self.request.user = self.user
        self.permission = DjangoTenantModelPermissions()


    def test_has_object_permission_with_created_tenant_single_tenant_object(self):