Workflow.py
1 ############################ Copyrights and license ############################ 2 # # 3 # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # 4 # # 5 # This file is part of PyGithub. # 6 # http://pygithub.readthedocs.io/ # 7 # # 8 # PyGithub is free software: you can redistribute it and/or modify it under # 9 # the terms of the GNU Lesser General Public License as published by the Free # 10 # Software Foundation, either version 3 of the License, or (at your option) # 11 # any later version. # 12 # # 13 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # 14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # 15 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # 16 # details. # 17 # # 18 # You should have received a copy of the GNU Lesser General Public License # 19 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # 20 # # 21 ################################################################################ 22 23 from datetime import datetime, timezone 24 25 from . import Framework 26 27 28 class Workflow(Framework.TestCase): 29 def setUp(self): 30 super().setUp() 31 self.workflow = self.g.get_repo("PyGithub/PyGithub").get_workflow("check.yml") 32 33 def testAttributes(self): 34 self.assertEqual( 35 repr(self.workflow), 36 'Workflow(url="https://api.github.com/repos/PyGithub/PyGithub/actions/workflows/1026390", name="check")', 37 ) 38 self.assertEqual(self.workflow.id, 1026390) 39 self.assertEqual(self.workflow.name, "check") 40 self.assertEqual(self.workflow.path, ".github/workflows/check.yml") 41 self.assertEqual(self.workflow.state, "active") 42 timestamp = datetime(2020, 4, 15, 0, 48, 32, tzinfo=timezone.utc) 43 self.assertEqual(self.workflow.created_at, timestamp) 44 self.assertEqual(self.workflow.updated_at, timestamp) 45 self.assertEqual( 46 self.workflow.url, 47 "https://api.github.com/repos/PyGithub/PyGithub/actions/workflows/1026390", 48 ) 49 self.assertEqual( 50 self.workflow.html_url, 51 "https://github.com/PyGithub/PyGithub/blob/master/.github/workflows/check.yml", 52 ) 53 self.assertEqual( 54 self.workflow.badge_url, 55 "https://github.com/PyGithub/PyGithub/workflows/check/badge.svg", 56 ) 57 58 def testGetRunsWithNoArguments(self): 59 self.assertListKeyEqual( 60 self.workflow.get_runs(), 61 lambda r: r.id, 62 [109950033, 109168419, 108934155, 108817672], 63 ) 64 65 def testGetRunsWithObjects(self): 66 sfdye = self.g.get_user("sfdye") 67 master = self.g.get_repo("PyGithub/PyGithub").get_branch("master") 68 self.assertListKeyEqual( 69 self.workflow.get_runs(actor=sfdye, branch=master, event="push", status="completed"), 70 lambda r: r.id, 71 [100957683, 94845611, 93946842, 92714488], 72 ) 73 74 def testGetRunsWithStrings(self): 75 self.assertListKeyEqual( 76 self.workflow.get_runs(actor="s-t-e-v-e-n-k", branch="master"), 77 lambda r: r.id, 78 [109950033, 108817672, 108794468, 107927403, 105213061, 105212023], 79 ) 80 81 def testGetRunsWithHeadSha(self): 82 self.assertListKeyEqual( 83 self.workflow.get_runs(head_sha="3a6235b56eecc0e193c1e267b064c155c6ebc022"), 84 lambda r: r.id, 85 [3349872717], 86 ) 87 88 def testCreateDispatchWithBranch(self): 89 dispatch_inputs = {"logLevel": "Warning", "message": "Log Message"} 90 workflow = self.g.get_repo("wrecker/PyGithub").get_workflow("manual_dispatch.yml") 91 branch = self.g.get_repo("wrecker/PyGithub").get_branch("workflow_dispatch_branch") 92 self.assertTrue(workflow.create_dispatch(branch, dispatch_inputs)) 93 94 def testCreateDispatchWithTag(self): 95 dispatch_inputs = {"logLevel": "Warning", "message": "Log Message"} 96 workflow = self.g.get_repo("wrecker/PyGithub").get_workflow("manual_dispatch.yml") 97 tags = self.g.get_repo("wrecker/PyGithub").get_tags() 98 tag = [t for t in tags if t.name == "workflow_dispatch_tag"].pop() 99 self.assertTrue(workflow.create_dispatch(tag, dispatch_inputs)) 100 101 def testCreateDispatchWithString(self): 102 dispatch_inputs = {"logLevel": "Warning", "message": "Log Message"} 103 workflow = self.g.get_repo("wrecker/PyGithub").get_workflow("manual_dispatch.yml") 104 ref_str = "main" 105 self.assertTrue(workflow.create_dispatch(ref_str, dispatch_inputs)) 106 107 def testCreateDispatchForNonTriggerEnabled(self): 108 workflow = self.g.get_repo("wrecker/PyGithub").get_workflow("check.yml") 109 self.assertFalse(workflow.create_dispatch("main"))