def test_github(self) -> None: """Tests /osm/webhooks/github.""" environ: Dict[str, BinaryIO] = {} root = {"ref": "refs/heads/master"} payload = json.dumps(root) body = {"payload": [payload]} query_string = urllib.parse.urlencode(body, doseq=True) buf = io.BytesIO() buf.write(query_string.encode('utf-8')) buf.seek(0) environ["wsgi.input"] = buf actual_args: List[str] = [] actual_check = False actual_path = "" def mock_subprocess_run(args: List[str], check: bool, env: Any) -> None: nonlocal actual_args nonlocal actual_check nonlocal actual_path actual_args = args actual_check = check actual_path = env["PATH"] with unittest.mock.patch('subprocess.run', mock_subprocess_run): wsgi.handle_github_webhook(environ) self.assertEqual(actual_args[0], "make") self.assertEqual(actual_args[-1], "deploy-pythonanywhere") self.assertTrue(actual_check) self.assertIn("osm-gimmisn-env/bin", actual_path)
def test_github_branch(self) -> None: """Tests /osm/webhooks/github, the case when a non-master branch is updated.""" environ: Dict[str, BinaryIO] = {} root = {"ref": "refs/heads/stable"} payload = json.dumps(root) body = {"payload": [payload]} query_string = urllib.parse.urlencode(body, doseq=True) buf = io.BytesIO() buf.write(query_string.encode('utf-8')) buf.seek(0) environ["wsgi.input"] = buf invoked = False def mock_subprocess_run(_args: List[str], _check: bool) -> None: nonlocal invoked with unittest.mock.patch('subprocess.run', mock_subprocess_run): wsgi.handle_github_webhook(environ) self.assertFalse(invoked)