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

Unified Diff: appengine/monorail/tracker/test/spam_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
Index: appengine/monorail/tracker/test/spam_test.py
diff --git a/appengine/monorail/tracker/test/spam_test.py b/appengine/monorail/tracker/test/spam_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..2aeb535a6417e41c1c77d8ee1e312f563793ac6e
--- /dev/null
+++ b/appengine/monorail/tracker/test/spam_test.py
@@ -0,0 +1,114 @@
+# 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
+
+"""Unittests for monorail.tracker.spam."""
+
+import unittest
+
+from framework import permissions
+from services import service_manager
+from services import issue_svc
+from testing import fake
+from testing import testing_helpers
+from tracker import spam
+
+
+class FlagSpamFormTest(unittest.TestCase):
+
+ def setUp(self):
+ self.cnxn = 'fake cnxn'
+ self.services = service_manager.Services(
+ config=fake.ConfigService(),
+ issue=fake.IssueService(),
+ user=fake.UserService(),
+ project=fake.ProjectService(),
+ spam=fake.SpamService()
+ )
+ self.project = self.services.project.TestAddProject('proj', project_id=987)
+ self.servlet = spam.FlagSpamForm(
+ 'req', 'res', services=self.services)
+
+ def testProcessFormData_Permission(self):
+ local_id_1 = self.services.issue.CreateIssue(
+ self.cnxn, self.services, self.project.project_id,
+ 'summary_1', 'status', 111L, [], [], [], [], 111L, 'description_1')
+
+ # test owner case.
+ _, mr = testing_helpers.GetRequestObjects(
+ project=self.project,
+ perms=permissions.OWNER_ACTIVE_PERMISSIONSET)
+ mr.local_id = local_id_1
+ mr.auth_user_id = 222L
+ post_data = {
+ 'id': local_id_1,
+ 'spam': 'true'
+ }
+ res = self.servlet.ProcessFormData(mr, post_data)
+ self.assertEqual('http://127.0.0.1/p/None/issues/detail?id=1', res)
+
+ # test member case.
+ _, mr = testing_helpers.GetRequestObjects(
+ project=self.project,
+ perms=permissions.COMMITTER_ACTIVE_PERMISSIONSET)
+ mr.local_id = local_id_1
+ mr.auth_user_id = 222L
+ post_data = {
+ 'id': local_id_1,
+ 'spam': 'true'
+ }
+ res = self.servlet.ProcessFormData(mr, post_data)
+ self.assertEqual('http://127.0.0.1/p/None/issues/detail?id=1', res)
+
+ # test non-member case.
+ _, mr = testing_helpers.GetRequestObjects(
+ project=self.project,
+ perms=permissions.READ_ONLY_PERMISSIONSET)
+ mr.local_id = local_id_1
+ mr.auth_user_id = 222L
+ post_data = {
+ 'id': local_id_1,
+ 'spam': 'true'
+ }
+
+ with self.assertRaises(permissions.PermissionException):
+ res = self.servlet.ProcessFormData(mr, post_data)
+
+
+ def testProcessFormData_Comment(self):
+ local_id_1 = self.services.issue.CreateIssue(
+ self.cnxn, self.services, self.project.project_id,
+ 'summary_1', 'status', 111L, [], [], [], [], 111L, 'description_1')
+
+ # test owner case, non-existent comment.
+ _, mr = testing_helpers.GetRequestObjects(
+ project=self.project,
+ perms=permissions.OWNER_ACTIVE_PERMISSIONSET)
+ mr.local_id = local_id_1
+ mr.auth_user_id = 222L
+ post_data = {
+ 'id': local_id_1,
+ 'comment_id': 123,
+ 'spam': 'true'
+ }
+ with self.assertRaises(issue_svc.NoSuchCommentException):
+ res = self.servlet.ProcessFormData(mr, post_data)
+
+ comment = self.services.issue.CreateIssueComment(
+ self.cnxn, self.project.project_id, local_id_1, 111L, "Test comment")
+
+ _, mr = testing_helpers.GetRequestObjects(
+ project=self.project,
+ perms=permissions.OWNER_ACTIVE_PERMISSIONSET)
+ mr.local_id = local_id_1
+ mr.auth_user_id = 222L
+ post_data = {
+ 'id': local_id_1,
+ 'comment_id': comment.id,
+ 'sequence_num': 2,
+ 'spam': 'true'
+ }
+
+ res = self.servlet.ProcessFormData(mr, post_data)
+ self.assertEqual('http://127.0.0.1/p/None/issues/detail?id=1', res)
« no previous file with comments | « appengine/monorail/tracker/test/issuetips_test.py ('k') | appengine/monorail/tracker/test/tablecell_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698