Skip to content

Commit

Permalink
Merge 1b85a99 into 1d53771
Browse files Browse the repository at this point in the history
  • Loading branch information
LegoStormtroopr committed Feb 8, 2016
2 parents 1d53771 + 1b85a99 commit f9f565c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,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.
Expand Down
12 changes: 12 additions & 0 deletions notifications/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,15 @@ def test_live_update_tags(self):
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'],[])
1 change: 1 addition & 0 deletions notifications/tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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,
Expand Down
15 changes: 12 additions & 3 deletions notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f9f565c

Please sign in to comment.