def test_karma_calculation_bug(self): toms_karma = list([ Karma(awarded_to_username="******", reason="", awarded_by_username="******", awarded=datetime.now(), karma_type=KarmaType.NEGGYNEG), Karma(awarded_to_username="******", reason="", awarded_by_username="******", awarded=datetime.now(), karma_type=KarmaType.NEGGYNEG), Karma(awarded_to_username="******", reason="", awarded_by_username="******", awarded=datetime.now(), karma_type=KarmaType.NEGGYNEG) ]) for k in toms_karma: k.save() net_karma = Karma.get_current_net_karma_for_recipient("tomallen") self.assertEqual(-3, net_karma)
def test_get_current_karma_with_net(self): # Arrange karma_to_save = default_karma_list() for k in karma_to_save: k.save() # Act net_karma = Karma.get_current_net_karma_for_recipient(test_recipient) # Assert self.assertEqual(0, net_karma)
def test_get_current_karma_with_expired(self): # Arrange newly_awarded = datetime.today() award_ages_ago = datetime.today() - timedelta(days=31) new_karma = create_karma(awarded=newly_awarded) old_karma = create_karma(awarded=award_ages_ago) new_karma.save() old_karma.save() # Act current_karma = Karma.get_current_net_karma_for_recipient( test_recipient) # Assert self.assertEqual(1, current_karma)
def get_current_karma(self): return Karma.get_current_net_karma_for_recipient(self.username)
def execute(self, recipient): net_karma = Karma.get_current_net_karma_for_recipient(recipient) return net_karma
def test_get_current_net_karma_unknown_recipient_is_zero(self): recipient = "bfvhdsukvhksdbv" net_karma = Karma.get_current_net_karma_for_recipient(recipient) self.assertEqual(0, net_karma)