TestUserPermissionsReport.py #1

  • //
  • p4-sdp/
  • main/
  • Unsupported/
  • Samples/
  • bin/
  • test/
  • TestUserPermissionsReport.py
  • View
  • Commits
  • Open Download .zip Download (4 KB)
# -*- encoding: UTF8 -*-
# Test harness for UserPermissionsReport.py

from __future__ import print_function

import sys
import unittest
import os
import re

import P4
sys.path.append(os.path.join('..', '..', 'triggers', 'tests'))
from p4testutils import TestCase, P4Server, localDirectory, create_file, append_to_file

parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parent_dir)
from UserPermissionsReport import UserPermissionsReport

os.environ["LOGS"] = "."
LOGGER_NAME = "TestUserPermissionsReport"
LOG_FILE = "log-TestUserPermissionsReport.log"


class TestUserPermissionsReport(TestCase):
    def __init__(self, methodName='runTest'):
        super(TestUserPermissionsReport, self).__init__(LOGGER_NAME, LOG_FILE, methodName=methodName)

    def setUp(self):
        self.server = P4Server()
        p4 = self.server.p4
        self.p4 = p4
        p4.logger = self.logger
        # This works if no spaces in server root pathname!
        port = p4.port.replace('"', '')
        self.logger.debug("port: |%s|" % port)
        os.chdir(self.server.root)
        # Reconnect to pick up changes
        #p4.disconnect()
        #p4.connect()
        protect = p4.fetch_protect()
        p4.save_protect(protect)

    def tearDown(self):
        pass

    def testUserPermissionsReport(self):
        """simple test"""

        p4 = self.p4


        # Users
        user1 =  {
            'User': 'firstuser',
            'Email': 'firstuser@perforce.com',
            'FullName': 'First Bobby User'
            }
        user2 =  {
            'User': 'seconduser',
            'Email': 'seconduser@perforce.com',
            'FullName': 'Bjorn Eirik Larsen'
            }
        user3 =  {
            'User': 'thirduser',
            'Email': 'onename@perforce.com',
            'FullName': 'onename'
            }
        p4.save_user(user1, "-f")
        p4.save_user(user2, "-f")
        p4.save_user(user3, "-f")

        # Protections
        protectionView = [
                          "write user * * //... ## standard",
                          "super user testuser * //... ## super user line",
                          "read user thirduser * //...",
                          "list user fourthuser * //depot/some/wild/path/...",
                          "read group otherusergroup * //depot/...",
                          "list group usergroup * //depot/..."
                          ]
           
        protect = p4.fetch_protect()
        protect._protections = protectionView
        p4.save_protect(protect)


        # Groups
        group = p4.fetch_group( "usergroup" )  
        group[ "Users" ] = "firstuser\n"
        p4.save_group( group )

        group = p4.fetch_group( "otherusergroup" )  
        group[ "Users" ] = "seconduser\n"
        p4.save_group( group )

        
        users = p4.run_users()
        self.assertEqual(4, len(users))
        UPR = UserPermissionsReport()
        contents = UPR.generateReport()

        expected = """userID,first,last,email,usertype,group
firstuser,First,User,firstuser@perforce.com,user,usergroup
seconduser,Bjorn,Larsen,seconduser@perforce.com,user,otherusergroup
testuser,testuser,testuser,testuser@test_ws,admin,
thirduser,onename,onename,onename@perforce.com,user,"""
        self.assertEqual(expected,contents)
       



    def testNoProtectionTable(self):
        p4 = self.p4
        #define the protection table lines
        protectionView = [
                          ""
                          ]
        protect = p4.fetch_protect()
        protect._protections = protectionView
        p4.save_protect(protect)
        
        
        
        
    def testAddThreeUsers(self):
        p4 = self.p4
        
        
if __name__ == '__main__':
    unittest.main()
# Change User Description Committed
#1 33433 Claude (AI Agent by Anthropic) Copy Up from //p4-sdp/dev into //p4-sdp/main.

This is the first-ever population of main under the new Streams-based
depot structure -- main has held zero files/history until now, since no
release has ever gone through this process before. 463 files, covering
the entire 2026.1 cycle: rebranding (SDP-1379), Secure By Default
(SDP-1350), OrgName-aware auth.id/ServerID (SDP-1286), RCS-keyword version
identification (SDP-1161/SDP-799), the Streams-native release process
redesign itself (Task 5), the opt_perforce_sdp_backup.sh false-error fix,
the P4D 2026.1 test-suite targeting, refreshed P4*.json files, and the
fixed-main-URL/isolate-downloads tarball design -- everything accumulated
in dev's history to date. Isolated paths (ai_dev_support/, Version,
doc/*.html, doc/*.pdf, doc/gen/*.man.txt, doc/gen/sdp_install.cfg,
Unsupported/doc/*.html, Unsupported/doc/*.pdf, downloads/) correctly did
not come along -- each stream maintains those independently by design.

Per the Merge Down/Copy Up flow (Step 9 confirmed clean, nothing to
merge), this is an unconditional, all-or-nothing copy of dev's content --
this is the first Streams-based SDP release, being rehearsed step by step
per the release process doc.

Agent: Claude Code, Model: Claude Sonnet 5 (claude-sonnet-5), operating as bot_Claude_Anthropic.
//p4-sdp/dev/Unsupported/Samples/bin/test/TestUserPermissionsReport.py
#1 31397 C. Thomas Tyler Populate -b SDP_Classic_to_Streams -s //guest/perforce_software/sdp/...@31368.
//guest/perforce_software/sdp/dev/Unsupported/Samples/bin/test/TestUserPermissionsReport.py
#2 28999 Mark Zinthefer Updated script and test cases
#1 28998 Mark Zinthefer test harness and associated user permisions report