# Path: open_connect/accounts/models.py
# class Visit(TimestampModel):
#     """Store information about a user's visits to the site."""
#     user = models.ForeignKey(User, blank=True, null=True)
#     ip_address = models.GenericIPAddressField(blank=True, null=True)
#     user_agent = models.TextField(blank=True)


from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.test import TestCase, RequestFactory
from django.test.utils import override_settings
from mock import Mock
from model_mommy import mommy
from open_connect.middleware.visit_tracking import VisitTrackingMiddleware
from open_connect.accounts.models import Visit
from open_connect.connect_core.utils.basetests import ConnectTestMixin
"""Tests for visit tracking middleware."""
# pylint: disable=invalid-name




User = get_user_model()


middleware = list(settings.MIDDLEWARE_CLASSES)
# pylint: disable=line-too-long
if 'open_connect.middleware.visit_tracking.VisitTrackingMiddleware' not in middleware:
    middleware.insert(
        0, 'open_connect.middleware.visit_tracking.VisitTrackingMiddleware')


@override_settings(MIDDLEWARE_CLASSES=middleware)
class VisitTrackingMiddlewareTest(ConnectTestMixin, TestCase):
    """Tests for visit tracking middleware."""
    def test_no_user_attribute(self):
        """Test that a request without a user attr won't trigger an error"""
        user = mommy.make(User)
        request_factory = RequestFactory()
        visit_tracking_mw = VisitTrackingMiddleware()


# Path: open_connect/accounts/models.py
# class Visit(TimestampModel):
#     """Store information about a user's visits to the site."""
#     user = models.ForeignKey(User, blank=True, null=True)
#     ip_address = models.GenericIPAddressField(blank=True, null=True)
#     user_agent = models.TextField(blank=True)


# Path: open_connect/middleware/tests/test_visit_tracking.py
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.test import TestCase, RequestFactory
from django.test.utils import override_settings
from mock import Mock
from model_mommy import mommy
from open_connect.middleware.visit_tracking import VisitTrackingMiddleware
from open_connect.accounts.models import Visit
from open_connect.connect_core.utils.basetests import ConnectTestMixin

"""Tests for visit tracking middleware."""
# pylint: disable=invalid-name




User = get_user_model()


middleware = list(settings.MIDDLEWARE_CLASSES)
# pylint: disable=line-too-long
if 'open_connect.middleware.visit_tracking.VisitTrackingMiddleware' not in middleware:
    middleware.insert(
        0, 'open_connect.middleware.visit_tracking.VisitTrackingMiddleware')


@override_settings(MIDDLEWARE_CLASSES=middleware)
class VisitTrackingMiddlewareTest(ConnectTestMixin, TestCase):
    """Tests for visit tracking middleware."""
    def test_no_user_attribute(self):
        """Test that a request without a user attr won't trigger an error"""
        user = mommy.make(User)
        request_factory = RequestFactory()
        visit_tracking_mw = VisitTrackingMiddleware()


        visit_count = Visit.objects.count()