Skip to content

Instantly share code, notes, and snippets.

@kaaveland
Created May 3, 2017 05:56
Show Gist options
  • Save kaaveland/1fbe629c6391ebaf5409cdb6dc71cd3a to your computer and use it in GitHub Desktop.
Save kaaveland/1fbe629c6391ebaf5409cdb6dc71cd3a to your computer and use it in GitHub Desktop.
some example code
@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