Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | # Copyright 2016 The Chromium Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Unittests for Project Summary servlet.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
| 10 | import unittest |
| 11 | |
| 12 | from framework import permissions |
| 13 | from project import projectsummary |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 14 | from mrproto import project_pb2 |
| 15 | from mrproto import user_pb2 |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 16 | from services import service_manager |
| 17 | from testing import fake |
| 18 | from testing import testing_helpers |
| 19 | |
| 20 | |
| 21 | class ProjectSummaryTest(unittest.TestCase): |
| 22 | |
| 23 | def setUp(self): |
| 24 | services = service_manager.Services( |
| 25 | project=fake.ProjectService(), |
| 26 | user=fake.UserService(), |
| 27 | usergroup=fake.UserGroupService(), |
| 28 | project_star=fake.ProjectStarService()) |
| 29 | self.project = services.project.TestAddProject( |
| 30 | 'proj', project_id=123, summary='sum', |
| 31 | description='desc') |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 32 | self.servlet = projectsummary.ProjectSummary(services=services) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 33 | |
| 34 | def testGatherPageData(self): |
| 35 | mr = testing_helpers.MakeMonorailRequest(project=self.project) |
| 36 | page_data = self.servlet.GatherPageData(mr) |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 37 | self.assertEqual('desc', page_data['formatted_project_description']) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 38 | self.assertEqual( |
| 39 | int(project_pb2.ProjectAccess.ANYONE), page_data['access_level'].key) |
| 40 | self.assertEqual(0, page_data['num_stars']) |
| 41 | self.assertEqual('s', page_data['plural']) |
| 42 | |
| 43 | def testGatherHelpData(self): |
| 44 | mr = testing_helpers.MakeMonorailRequest(project=self.project) |
| 45 | |
| 46 | # Non-members cannot edit project, so cue is not relevant. |
| 47 | mr.perms = permissions.READ_ONLY_PERMISSIONSET |
| 48 | help_data = self.servlet.GatherHelpData(mr, {}) |
| 49 | self.assertEqual(None, help_data['cue']) |
| 50 | |
| 51 | # Members (not owners) cannot edit project, so cue is not relevant. |
| 52 | mr.perms = permissions.READ_ONLY_PERMISSIONSET |
| 53 | help_data = self.servlet.GatherHelpData(mr, {}) |
| 54 | self.assertEqual(None, help_data['cue']) |
| 55 | |
| 56 | # This is a project member who has set up mailing lists and added |
| 57 | # members, but has not noted any duties. |
| 58 | mr = testing_helpers.MakeMonorailRequest(project=self.project) |
| 59 | self.project.issue_notify_address = 'example@domain.com' |
| 60 | self.project.committer_ids.extend([111, 222]) |
| 61 | help_data = self.servlet.GatherHelpData(mr, {}) |
| 62 | self.assertEqual('document_team_duties', help_data['cue']) |
| 63 | |
| 64 | # Now help set up notes too. |
| 65 | project_commitments = project_pb2.ProjectCommitments() |
| 66 | project_commitments.project_id = self.project.project_id |
| 67 | project_commitments.commitments.append( |
| 68 | project_pb2.ProjectCommitments.MemberCommitment()) |
| 69 | self.servlet.services.project.TestStoreProjectCommitments( |
| 70 | project_commitments) |
| 71 | help_data = self.servlet.GatherHelpData(mr, {}) |
| 72 | self.assertEqual(None, help_data['cue']) |
| 73 | |
| 74 | def testGatherHelpData_Dismissed(self): |
| 75 | mr = testing_helpers.MakeMonorailRequest(project=self.project) |
| 76 | mr.auth.user_id = 111 |
| 77 | self.project.committer_ids.extend([111, 222]) |
| 78 | self.servlet.services.user.SetUserPrefs( |
| 79 | 'cnxn', 111, |
| 80 | [user_pb2.UserPrefValue(name='document_team_duties', value='true')]) |
| 81 | help_data = self.servlet.GatherHelpData(mr, {}) |
| 82 | self.assertEqual(None, help_data['cue']) |