mirror of
https://github.com/Hopiu/django-notifications.git
synced 2026-05-15 00:23:09 +00:00
fixes failed travis tests
includes django1.6 way of doing jsonresponse
This commit is contained in:
parent
c7246f022e
commit
e794ee5a82
2 changed files with 18 additions and 9 deletions
|
|
@ -218,20 +218,20 @@ class NotificationTestPages(TestCase):
|
|||
self.login('to', 'pwd')
|
||||
|
||||
response = self.client.get(reverse('notifications:live_unread_notification_count'))
|
||||
data = json.loads(response.content)
|
||||
data = json.loads(str(response.content))
|
||||
self.assertEqual(data.keys(),['unread_count'])
|
||||
self.assertEqual(data['unread_count'],10)
|
||||
|
||||
|
||||
Notification.objects.filter(recipient=self.to_user).mark_all_as_read()
|
||||
response = self.client.get(reverse('notifications:live_unread_notification_count'))
|
||||
data = json.loads(response.content)
|
||||
data = json.loads(str(response.content))
|
||||
self.assertEqual(data.keys(),['unread_count'])
|
||||
self.assertEqual(data['unread_count'],0)
|
||||
|
||||
notify.send(self.from_user, recipient=self.to_user, verb='commented', action_object=self.from_user)
|
||||
response = self.client.get(reverse('notifications:live_unread_notification_count'))
|
||||
data = json.loads(response.content)
|
||||
data = json.loads(str(response.content))
|
||||
self.assertEqual(data.keys(),['unread_count'])
|
||||
self.assertEqual(data['unread_count'],1)
|
||||
|
||||
|
|
@ -239,34 +239,34 @@ class NotificationTestPages(TestCase):
|
|||
self.login('to', 'pwd')
|
||||
|
||||
response = self.client.get(reverse('notifications:live_unread_notification_list'))
|
||||
data = json.loads(response.content)
|
||||
data = json.loads(str(response.content))
|
||||
self.assertEqual(data.keys(),['unread_count','unread_list'])
|
||||
self.assertEqual(data['unread_count'],10)
|
||||
self.assertEqual(len(data['unread_list']),5)
|
||||
|
||||
response = self.client.get(reverse('notifications:live_unread_notification_list')+"?max=12")
|
||||
data = json.loads(response.content)
|
||||
data = json.loads(str(response.content))
|
||||
self.assertEqual(data.keys(),['unread_count','unread_list'])
|
||||
self.assertEqual(data['unread_count'],10)
|
||||
self.assertEqual(len(data['unread_list']),10)
|
||||
|
||||
# Test with a bad 'max' value
|
||||
response = self.client.get(reverse('notifications:live_unread_notification_list')+"?max=this_is_wrong")
|
||||
data = json.loads(response.content)
|
||||
data = json.loads(str(response.content))
|
||||
self.assertEqual(data.keys(),['unread_count','unread_list'])
|
||||
self.assertEqual(data['unread_count'],10)
|
||||
self.assertEqual(len(data['unread_list']),5)
|
||||
|
||||
Notification.objects.filter(recipient=self.to_user).mark_all_as_read()
|
||||
response = self.client.get(reverse('notifications:live_unread_notification_list'))
|
||||
data = json.loads(response.content)
|
||||
data = json.loads(str(response.content))
|
||||
self.assertEqual(data.keys(),['unread_count','unread_list'])
|
||||
self.assertEqual(data['unread_count'],0)
|
||||
self.assertEqual(len(data['unread_list']),0)
|
||||
|
||||
notify.send(self.from_user, recipient=self.to_user, verb='commented', action_object=self.from_user)
|
||||
response = self.client.get(reverse('notifications:live_unread_notification_list'))
|
||||
data = json.loads(response.content)
|
||||
data = json.loads(str(response.content))
|
||||
self.assertEqual(data.keys(),['unread_count','unread_list'])
|
||||
self.assertEqual(data['unread_count'],1)
|
||||
self.assertEqual(len(data['unread_list']),1)
|
||||
|
|
|
|||
|
|
@ -3,13 +3,22 @@ from django.conf import settings
|
|||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
from django.forms import model_to_dict
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import get_object_or_404, render, redirect
|
||||
from django.template.context import RequestContext
|
||||
|
||||
from .utils import slug2id
|
||||
from .models import Notification
|
||||
|
||||
from django import get_version
|
||||
from distutils.version import StrictVersion
|
||||
if StrictVersion(get_version()) >= StrictVersion('1.7.0'):
|
||||
from django.http import JsonResponse
|
||||
else:
|
||||
# Django 1.6 doesn't have a proper JsonResponse
|
||||
import json
|
||||
def JsonResponse(data):
|
||||
return HttpResponse(json.dumps(data), content_type="application/json")
|
||||
|
||||
@login_required
|
||||
def all(request):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue