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