From 5891561378249ef4b188e534f48e1257783eb3f0 Mon Sep 17 00:00:00 2001 From: Charlie DeTar Date: Fri, 9 Jan 2015 14:05:26 -0700 Subject: [PATCH] Don't give points when downloading own doc Fixes #383. Add tests for this. --- karmaworld/apps/notes/views.py | 2 +- karmaworld/apps/users/tests.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/karmaworld/apps/notes/views.py b/karmaworld/apps/notes/views.py index 349cd17..b6cdaf4 100644 --- a/karmaworld/apps/notes/views.py +++ b/karmaworld/apps/notes/views.py @@ -348,7 +348,7 @@ def process_downloaded_note(request_user, note): """Record that somebody has downloaded a note""" if request_user.is_authenticated() and request_user != note.user: NoteKarmaEvent.create_event(request_user, note, NoteKarmaEvent.DOWNLOADED_NOTE) - if request_user.is_authenticated() and note.user: + if request_user.is_authenticated() and note.user and note.user != request_user: NoteKarmaEvent.create_event(note.user, note, NoteKarmaEvent.HAD_NOTE_DOWNLOADED) diff --git a/karmaworld/apps/users/tests.py b/karmaworld/apps/users/tests.py index 4d48c8b..10b212f 100644 --- a/karmaworld/apps/users/tests.py +++ b/karmaworld/apps/users/tests.py @@ -134,6 +134,20 @@ class TestUsers(TestCase): except ObjectDoesNotExist: self.fail("Karma event not created") + def test_download_own_note_karma(self): + """No karma change for downloading your own note""" + downloaded_note(self.request1, self.note.pk) + try: + NoteKarmaEvent.objects.get(event_type=NoteKarmaEvent.DOWNLOADED_NOTE, user=self.user1) + self.fail("Karma debited for downloading own note, but shouldn't have been.") + except ObjectDoesNotExist: + pass + try: + NoteKarmaEvent.objects.get(event_type=NoteKarmaEvent.HAD_NOTE_DOWNLOADED, user=self.user1) + self.fail("Karma given for downloading own note, but shouldn't have been.") + except ObjectDoesNotExist: + pass + def test_email_confirm_karma(self): class FakeEmailAddress: user = self.user1 -- 2.25.1