OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is govered by a BSD-style |
| 3 # license that can be found in the LICENSE file or at |
| 4 # https://developers.google.com/open-source/licenses/bsd |
| 5 |
| 6 """Unittests for monorail.tracker.spam.""" |
| 7 |
| 8 import unittest |
| 9 |
| 10 from framework import permissions |
| 11 from services import service_manager |
| 12 from services import issue_svc |
| 13 from testing import fake |
| 14 from testing import testing_helpers |
| 15 from tracker import spam |
| 16 |
| 17 |
| 18 class FlagSpamFormTest(unittest.TestCase): |
| 19 |
| 20 def setUp(self): |
| 21 self.cnxn = 'fake cnxn' |
| 22 self.services = service_manager.Services( |
| 23 config=fake.ConfigService(), |
| 24 issue=fake.IssueService(), |
| 25 user=fake.UserService(), |
| 26 project=fake.ProjectService(), |
| 27 spam=fake.SpamService() |
| 28 ) |
| 29 self.project = self.services.project.TestAddProject('proj', project_id=987) |
| 30 self.servlet = spam.FlagSpamForm( |
| 31 'req', 'res', services=self.services) |
| 32 |
| 33 def testProcessFormData_Permission(self): |
| 34 local_id_1 = self.services.issue.CreateIssue( |
| 35 self.cnxn, self.services, self.project.project_id, |
| 36 'summary_1', 'status', 111L, [], [], [], [], 111L, 'description_1') |
| 37 |
| 38 # test owner case. |
| 39 _, mr = testing_helpers.GetRequestObjects( |
| 40 project=self.project, |
| 41 perms=permissions.OWNER_ACTIVE_PERMISSIONSET) |
| 42 mr.local_id = local_id_1 |
| 43 mr.auth_user_id = 222L |
| 44 post_data = { |
| 45 'id': local_id_1, |
| 46 'spam': 'true' |
| 47 } |
| 48 res = self.servlet.ProcessFormData(mr, post_data) |
| 49 self.assertEqual('http://127.0.0.1/p/None/issues/detail?id=1', res) |
| 50 |
| 51 # test member case. |
| 52 _, mr = testing_helpers.GetRequestObjects( |
| 53 project=self.project, |
| 54 perms=permissions.COMMITTER_ACTIVE_PERMISSIONSET) |
| 55 mr.local_id = local_id_1 |
| 56 mr.auth_user_id = 222L |
| 57 post_data = { |
| 58 'id': local_id_1, |
| 59 'spam': 'true' |
| 60 } |
| 61 res = self.servlet.ProcessFormData(mr, post_data) |
| 62 self.assertEqual('http://127.0.0.1/p/None/issues/detail?id=1', res) |
| 63 |
| 64 # test non-member case. |
| 65 _, mr = testing_helpers.GetRequestObjects( |
| 66 project=self.project, |
| 67 perms=permissions.READ_ONLY_PERMISSIONSET) |
| 68 mr.local_id = local_id_1 |
| 69 mr.auth_user_id = 222L |
| 70 post_data = { |
| 71 'id': local_id_1, |
| 72 'spam': 'true' |
| 73 } |
| 74 |
| 75 with self.assertRaises(permissions.PermissionException): |
| 76 res = self.servlet.ProcessFormData(mr, post_data) |
| 77 |
| 78 |
| 79 def testProcessFormData_Comment(self): |
| 80 local_id_1 = self.services.issue.CreateIssue( |
| 81 self.cnxn, self.services, self.project.project_id, |
| 82 'summary_1', 'status', 111L, [], [], [], [], 111L, 'description_1') |
| 83 |
| 84 # test owner case, non-existent comment. |
| 85 _, mr = testing_helpers.GetRequestObjects( |
| 86 project=self.project, |
| 87 perms=permissions.OWNER_ACTIVE_PERMISSIONSET) |
| 88 mr.local_id = local_id_1 |
| 89 mr.auth_user_id = 222L |
| 90 post_data = { |
| 91 'id': local_id_1, |
| 92 'comment_id': 123, |
| 93 'spam': 'true' |
| 94 } |
| 95 with self.assertRaises(issue_svc.NoSuchCommentException): |
| 96 res = self.servlet.ProcessFormData(mr, post_data) |
| 97 |
| 98 comment = self.services.issue.CreateIssueComment( |
| 99 self.cnxn, self.project.project_id, local_id_1, 111L, "Test comment") |
| 100 |
| 101 _, mr = testing_helpers.GetRequestObjects( |
| 102 project=self.project, |
| 103 perms=permissions.OWNER_ACTIVE_PERMISSIONSET) |
| 104 mr.local_id = local_id_1 |
| 105 mr.auth_user_id = 222L |
| 106 post_data = { |
| 107 'id': local_id_1, |
| 108 'comment_id': comment.id, |
| 109 'sequence_num': 2, |
| 110 'spam': 'true' |
| 111 } |
| 112 |
| 113 res = self.servlet.ProcessFormData(mr, post_data) |
| 114 self.assertEqual('http://127.0.0.1/p/None/issues/detail?id=1', res) |
OLD | NEW |