blob: 6f6373bf32158642bda745574310628da0eb238c [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# 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.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Unittests for Project Summary servlet."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10import unittest
11
12from framework import permissions
13from project import projectsummary
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010014from mrproto import project_pb2
15from mrproto import user_pb2
Copybara854996b2021-09-07 19:36:02 +000016from services import service_manager
17from testing import fake
18from testing import testing_helpers
19
20
21class 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ínezf19ea432024-01-23 20:20:52 +010032 self.servlet = projectsummary.ProjectSummary(services=services)
Copybara854996b2021-09-07 19:36:02 +000033
34 def testGatherPageData(self):
35 mr = testing_helpers.MakeMonorailRequest(project=self.project)
36 page_data = self.servlet.GatherPageData(mr)
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020037 self.assertEqual('desc', page_data['formatted_project_description'])
Copybara854996b2021-09-07 19:36:02 +000038 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'])