diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-11-18 17:52:25 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-11-20 19:15:41 +0100 |
commit | 3d7878e1088138fbc3971313a74c91b79bbea643 (patch) | |
tree | 61c3bef248fd9c46d39dfd2b89c414c255c42395 /hyperkitty/tests/test_lib.py | |
parent | 467de0a0500d07b5687e4540b201016643857d30 (diff) | |
download | hyperkitty-3d7878e1088138fbc3971313a74c91b79bbea643.tar.gz hyperkitty-3d7878e1088138fbc3971313a74c91b79bbea643.tar.xz hyperkitty-3d7878e1088138fbc3971313a74c91b79bbea643.zip |
Improve and write tests for the set_thread_votes function
Diffstat (limited to 'hyperkitty/tests/test_lib.py')
-rw-r--r-- | hyperkitty/tests/test_lib.py | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/hyperkitty/tests/test_lib.py b/hyperkitty/tests/test_lib.py index 19f31d1..6b6a9e1 100644 --- a/hyperkitty/tests/test_lib.py +++ b/hyperkitty/tests/test_lib.py @@ -21,9 +21,14 @@ import datetime -from hyperkitty.tests.utils import TestCase +from django.contrib.auth.models import User, AnonymousUser +from django.core.cache import cache +from hyperkitty.models import Rating from hyperkitty.lib.view_helpers import get_display_dates, paginate +from hyperkitty.lib.voting import get_votes, set_thread_votes + +from hyperkitty.tests.utils import TestCase class GetDisplayDatesTestCase(TestCase): @@ -95,3 +100,57 @@ class PaginateTestCase(TestCase): [1, '...', 96, 97, 98, 99, 100]) self.assertEqual(paginate(objects, 100).page_range, [1, '...', 97, 98, 99, 100]) + + + +# +# Voting +# + +class DummyThread(object): + thread_id = "dummy" + list_name = "test@example.com" + email_id_hashes = [] + @property + def emails_count(self): + return len(email_id_hashes) + +class VotingTestCase(TestCase): + + def setUp(self): + self.thread = DummyThread() + self.user = User.objects.create_user('testuser', 'test@example.com', 'testPass') + + def tearDown(self): + cache.clear() + + def test_msg1(self): + # First message in thread is voted for + self.thread.email_id_hashes = ["msg1", "msg2", "msg3"] + Rating(list_address=self.thread.list_name, messageid="msg1", + user=self.user, vote=1).save() + set_thread_votes(self.thread) + self.assertEqual(self.thread.likes, 1) + self.assertEqual(self.thread.dislikes, 0) + self.assertEqual(self.thread.likestatus, "like") + + def test_msg2(self): + # Second message in thread is voted against + self.thread.email_id_hashes = ["msg1", "msg2", "msg3"] + Rating(list_address=self.thread.list_name, messageid="msg2", + user=self.user, vote=-1).save() + set_thread_votes(self.thread) + self.assertEqual(self.thread.likes, 0) + self.assertEqual(self.thread.dislikes, 1) + self.assertEqual(self.thread.likestatus, "neutral") + + def test_likealot(self): + # All messages in thread are voted for + self.thread.email_id_hashes = [ "msg%s" % num for num in range(1, 11) ] + for msgid in self.thread.email_id_hashes: + Rating(list_address=self.thread.list_name, messageid=msgid, + user=self.user, vote=1).save() + set_thread_votes(self.thread) + self.assertEqual(self.thread.likes, 10) + self.assertEqual(self.thread.dislikes, 0) + self.assertEqual(self.thread.likestatus, "likealot") |