mirror of
https://github.com/Hopiu/django-notifications.git
synced 2026-05-17 09:11:06 +00:00
Added sentinals for unauthenticated users, preventing a 500 error
also fix spelling mistake in README
This commit is contained in:
parent
551be1e910
commit
d55762edd3
4 changed files with 27 additions and 4 deletions
|
|
@ -342,7 +342,7 @@ Testing the live-updater
|
|||
------------------------
|
||||
|
||||
1. Clone the repo
|
||||
2. Set the 'NOTIFICATION_TEST' environemnt variable. E.g. `export NOTIFICATION_TEST=1`
|
||||
2. Set the 'NOTIFICATION_TEST' environment variable. E.g. `export NOTIFICATION_TEST=1`
|
||||
3. Run `./manage.py runserver`
|
||||
4. Browse to `yourserverip/test/`
|
||||
5. Click 'Make a notification' and a new notification should appear in the list in 5-10 seconds.
|
||||
|
|
|
|||
|
|
@ -284,3 +284,16 @@ class NotificationTestPages(TestCase):
|
|||
page = render(request, 'notifications/test_tags.html', {'request':request})
|
||||
|
||||
#TODO: Add more tests to check what is being output.
|
||||
|
||||
def test_anon_user_gets_nothing(self):
|
||||
response = self.client.post(reverse('notifications:live_unread_notification_count'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
data = json.loads(response.content.decode('utf-8'))
|
||||
self.assertEqual(data['unread_count'],0)
|
||||
|
||||
response = self.client.post(reverse('notifications:live_unread_notification_list'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
data = json.loads(response.content.decode('utf-8'))
|
||||
self.assertEqual(data['unread_count'],0)
|
||||
self.assertEqual(data['unread_list'],[])
|
||||
|
||||
|
|
@ -21,6 +21,7 @@ def make_notification(request):
|
|||
'cleaning the car',
|
||||
'jumping the shark',
|
||||
'testing the app',
|
||||
'attaching the plumbus',
|
||||
])
|
||||
|
||||
notify.send(sender=request.user, recipient=request.user, verb='you asked for a notification - you are '+the_notification)
|
||||
|
|
|
|||
|
|
@ -120,13 +120,22 @@ def delete(request, slug=None):
|
|||
|
||||
|
||||
def live_unread_notification_count(request):
|
||||
data = {
|
||||
'unread_count': request.user.notifications.unread().count(),
|
||||
}
|
||||
if not request.user.is_authenticated():
|
||||
data = {'unread_count':0}
|
||||
else:
|
||||
data = {
|
||||
'unread_count': request.user.notifications.unread().count(),
|
||||
}
|
||||
return JsonResponse(data)
|
||||
|
||||
|
||||
def live_unread_notification_list(request):
|
||||
if not request.user.is_authenticated():
|
||||
data = {
|
||||
'unread_count':0,
|
||||
'unread_list':[]
|
||||
}
|
||||
return JsonResponse(data)
|
||||
|
||||
try:
|
||||
num_to_fetch = request.GET.get('max', 5) # If they don't specify, make it 5.
|
||||
|
|
|
|||
Loading…
Reference in a new issue