self.assertFalse(acl.can_read_config_set('projects/secret')) auth.is_group_member.side_effect = lambda name, *_: name == 'googlers' self.assertTrue(acl.can_read_config_set('projects/secret')) auth.is_group_member.side_effect = lambda name, *_: name == 'project-admins' self.assertTrue(acl.can_read_config_set('projects/secret')) def test_has_project_access_identity(self): self.mock(projects, 'get_metadata', mock.Mock()) projects.get_metadata.return_value = project_config_pb2.ProjectCfg( access=['group:googlers', '*****@*****.**'] ) self.assertFalse(acl.can_read_config_set('projects/secret')) auth.get_current_identity.return_value = auth.Identity('user', '*****@*****.**') self.assertTrue(acl.can_read_config_set('projects/secret')) def test_can_read_project_config_no_access(self): self.assertFalse(acl.has_project_access('projects/swarming')) self.assertFalse(acl.can_read_config_set('projects/swarming/refs/heads/x')) def test_malformed_config_set(self): with self.assertRaises(ValueError): acl.can_read_config_set('invalid config set') if __name__ == '__main__': test_env.main()
removed = [] self.mock(os, 'remove', removed.append) self.mock(net, 'url_open', lambda url, **_kwargs: timeouting_http_response(url)) self.assertEqual( False, net.url_retrieve('filepath', 'https://localhost/test')) self.assertEqual(['filepath'], removed) class TestNetFunctions(auto_stub.TestCase): def test_fix_url(self): data = [ ('http://foo.com/', 'http://foo.com'), ('https://foo.com/', 'https://foo.com'), ('https://foo.com', 'https://foo.com'), ('https://foo.com/a', 'https://foo.com/a'), ('https://foo.com/a/', 'https://foo.com/a'), ('https://foo.com:8080/a/', 'https://foo.com:8080/a'), ('foo.com', 'https://foo.com'), ('foo.com:8080', 'https://foo.com:8080'), ('foo.com/', 'https://foo.com'), ('foo.com/a/', 'https://foo.com/a'), ] for value, expected in data: self.assertEqual(expected, net.fix_url(value)) if __name__ == '__main__': test_env.main()
cs1 = [self.cm('1') for _ in xrange(5)] cs2 = [ self.cm('2', [cs1[3]]), # simulates an out-of-order dependency (revert) self.cm('2', [cs1[0]]), self.cm('2', [cs1[0]]), self.cm('2', [cs1[1]]), self.cm('2', [cs1[3]]), self.cm('2', [cs1[3]]), ] cl1 = CommitList(cs1) self.assertEqual(cl1.dist_compatible_with('2', cs2[0].revision), 0) cl2 = CommitList(cs2) # current one is compatible, so distance is 0 self.assertEqual(cl2.dist_compatible_with('1', cs1[3].revision), 0) cl2.advance() # now the version is cs1[0], so the distance is 3 self.assertEqual(cl2.dist_compatible_with('1', cs1[3].revision), 3) self.assertEqual(cl2.dist_compatible_with('1', 'not_a_known_commit'), 5) cl2.advance() # and now it's 2 self.assertEqual(cl2.dist_compatible_with('1', cs1[3].revision), 2) if __name__ == '__main__': sys.exit(test_env.main())