def test_delete_pr_preview_required_args(self): cli = create_cli([ "delete-pr-preview", "--username", "USER", "--password", "PASS", "--git-user", "GIT_USER", "--git-email", "GIT_EMAIL", "--organisation", "ORG", "--repository-name", "REPO", "--branch", "BRANCH", ]) self.assertEqual(cli.command, "delete-pr-preview") self.assertEqual(cli.username, "USER") self.assertEqual(cli.password, "PASS") self.assertEqual(cli.git_user, "GIT_USER") self.assertEqual(cli.git_email, "GIT_EMAIL") self.assertEqual(cli.organisation, "ORG") self.assertEqual(cli.repository_name, "REPO") self.assertEqual(cli.branch, "BRANCH") self.assertIsNone(cli.git_provider) self.assertIsNone(cli.git_provider_url) self.assertFalse(cli.verbose)
def test_sync_apps_required_args(self): cli = create_cli([ "sync-apps", "--username", "USER", "--password", "PASS", "--git-user", "GIT_USER", "--git-email", "GIT_EMAIL", "--organisation", "ORG", "--repository-name", "REPO", "--root-organisation", "ROOT_ORGA", "--root-repository-name", "ROOT_REPO", ]) self.assertEqual(cli.command, "sync-apps") self.assertEqual(cli.username, "USER") self.assertEqual(cli.password, "PASS") self.assertEqual(cli.git_user, "GIT_USER") self.assertEqual(cli.git_email, "GIT_EMAIL") self.assertEqual(cli.organisation, "ORG") self.assertEqual(cli.repository_name, "REPO") self.assertEqual(cli.root_organisation, "ROOT_ORGA") self.assertEqual(cli.root_repository_name, "ROOT_REPO") self.assertIsNone(cli.git_provider) self.assertIsNone(cli.git_provider_url) self.assertFalse(cli.verbose)
def test_create_preview_required_args(self): cli = create_cli([ "create-preview", "--username", "USER", "--password", "PASS", "--git-user", "GIT_USER", "--git-email", "GIT_EMAIL", "--organisation", "ORG", "--repository-name", "REPO", "--git-hash", "c0784a34e834117e1489973327ff4ff3c2582b94", "--preview-id", "abc123", ]) self.assertEqual(cli.command, "create-preview") self.assertEqual(cli.username, "USER") self.assertEqual(cli.password, "PASS") self.assertEqual(cli.git_user, "GIT_USER") self.assertEqual(cli.git_email, "GIT_EMAIL") self.assertEqual(cli.organisation, "ORG") self.assertEqual(cli.repository_name, "REPO") self.assertEqual(cli.git_hash, "c0784a34e834117e1489973327ff4ff3c2582b94") self.assertEqual(cli.preview_id, "abc123") self.assertIsNone(cli.git_provider) self.assertIsNone(cli.git_provider_url) self.assertFalse(cli.verbose)
def test_add_pr_comment_all_args(self): cli = create_cli([ "add-pr-comment", "--username", "USER", "--password", "PASS", "--git-provider", "GIT_PROVIDER", "--git-provider-url", "GIT_PROVIDER_URL", "--organisation", "ORG", "--repository-name", "REPO", "--pr-id", "4711", "--parent-id", "42", "--text", "TEXT", "--verbose", ]) self.assertEqual(cli.command, "add-pr-comment") self.assertEqual(cli.username, "USER") self.assertEqual(cli.password, "PASS") self.assertEqual(cli.git_provider, "GIT_PROVIDER") self.assertEqual(cli.git_provider_url, "GIT_PROVIDER_URL") self.assertEqual(cli.organisation, "ORG") self.assertEqual(cli.repository_name, "REPO") self.assertEqual(cli.pr_id, 4711) self.assertEqual(cli.parent_id, 42) self.assertEqual(cli.text, "TEXT") self.assertTrue(cli.verbose)
def test_add_pr_comment_required_args(self): cli = create_cli([ "add-pr-comment", "--username", "USER", "--password", "PASS", "--organisation", "ORG", "--repository-name", "REPO", "--pr-id", "4711", "--text", "TEXT", ]) self.assertEqual(cli.command, "add-pr-comment") self.assertEqual(cli.username, "USER") self.assertEqual(cli.password, "PASS") self.assertEqual(cli.organisation, "ORG") self.assertEqual(cli.repository_name, "REPO") self.assertEqual(cli.pr_id, 4711) self.assertEqual(cli.text, "TEXT") self.assertIsNone(cli.parent_id) self.assertIsNone(cli.git_provider) self.assertIsNone(cli.git_provider_url) self.assertFalse(cli.verbose)
def test_deploy_all_args(self): cli = create_cli([ "deploy", "--username", "USER", "--password", "PASS", "--git-user", "GIT_USER", "--git-email", "GIT_EMAIL", "--git-provider", "GIT_PROVIDER", "--git-provider-url", "GIT_PROVIDER_URL", "--organisation", "ORG", "--repository-name", "REPO", "--file", "FILE", "--values", "{a.b: 42}", # yaml "--create-pr", "--auto-merge", "--single-commit", "--verbose", ]) self.assertEqual(cli.command, "deploy") self.assertEqual(cli.username, "USER") self.assertEqual(cli.password, "PASS") self.assertEqual(cli.git_user, "GIT_USER") self.assertEqual(cli.git_email, "GIT_EMAIL") self.assertEqual(cli.organisation, "ORG") self.assertEqual(cli.repository_name, "REPO") self.assertEqual(cli.file, "FILE") self.assertEqual(cli.values, {"a.b": 42}) self.assertEqual(cli.git_provider, "GIT_PROVIDER") self.assertEqual(cli.git_provider_url, "GIT_PROVIDER_URL") self.assertTrue(cli.create_pr) self.assertTrue(cli.auto_merge) self.assertTrue(cli.single_commit) self.assertTrue(cli.verbose)
def main(): logging.basicConfig(level=logging.INFO, format="%(levelname)-2s %(funcName)s: %(message)s") args = create_cli(sys.argv[1:]) command = get_command(args.command) if "verbose" in args: verbose = args.verbose del args.verbose else: verbose = False try: command(**vars(args)) except GitOpsException as ex: if verbose: logging.exception(ex) else: logging.error(ex) sys.exit(1)
def test_create_pr_preview_all_args(self): cli = create_cli([ "create-pr-preview", "--username", "USER", "--password", "PASS", "--git-user", "GIT_USER", "--git-email", "GIT_EMAIL", "--git-provider", "GIT_PROVIDER", "--git-provider-url", "GIT_PROVIDER_URL", "--organisation", "ORG", "--repository-name", "REPO", "--pr-id", "4711", "--parent-id", "42", "-v", ]) self.assertEqual(cli.command, "create-pr-preview") self.assertEqual(cli.username, "USER") self.assertEqual(cli.password, "PASS") self.assertEqual(cli.git_user, "GIT_USER") self.assertEqual(cli.git_email, "GIT_EMAIL") self.assertEqual(cli.organisation, "ORG") self.assertEqual(cli.repository_name, "REPO") self.assertEqual(cli.pr_id, 4711) self.assertEqual(cli.parent_id, 42) self.assertEqual(cli.git_provider, "GIT_PROVIDER") self.assertEqual(cli.git_provider_url, "GIT_PROVIDER_URL") self.assertTrue(cli.verbose)
def test_deploy_required_args(self): cli = create_cli([ "deploy", "--username", "USER", "--password", "PASS", "--git-user", "GIT_USER", "--git-email", "GIT_EMAIL", "--organisation", "ORG", "--repository-name", "REPO", "--file", "FILE", "--values", '{"a.b": 42}', # json ]) self.assertEqual(cli.command, "deploy") self.assertEqual(cli.username, "USER") self.assertEqual(cli.password, "PASS") self.assertEqual(cli.git_user, "GIT_USER") self.assertEqual(cli.git_email, "GIT_EMAIL") self.assertEqual(cli.organisation, "ORG") self.assertEqual(cli.repository_name, "REPO") self.assertEqual(cli.file, "FILE") self.assertEqual(cli.values, {"a.b": 42}) self.assertIsNone(cli.git_provider) self.assertIsNone(cli.git_provider_url) self.assertFalse(cli.create_pr) self.assertFalse(cli.auto_merge) self.assertFalse(cli.single_commit) self.assertFalse(cli.verbose)
def test_delete_preview_all_args(self): cli = create_cli([ "delete-preview", "--username", "USER", "--password", "PASS", "--git-user", "GIT_USER", "--git-email", "GIT_EMAIL", "--git-provider", "GIT_PROVIDER", "--git-provider-url", "GIT_PROVIDER_URL", "--organisation", "ORG", "--repository-name", "REPO", "--preview-id", "abc123", "-v", "n", ]) self.assertEqual(cli.command, "delete-preview") self.assertEqual(cli.username, "USER") self.assertEqual(cli.password, "PASS") self.assertEqual(cli.git_user, "GIT_USER") self.assertEqual(cli.git_email, "GIT_EMAIL") self.assertEqual(cli.organisation, "ORG") self.assertEqual(cli.repository_name, "REPO") self.assertEqual(cli.preview_id, "abc123") self.assertEqual(cli.git_provider, "GIT_PROVIDER") self.assertEqual(cli.git_provider_url, "GIT_PROVIDER_URL") self.assertFalse(cli.verbose)
def _capture_create_cli(args): with captured_output() as (stdout, stderr), pytest.raises(SystemExit) as ex: create_cli(args) return ex.value.code, stdout.getvalue(), stderr.getvalue()
def test_version_args(self): cli = create_cli(["version"]) self.assertEqual(cli.command, "version")