# Path: tests/utils.py
# def request_factory_login(factory, user=None, method="request", **kwargs):
#     """Based on this gist: https://gist.github.com/964472"""
#     # engine = import_module(settings.SESSION_ENGINE)
#     request = getattr(factory, method)(**kwargs)
#     # request.session = engine.SessionStore()
#     # request.session[SESSION_KEY] = user.pk
#     request.user = user or AnonymousUser()
#     return request


from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings
from organizations.models import Organization
from organizations.models import OrganizationUser
from organizations.views.mixins import AdminRequiredMixin
from organizations.views.mixins import MembershipRequiredMixin
from organizations.views.mixins import OrganizationMixin
from organizations.views.mixins import OrganizationUserMixin
from organizations.views.mixins import OwnerRequiredMixin
from tests.utils import request_factory_login
    def test_get_org_object(self):
        view = OrgView(organization_pk=self.foo.pk)
        self.assertEqual(view.get_object(), self.foo)

    def test_get_user_object(self):
        view = UserView(organization_pk=self.foo.pk, user_pk=self.dave.pk)
        self.assertEqual(view.get_object(), self.dave)
        self.assertEqual(view.get_organization(), self.foo)

    def test_get_model(self):
        """Ensure that the method returns the class object"""
        self.assertEqual(Organization, OrganizationMixin().get_org_model())
        self.assertEqual(Organization, OrganizationUserMixin().get_org_model())
        self.assertEqual(OrganizationUser, OrganizationUserMixin().get_user_model())


@override_settings(USE_TZ=True)
class AccessMixinTests(TestCase):

    fixtures = ["users.json", "orgs.json"]

    def setUp(self):
        self.nirvana = Organization.objects.get(name="Nirvana")
        self.kurt = User.objects.get(username="kurt")
        self.krist = User.objects.get(username="krist")
        self.dave = User.objects.get(username="dave")
        self.dummy = User.objects.create_user(
            "dummy", email="dummy@example.com", password="test"
        )
        self.factory = RequestFactory()

# Path: tests/utils.py
# def request_factory_login(factory, user=None, method="request", **kwargs):
#     """Based on this gist: https://gist.github.com/964472"""
#     # engine = import_module(settings.SESSION_ENGINE)
#     request = getattr(factory, method)(**kwargs)
#     # request.session = engine.SessionStore()
#     # request.session[SESSION_KEY] = user.pk
#     request.user = user or AnonymousUser()
#     return request


# Path: tests/test_mixins.py
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings
from organizations.models import Organization
from organizations.models import OrganizationUser
from organizations.views.mixins import AdminRequiredMixin
from organizations.views.mixins import MembershipRequiredMixin
from organizations.views.mixins import OrganizationMixin
from organizations.views.mixins import OrganizationUserMixin
from organizations.views.mixins import OwnerRequiredMixin
from tests.utils import request_factory_login

    def test_get_org_object(self):
        view = OrgView(organization_pk=self.foo.pk)
        self.assertEqual(view.get_object(), self.foo)

    def test_get_user_object(self):
        view = UserView(organization_pk=self.foo.pk, user_pk=self.dave.pk)
        self.assertEqual(view.get_object(), self.dave)
        self.assertEqual(view.get_organization(), self.foo)

    def test_get_model(self):
        """Ensure that the method returns the class object"""
        self.assertEqual(Organization, OrganizationMixin().get_org_model())
        self.assertEqual(Organization, OrganizationUserMixin().get_org_model())
        self.assertEqual(OrganizationUser, OrganizationUserMixin().get_user_model())


@override_settings(USE_TZ=True)
class AccessMixinTests(TestCase):

    fixtures = ["users.json", "orgs.json"]

    def setUp(self):
        self.nirvana = Organization.objects.get(name="Nirvana")
        self.kurt = User.objects.get(username="kurt")
        self.krist = User.objects.get(username="krist")
        self.dave = User.objects.get(username="dave")
        self.dummy = User.objects.create_user(
            "dummy", email="dummy@example.com", password="test"
        )
        self.factory = RequestFactory()

        self.kurt_request = request_factory_login(self.factory, self.kurt)