[extensions-web/filter-sort-ui: 11/20] Add tests for ratings



commit abe352610bcb8e530cb81c3c0a13b1664ad2e272
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Dec 27 15:22:35 2011 -0500

    Add tests for ratings

 sweettooth/extensions/tests.py |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/sweettooth/extensions/tests.py b/sweettooth/extensions/tests.py
index 8d1c9c3..c379ac4 100644
--- a/sweettooth/extensions/tests.py
+++ b/sweettooth/extensions/tests.py
@@ -364,3 +364,37 @@ class UpdateVersionTest(TestCase):
 
         response = self.grab_response(installed)
         self.assertEqual(self.full_expected, response)
+
+class TestVoteTracker(BasicUserTestCase, TestCase):
+    def test_simple(self):
+        extension = models.Extension(name="Hi! I'm a talking door!",
+                                     creator=self.user,
+                                     uuid='talking-door mecheye net')
+        extension.save()
+
+        response = self.client.post('/ajax/adjust-rating/',
+                                    dict(uuid=extension.uuid,
+                                         action='like'))
+
+        tracker = models.ExtensionLikeTracker.objects.get(user=self.user,
+                                                          extension=extension)
+        self.assertEqual(tracker.user, self.user)
+        self.assertEqual(tracker.extension, extension)
+        self.assertEqual(tracker.vote, True)
+
+        # Man, I love floating point
+        extension = models.Extension.objects.get(uuid='talking-door mecheye net')
+        self.assertTrue(abs(models.confidence(1, 0) - extension.rating) < 0.1)
+
+        response = self.client.post('/ajax/adjust-rating/',
+                                    dict(uuid=extension.uuid,
+                                         action='dislike'))
+
+        tracker = models.ExtensionLikeTracker.objects.get(user=self.user,
+                                                          extension=extension)
+        self.assertEqual(tracker.user, self.user)
+        self.assertEqual(tracker.extension, extension)
+        self.assertEqual(tracker.vote, False)
+
+        extension = models.Extension.objects.get(uuid='talking-door mecheye net')
+        self.assertTrue(abs(models.confidence(0, 1) - extension.rating) < 0.1)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]