Don't give points when downloading own doc
authorCharlie DeTar <cfd@media.mit.edu>
Fri, 9 Jan 2015 21:05:26 +0000 (14:05 -0700)
committerCharlie DeTar <cfd@media.mit.edu>
Fri, 9 Jan 2015 21:05:26 +0000 (14:05 -0700)
Fixes #383.  Add tests for this.

karmaworld/apps/notes/views.py
karmaworld/apps/users/tests.py

index 349cd17416a1d19c07a793b6c759e9ea999a50be..b6cdaf46057075b82a5a4e6a02955c1ca9cac799 100644 (file)
@@ -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)
     """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)
 
 
         NoteKarmaEvent.create_event(note.user, note, NoteKarmaEvent.HAD_NOTE_DOWNLOADED)
 
 
index 4d48c8b0edecc7eeacba5505681b7876bc538b3e..10b212f675c4e8ca2d33734f520640a938b3860d 100644 (file)
@@ -134,6 +134,20 @@ class TestUsers(TestCase):
         except ObjectDoesNotExist:
             self.fail("Karma event not created")
 
         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
     def test_email_confirm_karma(self):
         class FakeEmailAddress:
             user = self.user1