# Path: open_connect/middleware/accept_terms.py
# class AcceptTermsAndConductMiddleware(object):
#     """Checks that users have accepted terms and conduct agreements."""
#     def process_request(self, request):
#         """Process request and ask for an invite code if needed."""
#         # Find users that are logged in but haven't been verified
#         user = request.user
#         if user.is_authenticated() and not request.is_ajax():
#             if user.tos_accepted_at and user.ucoc_accepted_at:
#                 return
#             path = request.path_info.lstrip('/')
#             # Only check the invite for paths that require login
#             if not any(m.match(path) for m in EXEMPT_URLS):
#                 redirect_to = '{url}?next={next}'.format(
#                     url=reverse('accept_terms_and_conduct'),
#                     next=request.path_info
#                 )
#                 return HttpResponseRedirect(redirect_to)


from django.contrib.auth.models import AnonymousUser
from django.core.urlresolvers import reverse
from django.test import TestCase, RequestFactory
from django.utils.timezone import now
from model_mommy import mommy
from open_connect.middleware.accept_terms import AcceptTermsAndConductMiddleware
"""Tests for accepting terms middleware."""
# pylint: disable=invalid-name



class TestAcceptTermsAndConductMiddleware(TestCase):
    """Tests for AcceptTermsAndConductMiddleware."""
    def setUp(self):
        """Setup the TestAcceptTermsAndConductMiddleware TestCase"""
        self.factory = RequestFactory()

# Path: open_connect/middleware/accept_terms.py
# class AcceptTermsAndConductMiddleware(object):
#     """Checks that users have accepted terms and conduct agreements."""
#     def process_request(self, request):
#         """Process request and ask for an invite code if needed."""
#         # Find users that are logged in but haven't been verified
#         user = request.user
#         if user.is_authenticated() and not request.is_ajax():
#             if user.tos_accepted_at and user.ucoc_accepted_at:
#                 return
#             path = request.path_info.lstrip('/')
#             # Only check the invite for paths that require login
#             if not any(m.match(path) for m in EXEMPT_URLS):
#                 redirect_to = '{url}?next={next}'.format(
#                     url=reverse('accept_terms_and_conduct'),
#                     next=request.path_info
#                 )
#                 return HttpResponseRedirect(redirect_to)


# Path: open_connect/middleware/tests/test_accept_terms.py
from django.contrib.auth.models import AnonymousUser
from django.core.urlresolvers import reverse
from django.test import TestCase, RequestFactory
from django.utils.timezone import now
from model_mommy import mommy
from open_connect.middleware.accept_terms import AcceptTermsAndConductMiddleware

"""Tests for accepting terms middleware."""
# pylint: disable=invalid-name



class TestAcceptTermsAndConductMiddleware(TestCase):
    """Tests for AcceptTermsAndConductMiddleware."""
    def setUp(self):
        """Setup the TestAcceptTermsAndConductMiddleware TestCase"""
        self.factory = RequestFactory()

        self.mw = AcceptTermsAndConductMiddleware()