blob: 033664d1c245dee49ae6d384e9dbfbc7aef666cf [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)
39 self.assertEqual(
40 '<p>desc</p>', page_data['formatted_project_description'])
41 self.assertEqual(
42 int(project_pb2.ProjectAccess.ANYONE), page_data['access_level'].key)
43 self.assertEqual(0, page_data['num_stars'])
44 self.assertEqual('s', page_data['plural'])
45
46 def testGatherHelpData(self):
47 mr = testing_helpers.MakeMonorailRequest(project=self.project)
48
49 # Non-members cannot edit project, so cue is not relevant.
50 mr.perms = permissions.READ_ONLY_PERMISSIONSET
51 help_data = self.servlet.GatherHelpData(mr, {})
52 self.assertEqual(None, help_data['cue'])
53
54 # Members (not owners) cannot edit project, so cue is not relevant.
55 mr.perms = permissions.READ_ONLY_PERMISSIONSET
56 help_data = self.servlet.GatherHelpData(mr, {})
57 self.assertEqual(None, help_data['cue'])
58
59 # This is a project member who has set up mailing lists and added
60 # members, but has not noted any duties.
61 mr = testing_helpers.MakeMonorailRequest(project=self.project)
62 self.project.issue_notify_address = 'example@domain.com'
63 self.project.committer_ids.extend([111, 222])
64 help_data = self.servlet.GatherHelpData(mr, {})
65 self.assertEqual('document_team_duties', help_data['cue'])
66
67 # Now help set up notes too.
68 project_commitments = project_pb2.ProjectCommitments()
69 project_commitments.project_id = self.project.project_id
70 project_commitments.commitments.append(
71 project_pb2.ProjectCommitments.MemberCommitment())
72 self.servlet.services.project.TestStoreProjectCommitments(
73 project_commitments)
74 help_data = self.servlet.GatherHelpData(mr, {})
75 self.assertEqual(None, help_data['cue'])
76
77 def testGatherHelpData_Dismissed(self):
78 mr = testing_helpers.MakeMonorailRequest(project=self.project)
79 mr.auth.user_id = 111
80 self.project.committer_ids.extend([111, 222])
81 self.servlet.services.user.SetUserPrefs(
82 'cnxn', 111,
83 [user_pb2.UserPrefValue(name='document_team_duties', value='true')])
84 help_data = self.servlet.GatherHelpData(mr, {})
85 self.assertEqual(None, help_data['cue'])