From: Charlie DeTar Date: Fri, 9 Jan 2015 21:05:26 +0000 (-0700) Subject: Don't give points when downloading own doc X-Git-Tag: release-20150131~11 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=5891561378249ef4b188e534f48e1257783eb3f0;p=oweals%2Fkarmaworld.git Don't give points when downloading own doc Fixes #383. Add tests for this. --- 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