Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: appengine/monorail/features/test/stars_test.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/monorail/features/test/savedqueries_test.py ('k') | appengine/monorail/framework/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/monorail/features/test/stars_test.py
diff --git a/appengine/monorail/features/test/stars_test.py b/appengine/monorail/features/test/stars_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..e96d765567f7a2ac12d78be21005edd9d07f04dd
--- /dev/null
+++ b/appengine/monorail/features/test/stars_test.py
@@ -0,0 +1,68 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is govered by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""Tests for the project and user stars feature."""
+
+import unittest
+
+from features import stars
+from services import service_manager
+from testing import fake
+from testing import testing_helpers
+
+
+class StarsTest(unittest.TestCase):
+
+ def setUp(self):
+ self.services = service_manager.Services(
+ project=fake.ProjectService(),
+ user=fake.UserService(),
+ project_star=fake.ProjectStarService(),
+ user_star=fake.UserStarService())
+ self.services.project.TestAddProject('proj', project_id=123)
+ self.services.user.TestAddUser('testuser', 111L)
+ self.set_stars_feed = stars.SetStarsFeed(
+ 'req', 'res', services=self.services)
+
+ def SetAndVerifyStarredItems(self, scope, item, item_id, get_star_count):
+ self.assertEqual(0, get_star_count('fake cnxn', item_id))
+
+ mr = testing_helpers.MakeMonorailRequest(
+ user_info={'user_id': 111L}, services=self.services, method='POST',
+ params={'scope': scope, 'item': item, 'starred': 1, 'token': 'x'})
+ result = self.set_stars_feed.HandleRequest(mr)
+
+ self.assertEqual({'starred': True}, result)
+ self.assertEqual(1, get_star_count('fake cnxn', item_id))
+
+ # The same starrer doing it again does not drive up the count more.
+ result = self.set_stars_feed.HandleRequest(mr)
+ self.assertEqual({'starred': True}, result)
+ self.assertEqual(1, get_star_count('fake cnxn', item_id))
+
+ mr = testing_helpers.MakeMonorailRequest(
+ user_info={'user_id': 111L}, services=self.services, method='POST',
+ params={'scope': scope, 'item': item, 'starred': 0, 'token': 'x'})
+ result = self.set_stars_feed.HandleRequest(mr)
+ self.assertEqual({'starred': False}, result)
+ self.assertEqual(0, get_star_count('fake cnxn', item_id))
+
+ # The same starrer doing it again does not drive down the count more.
+ result = self.set_stars_feed.HandleRequest(mr)
+ self.assertEqual({'starred': False}, result)
+ self.assertEqual(0, get_star_count('fake cnxn', item_id))
+
+ def testSetAndGetStarredItems_User(self):
+ """Tests SetStarsFeed.HandleRequest method."""
+ self.SetAndVerifyStarredItems(
+ 'users', '111', 111L, self.services.user_star.CountItemStars)
+
+ def testSetAndGetStarredItems_Project(self):
+ self.SetAndVerifyStarredItems(
+ 'projects', 'proj', 123, self.services.project_star.CountItemStars)
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « appengine/monorail/features/test/savedqueries_test.py ('k') | appengine/monorail/framework/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698