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 """Unit tests for project_views module.""" |
| 7 |
| 8 import unittest |
| 9 |
| 10 from framework import framework_views |
| 11 from project import project_views |
| 12 from proto import project_pb2 |
| 13 from services import service_manager |
| 14 from testing import fake |
| 15 |
| 16 |
| 17 class ProjectAccessViewTest(unittest.TestCase): |
| 18 |
| 19 def testAccessViews(self): |
| 20 anyone_view = project_views.ProjectAccessView( |
| 21 project_pb2.ProjectAccess.ANYONE) |
| 22 self.assertEqual(anyone_view.key, int(project_pb2.ProjectAccess.ANYONE)) |
| 23 |
| 24 members_only_view = project_views.ProjectAccessView( |
| 25 project_pb2.ProjectAccess.MEMBERS_ONLY) |
| 26 self.assertEqual(members_only_view.key, |
| 27 int(project_pb2.ProjectAccess.MEMBERS_ONLY)) |
| 28 |
| 29 |
| 30 class ProjectViewTest(unittest.TestCase): |
| 31 |
| 32 def setUp(self): |
| 33 self.services = service_manager.Services( |
| 34 project=fake.ProjectService(), |
| 35 user=fake.UserService()) |
| 36 self.services.project.TestAddProject('test') |
| 37 |
| 38 def testNormalProject(self): |
| 39 project = self.services.project.GetProjectByName('fake cnxn', 'test') |
| 40 project_view = project_views.ProjectView(project) |
| 41 self.assertEqual('test', project_view.project_name) |
| 42 self.assertEqual('/p/test', project_view.relative_home_url) |
| 43 self.assertEqual('LIVE', project_view.state_name) |
| 44 |
| 45 def testCachedContentTimestamp(self): |
| 46 project = self.services.project.GetProjectByName('fake cnxn', 'test') |
| 47 |
| 48 # Project was never updated since we added cached_content_timestamp. |
| 49 project.cached_content_timestamp = 0 |
| 50 view = project_views.ProjectView(project, now=1 * 60 * 60 + 234) |
| 51 self.assertEqual(1 * 60 * 60, view.cached_content_timestamp) |
| 52 |
| 53 # Project was updated within the last hour, use that timestamp. |
| 54 project.cached_content_timestamp = 1 * 60 * 60 + 123 |
| 55 view = project_views.ProjectView(project, now=1 * 60 * 60 + 234) |
| 56 self.assertEqual(1 * 60 * 60 + 123, view.cached_content_timestamp) |
| 57 |
| 58 # Project was not updated within the last hour, but user groups |
| 59 # could have been updated on groups.google.com without any |
| 60 # notification to us, so the client will ask for an updated feed |
| 61 # at least once an hour. |
| 62 project.cached_content_timestamp = 1 * 60 * 60 + 123 |
| 63 view = project_views.ProjectView(project, now=2 * 60 * 60 + 234) |
| 64 self.assertEqual(2 * 60 * 60, view.cached_content_timestamp) |
| 65 |
| 66 |
| 67 class MemberViewTest(unittest.TestCase): |
| 68 |
| 69 def setUp(self): |
| 70 self.alice_view = framework_views.UserView(111L, 'alice', True) |
| 71 self.bob_view = framework_views.UserView(222L, 'bob', True) |
| 72 self.carol_view = framework_views.UserView(333L, 'carol', True) |
| 73 |
| 74 self.project = project_pb2.Project() |
| 75 self.project.project_name = 'proj' |
| 76 self.project.owner_ids.append(111L) |
| 77 self.project.committer_ids.append(222L) |
| 78 self.project.contributor_ids.append(333L) |
| 79 |
| 80 def testViewingSelf(self): |
| 81 member_view = project_views.MemberView( |
| 82 0, 111L, self.alice_view, self.project, None) |
| 83 self.assertFalse(member_view.viewing_self) |
| 84 member_view = project_views.MemberView( |
| 85 222L, 111L, self.alice_view, self.project, None) |
| 86 self.assertFalse(member_view.viewing_self) |
| 87 |
| 88 member_view = project_views.MemberView( |
| 89 111L, 111L, self.alice_view, self.project, None) |
| 90 self.assertTrue(member_view.viewing_self) |
| 91 |
| 92 def testRoles(self): |
| 93 member_view = project_views.MemberView( |
| 94 0, 111L, self.alice_view, self.project, None) |
| 95 self.assertEqual('Owner', member_view.role) |
| 96 self.assertEqual('/p/proj/people/detail?u=111', |
| 97 member_view.detail_url) |
| 98 |
| 99 member_view = project_views.MemberView( |
| 100 0, 222L, self.bob_view, self.project, None) |
| 101 self.assertEqual('Committer', member_view.role) |
| 102 self.assertEqual('/p/proj/people/detail?u=222', |
| 103 member_view.detail_url) |
| 104 |
| 105 member_view = project_views.MemberView( |
| 106 0, 333L, self.carol_view, self.project, None) |
| 107 self.assertEqual('Contributor', member_view.role) |
| 108 self.assertEqual('/p/proj/people/detail?u=333', |
| 109 member_view.detail_url) |
| 110 |
| 111 |
| 112 if __name__ == '__main__': |
| 113 unittest.main() |
OLD | NEW |