def test_heroku_works(subprocess, capsys): subprocess.check_output.side_effect = create_check_output() subprocess.call.side_effect = successful_check_call_with_print subprocess.check_call.side_effect = successful_check_call_with_print deploy.main(["heroku", "-r", "myapp"]) snapshot = Snapshot(capsys.readouterr().out, SNAPSHOT_DIR / "heroku_works.txt") assert snapshot.expected == snapshot.actual
def test_heroku_with_preboot(subprocess, capsys): subprocess.check_output.side_effect = create_check_output({ "heroku features:info preboot --json": json.dumps({ "enabled": True }).encode("utf-8"), }) subprocess.call.side_effect = successful_check_call_with_print subprocess.check_call.side_effect = successful_check_call_with_print deploy.main(["heroku", "-r", "myapp"]) snapshot = Snapshot(capsys.readouterr().out, SNAPSHOT_DIR / "heroku_with_preboot.txt") assert snapshot.expected == snapshot.actual
def test_create(self): with tempfile.NamedTemporaryFile(delete=False) as dist_file: content = b"dist" dist_file.write(content) stubber = botocore.stub.Stubber(deploy.s3) stubber.add_client_error("get_object", "NoSuchKey") stubber.add_response( "put_object", {}, { "Body": content, "Bucket": self.s3_bucket, "ContentType": "application/zip", "Key": f"dist/{self.stage_name}", }, ) stubber.add_response( "put_object", {}, { "Body": json.dumps( { self.stage_name: { "file": f"dist/{self.stage_name}", "filebase64sha256": "vK4EFmIbPbQ9jLoeRFSnksevnktyh+UQVu/FohXZWDk=", } } ).encode(), "Bucket": self.s3_bucket, "ContentType": "application/json", "Key": f"manifest.json", }, ) stubber.activate() deploy.main([self.s3_bucket, self.stage_name, "--dist", dist_file.name]) os.unlink(dist_file.name)
def main(): """Bootstraps a development environment with ad-hoc management commands that can install, uninstall, rotate key pair, generate a site log report and start/stop a watched development session. """ domain = '$domain' # domain name/S3 bucket name email = '$email' # for CodePipeline notifications home = os.path.expanduser('~/') # expand home directory site_root = home + '$domain' # path to site root site_dpl = site_root + '/deploy' # path to site deploy site_src = site_root + '/src' # path to site source site_bld = site_src + '/build' # path to site build site_log = site_root + '/logs' # path to site logs report = '_report.html' # name of log report fullCmdArgs = sys.argv # read commandline arguments (first) argList = fullCmdArgs[1:] # further arguments # valid parameters shortOps = 'dsxprbcokhiu' longOps = [ 'dev', 'dev-style', 'dev-stop', 'post', 'report', 'build', 'clean', 'open', 'keypair', 'help', 'install', 'uninstall' ] if len(sys.argv) == 1: opt_error() sys.exit(1) try: arguments, values = getopt.getopt(argList, shortOps, longOps) except getopt.error as err: opt_error(err) for currentArgument, currentValue in arguments: if currentArgument in ("-d", "--dev"): dev_stop() dev(site_src, site_bld) site_open() elif currentArgument in ("-s", "--dev-style"): dev_stop() dev(site_src, site_bld) dev_style(site_bld) site_open() elif currentArgument in ("-x", "--dev-stop"): dev_stop() elif currentArgument in ("-p", "--post"): post(site_src) elif currentArgument in ("-r", "--report"): site_report(site_root, site_log, report) elif currentArgument in ("-b", "--build"): build(site_bld, site_src) elif currentArgument in ("-c", "clean"): clean(site_bld) elif currentArgument in ("-o", "--open"): site_open() elif currentArgument in ("-k", "--keypair"): key_gen.main() elif currentArgument in ("-h", "--help"): display_help() elif currentArgument in ("-i", "--install"): deploy.main(domain, email) elif currentArgument in ("-u", "--uninstall"): print ("Static-Site Uninstall Coming Soon") else: opt_error()
def test_it_shows_help_when_asked_for_help(capsys): with expect_normal_exit(): deploy.main(["--help"]) assert "usage: " in capsys.readouterr().out
def test_heroku_raises_err_with_no_remote(capsys): with pytest.raises(ValueError, match="Please specify a git remote"): deploy.main(["heroku"])
def test_selfcheck_works(capsys): deploy.main(["selfcheck"]) assert "Deployment prerequisites satisfied" in capsys.readouterr().out
def test_it_shows_help_when_given_no_args(capsys): with expect_abnormal_exit(): deploy.main([]) assert "usage: " in capsys.readouterr().out
#!/usr/bin/env python import deploy import log import monitor import test print "Modes:" print "[1] Deploy" print "[2] Test" print "[3] Log" print "[4] Monitor" mode = int(raw_input("\nSelect a mode: ")) print '' if mode == 1: deploy.main() elif mode == 2: test.main() elif mode == 3: log.main() elif mode == 4: monitor.main()