# Path: frontend/views.py
# def uncleared_notification_count(user, classgroup):
#     rating_count = RatingNotification.objects.filter(receiving_user=user, receiving_message__classgroup=classgroup, cleared=False).count()
#     message_count = MessageNotification.objects.filter(receiving_user=user, receiving_message__classgroup=classgroup, cleared=False).count()
#     return rating_count + message_count


from rest_framework.test import APITestCase, APIClient
from factories import UserFactory, ClassGroupFactory, ResourceFactory
from django.core.urlresolvers import reverse
from rest_framework.serializers import ValidationError
from permissions import ClassGroupPermissions
from tasks import process_saved_message
from frontend.views import uncleared_notification_count
from models import Resource
import logging
import json
import calendar
        self.create_message()

        # Get message notifications and check the count.  The count (1) is one less than the true count (2) in order
        # to prevent unnecessary notifications.
        message_notification_url = reverse('message_notifications')
        notifications = self.c0.get(
            message_notification_url,
            {
                'classgroup': self.cg.name,
                'start_time': calendar.timegm(self.cg.created.utctimetuple())
            }
        ).data
        self.assertEqual(notifications['message_count'], 1)

    def test_notification(self):
        """
        Test the notifications view when we mention someone in a message.
        """
        # Add user 1 to the classgroup.
        self.cg.users.add(self.user1)
        # Create a message from user0 that mentions user1.
        response = self.c0.post(self.message_url, {
            'classgroup': self.cg.name,
            'text': "@{0} mention test.".format(self.user1.username),
            'source': self.source,
            })
        messages = self.get_messages()
        # Run the task to process mentions.
        process_saved_message(messages[0]['pk'])
        # Check that user 1 has new notifications.

# Path: frontend/views.py
# def uncleared_notification_count(user, classgroup):
#     rating_count = RatingNotification.objects.filter(receiving_user=user, receiving_message__classgroup=classgroup, cleared=False).count()
#     message_count = MessageNotification.objects.filter(receiving_user=user, receiving_message__classgroup=classgroup, cleared=False).count()
#     return rating_count + message_count


# Path: api/tests.py
from rest_framework.test import APITestCase, APIClient
from factories import UserFactory, ClassGroupFactory, ResourceFactory
from django.core.urlresolvers import reverse
from rest_framework.serializers import ValidationError
from permissions import ClassGroupPermissions
from tasks import process_saved_message
from frontend.views import uncleared_notification_count
from models import Resource
import logging
import json
import calendar

        self.create_message()

        # Get message notifications and check the count.  The count (1) is one less than the true count (2) in order
        # to prevent unnecessary notifications.
        message_notification_url = reverse('message_notifications')
        notifications = self.c0.get(
            message_notification_url,
            {
                'classgroup': self.cg.name,
                'start_time': calendar.timegm(self.cg.created.utctimetuple())
            }
        ).data
        self.assertEqual(notifications['message_count'], 1)

    def test_notification(self):
        """
        Test the notifications view when we mention someone in a message.
        """
        # Add user 1 to the classgroup.
        self.cg.users.add(self.user1)
        # Create a message from user0 that mentions user1.
        response = self.c0.post(self.message_url, {
            'classgroup': self.cg.name,
            'text': "@{0} mention test.".format(self.user1.username),
            'source': self.source,
            })
        messages = self.get_messages()
        # Run the task to process mentions.
        process_saved_message(messages[0]['pk'])
        # Check that user 1 has new notifications.

        self.assertEqual(uncleared_notification_count(self.user1, self.cg), 1)