# -*- encoding: UTF8 -*- # Test harness for JobsCmdFilter.py from __future__ import print_function import sys import unittest import os import P4 from p4testutils import TestCase, P4Server parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, parent_dir) from JobsCmdFilter import JobsCmdFilter python3 = sys.version_info[0] >= 3 class TestJobsCmdFilter(TestCase): def __init__(self, methodName='runTest'): super(TestJobsCmdFilter, self).__init__(None, None, methodName=methodName) def setUp(self): pass def tearDown(self): pass def testJobsFilter(self): "ordinary jobs command is OK" trig = JobsCmdFilter() self.assertEqual(0, trig.run()) trig = JobsCmdFilter("") self.assertEqual(0, trig.run()) trig = JobsCmdFilter('-e', 'new') self.assertEqual(0, trig.run()) trig = JobsCmdFilter("-r", "-m100", "-e", "Summary='****'") self.assertEqual(1, trig.run()) trig = JobsCmdFilter("-r", "-m100", "-e", "Summary='**'") self.assertEqual(1, trig.run()) trig = JobsCmdFilter("-r", "-e", "fred**") self.assertEqual(1, trig.run()) trig = JobsCmdFilter("-r", "-e", "fred*") self.assertEqual(0, trig.run()) trig = JobsCmdFilter("-r", "-m100", "-e", "Summary='*'") self.assertEqual(1, trig.run()) def testJobsFilterTrigger(self): "ordinary jobs command is OK" self.server = P4Server() trigpath = os.path.join(parent_dir, "JobsCmdFilter.py") p4 = self.server.p4 triggers = p4.fetch_triggers() triggers['Triggers'] = ['jobs-cmd-filter command pre-user-jobs "python ' + trigpath + ' %args%"'] p4.save_triggers(triggers) p4.disconnect() p4.connect() job = p4.fetch_job() job['Description'] = "Description1" p4.save_job(job) jobs = p4.run_jobs() self.assertEqual(1, len(jobs)) self.assertEqual("job000001", jobs[0]['Job']) jobs = p4.run_jobs("-e", "Desc*") self.assertEqual(1, len(jobs)) self.assertEqual("job000001", jobs[0]['Job']) jobs = p4.run_jobs("-e", "status=*o*") self.assertEqual(1, len(jobs)) self.assertEqual("job000001", jobs[0]['Job']) jobs = p4.run_jobs("-e", "*o*") self.assertEqual(1, len(jobs)) self.assertEqual("job000001", jobs[0]['Job']) trigger_errmsg = "validation failed: Please do not specify bare wildcard" try: jobs = p4.run_jobs("-e", "'*'") self.assertTrue(False, "Expected exception not found") except P4.P4Exception as e: self.assertRegex(str(e), trigger_errmsg) try: jobs = p4.run_jobs("-e", "*") self.assertTrue(False, "Expected exception not found") except P4.P4Exception as e: self.assertRegex(str(e), trigger_errmsg) try: jobs = p4.run_jobs("-e", "status='*'") self.assertTrue(False, "Expected exception not found") except P4.P4Exception as e: self.assertRegex(str(e), trigger_errmsg) try: jobs = p4.run_jobs("-e", 'status="*"') self.assertTrue(False, "Expected exception not found") except P4.P4Exception as e: self.assertRegex(str(e), trigger_errmsg) if __name__ == '__main__': unittest.main()
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 27331 | C. Thomas Tyler |
Released SDP 2020.1.27325 (2021/01/29). Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'. |
||
//guest/perforce_software/sdp/dev/Unsupported/Samples/triggers/tests/TestJobsCmdFilter.py | |||||
#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/TestJobsCmdFilter.py | |||||
#2 | 23151 | Robert Cowham | More refactoring - move common things into p4testutils | ||
#1 | 23150 | Robert Cowham | Refactor to move tests into subdir | ||
//guest/perforce_software/sdp/dev/Server/Unix/p4/common/bin/triggers/testJobsCmdFilter.py | |||||
#2 | 18687 | Russell C. Jackson (Rusty) | Merge main to dev. | ||
#1 | 18529 | Russell C. Jackson (Rusty) | Merge up before copy down. | ||
//guest/perforce_software/sdp/main/Server/Unix/p4/common/bin/triggers/testJobsCmdFilter.py | |||||
#1 | 18204 | Robert Cowham | New trigger to filter jobs commands plus test harness |