-
-
Save kaaveland/1fbe629c6391ebaf5409cdb6dc71cd3a to your computer and use it in GitHub Desktop.
some example code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@fabric.api.serial | |
def stop(app_name): | |
fabric.api.run('service {} stop'.format(app_name)) | |
@mock.patch('fabric.api.run') | |
def test_stop_runs_nice_command(run_mock): | |
stop("awesome-app") | |
run_mock.verify_called_with("service awesome-app stop") | |
# More low-level commands like that, with similar test cases, then higher level code | |
def restart(application_config): | |
app_name = application_config.name | |
hosts = application_config.hosts | |
for host in hosts: | |
fabric.api.execute(stop, app_name, hosts=hosts) | |
fabric.api.execute(start, app_name, hosts=hosts) | |
@mock.patch('fabric.api.execute') | |
def test_that_app_is_stopped_only_on_one_server_at_a_time(execute_mock): | |
application_config = ApplicationConfig("awesome-app", ["server-1", "server-2"]) | |
restart(application_config) | |
assert execute_mock.has_calls([ | |
mock.call(stop, "awesome-app", hosts=["server-1"]), | |
mock.call(start, "awesome-app", hosts=["server-2"]), | |
mock.call(stop, "awesome-app", hosts=["server-1"]), | |
mock.call(start, "awesome-app", hosts=["server-2"]) | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment