# -*- encoding: UTF8 -*-
# Test harness for ControlStreamCreation.py
from __future__ import print_function
import sys
import unittest
import os
import re
import P4
from p4testutils import TestCase, P4Server, localDirectory, create_file, append_to_file
python3 = sys.version_info[0] >= 3
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parent_dir)
from ControlStreamCreation import ControlStreamCreation
os.environ["LOGS"] = "."
LOGGER_NAME = "TestControlStreamCreation"
LOG_FILE = "log-TestControlStreamCreation.log"
class TestControlStreamCreation(TestCase):
def __init__(self, methodName='runTest'):
super(TestControlStreamCreation, self).__init__(LOGGER_NAME, LOG_FILE, methodName=methodName)
def setUp(self):
self.server = P4Server()
trigpath = os.path.join(parent_dir, "ControlStreamCreation.py")
self.config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "~test_config.yaml")
p4 = self.server.p4
self.p4 = p4
p4.logger = self.logger
depot = p4.fetch_depot("streams")
depot["Type"] = "stream"
p4.save_depot(depot)
# This works if no spaces in server root pathname!
port = p4.port.replace('"', '')
self.logger.debug("port: |%s|" % port)
triggers = p4.fetch_triggers()
triggers['Triggers'] = ['control-stream-creation form-save stream " python {} -p %quote%{}%quote% '
'-u {} -c {} %user% %formfile% "'.format(trigpath, port, p4.user, self.config_path),
]
self.logger.debug(triggers)
p4.save_triggers(triggers)
# Reconnect to pick up changes
p4.disconnect()
p4.connect()
def tearDown(self):
pass
def testControlStreamCreation(self):
"""check that it works when called as a trigger"""
p4 = self.p4
with open(self.config_path, "w") as f:
f.write("""
msg_cant_create_stream:
- ""
- "You are not allowed to create new streams."
- "Check with the admins to be added to an appropriate group."
can_create_streams:
- name: All projects
stream_paths:
- ".*"
allowed_users_groups:
- user1
- group1
- group2
""")
stream = p4.fetch_stream("-tmainline", "//streams/main")
try:
p4.save_stream(stream)
self.assertTrue(False, "Expected exception not found")
except P4.P4Exception as e:
self.assertRegex(str(e), r"You are not allowed to create new streams")
with open(self.config_path, "w") as f:
f.write("""
msg_cant_create_stream:
- ""
- "You are not allowed to create new streams."
- "Check with the admins to be added to an appropriate group."
can_create_streams:
- name: All projects
stream_paths:
- ".*"
allowed_users_groups:
- testuser
""")
stream = p4.fetch_stream("-tmainline", "//streams/main")
p4.save_stream(stream)
with open(self.config_path, "w") as f:
f.write("""
msg_cant_create_stream:
- ""
- "You are not allowed to create new streams."
- "Check with the admins to be added to an appropriate group."
can_create_streams:
- name: All projects
stream_paths:
- "//streams/.*2"
allowed_users_groups:
- anotheruser
""")
stream = p4.fetch_stream("-tmainline", "//streams/main2")
try:
p4.save_stream(stream)
self.assertTrue(False, "Expected exception not found")
except P4.P4Exception as e:
self.assertRegex(str(e), r"You are not allowed to create new streams")
with open(self.config_path, "w") as f:
f.write("""
msg_cant_create_stream:
- ""
- "You are not allowed to create new streams."
- "Check with the admins to be added to an appropriate group."
can_create_streams:
- name: All projects
stream_paths:
- "//streams/.*2"
allowed_users_groups:
- testuser
""")
stream = p4.fetch_stream("-tmainline", "//streams/main2")
p4.save_stream(stream)
with open(self.config_path, "w") as f:
f.write("""
msg_cant_create_stream:
- ""
- "You are not allowed to create new streams."
- "Check with the admins to be added to an appropriate group."
can_create_streams:
- name: All projects
stream_paths:
- "//streams/.*"
allowed_users_groups:
- anotheruser
""")
stream = p4.fetch_stream("-tmainline", "//streams/main3")
try:
p4.save_stream(stream)
self.assertTrue(False, "Expected exception not found")
except P4.P4Exception as e:
self.assertRegex(str(e), r"You are not allowed to create new streams")
if __name__ == '__main__':
unittest.main()
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #1 | 33444 | Claude (AI Agent by Anthropic) | Initial population of r26.1.0.BETA from main. | ||
| //p4-sdp/main/Unsupported/Samples/triggers/tests/TestControlStreamCreation.py | |||||
| #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/triggers/tests/TestControlStreamCreation.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/triggers/tests/TestControlStreamCreation.py | |||||
| #2 | 28995 | Robert Cowham | Fix broken test | ||
| #1 | 26652 | Robert Cowham |
This is Tom's change: Introduced new 'Unsupported' directory to clarify that some files in the SDP are not officially supported. These files are samples for illustration, to provide examples, or are deprecated but not yet ready for removal from the package. The Maintenance and many SDP triggers have been moved under here, along with other SDP scripts and triggers. Added comments to p4_vars indicating that it should not be edited directly. Added reference to an optional site_global_vars file that, if it exists, will be sourced to provide global user settings without needing to edit p4_vars. As an exception to the refactoring, the totalusers.py Maintenance script will be moved to indicate that it is supported. Removed settings to support long-sunset P4Web from supported structure. Structure under new .../Unsupported folder is: Samples/bin Sample scripts. Samples/triggers Sample trigger scripts. Samples/triggers/tests Sample trigger script tests. Samples/broker Sample broker filter scripts. Deprecated/triggers Deprecated triggers. To Do in a subsequent change: Make corresponding doc changes. |
||
| //guest/perforce_software/sdp/dev/Server/Unix/p4/common/bin/triggers/tests/TestControlStreamCreation.py | |||||
| #2 | 26435 | Robert Cowham | New trigger for OSRAM Continental | ||
| #1 | 26049 | Robert Cowham | Allow only certain people (or group members) to create streams | ||