def test_list_application_ids(): responses.add( responses.GET, "http://marathon.somedomain.com:8080/v2/apps", status=200, json=_load_json_fixture("valid_apps") ) client = MarathonClient("http://marathon.somedomain.com:8080") application_ids = client.list_application_ids() assert application_ids == ["test-app-a", "test-app-b", "test-app-c"]
def test_list_application_ids_internal_server_error(): responses.add( responses.GET, "http://marathon.somedomain.com:8080/v2/apps", status=500, body="Internal Server Error" ) client = MarathonClient("http://marathon.somedomain.com:8080") with pytest.raises(ClientError): client.list_application_ids()
def test_deploy_unprocessable_entity(): responses.add(responses.PUT, 'http://marathon.somedomain.com:8080/v2/apps/test-app', status=422, json=_load_json_fixture("validation_errors")) client = MarathonClient("http://marathon.somedomain.com:8080") with pytest.raises(ClientError): client.deploy({"id": "test-app"})
def test_deploy_multiple(mock_deployment_check): responses.add( responses.PUT, "http://marathon.somedomain.com:8080/v2/apps/", status=201, json=_load_json_fixture("deployment") ) mock_deployment_check.return_value = True client = MarathonClient("http://marathon.somedomain.com:8080") deployment = client.deploy([{"id": "test-app"}, {"id": "test-app-2"}]) assert deployment.wait(check_interval_secs=0.1)
def test_deploy_conflict(): responses.add(responses.PUT, 'http://marathon.somedomain.com:8080/v2/apps/test-app', status=409, json=_load_json_fixture("deployment_in_progress")) client = MarathonClient("http://marathon.somedomain.com:8080") with pytest.raises(ClientError): client.deploy({"id": "test-app"})
def test_get_application_internal_server_error(): responses.add(responses.GET, 'http://marathon.somedomain.com:8080/v2/apps/test-app', status=500, body="Internal Server Error") client = MarathonClient("http://marathon.somedomain.com:8080") with pytest.raises(ClientError): client.get_application('test-app')
def test_delete_tasks(requests): client = MarathonClient("http://marathon.somedomain.com:8080") client.delete_tasks(["foo", "bar"], scale=True) requests.assert_called_with( "http://marathon.somedomain.com:8080/v2/tasks/delete", data='{"ids": ["foo", "bar"]}', headers={"Content-Type": "application/json"}, params={"scale": True}, )
def test_get_application_not_found(): responses.add(responses.GET, 'http://marathon.somedomain.com:8080/v2/apps/test-app', status=404, json={"message": "App '/test-app' does not exist"}) client = MarathonClient("http://marathon.somedomain.com:8080") with pytest.raises(ClientError): client.get_application('test-app')
def test_get_deployment_not_found(): responses.add(responses.GET, 'http://marathon.somedomain.com:8080/v2/deployments', status=200, json=_load_json_fixture("deployments")) client = MarathonClient("http://marathon.somedomain.com:8080") with pytest.raises(DeploymentNotFound): client.get_deployment("1234")
def test_get_application(): responses.add(responses.GET, 'http://marathon.somedomain.com:8080/v2/apps/test-app', status=200, json=_load_json_fixture("valid_app")) client = MarathonClient("http://marathon.somedomain.com:8080") application = client.get_application('test-app') assert application['id'] == "/test-app" assert application['cmd'] is None
def test_basic_auth_headers_not_present(): responses.add(responses.GET, 'http://marathon.somedomain.com:8080/v2/apps/test-app', status=200, json=_load_json_fixture("valid_app")) client = MarathonClient("http://marathon.somedomain.com:8080") client.get_application('test-app') assert "Authorization" not in responses.calls[0].request.headers
def test_get_deployment(): responses.add(responses.GET, 'http://marathon.somedomain.com:8080/v2/deployments', status=200, json=_load_json_fixture("deployments")) client = MarathonClient("http://marathon.somedomain.com:8080") deployment = client.get_deployment("97c136bf-5a28-4821-9d94-480d9fbb01c8") assert deployment is not None assert deployment['id'] == "97c136bf-5a28-4821-9d94-480d9fbb01c8"
def test_deploy_single_app_list(mock_deployment_check): responses.add(responses.PUT, 'http://marathon.somedomain.com:8080/v2/apps/test-app', status=201, json=_load_json_fixture("deployment")) mock_deployment_check.return_value = True client = MarathonClient("http://marathon.somedomain.com:8080") deployment = client.deploy([{"id": "test-app"}]) assert deployment.wait(check_interval_secs=0.1)
def test_get_deployment_not_found(): responses.add( responses.GET, "http://marathon.somedomain.com:8080/v2/deployments", status=200, json=_load_json_fixture("deployments"), ) client = MarathonClient("http://marathon.somedomain.com:8080") with pytest.raises(DeploymentNotFound): client.get_deployment("1234")
def test_deploy_conflict(): responses.add( responses.PUT, "http://marathon.somedomain.com:8080/v2/apps/test-app", status=409, json=_load_json_fixture("deployment_in_progress"), ) client = MarathonClient("http://marathon.somedomain.com:8080") with pytest.raises(ClientError): client.deploy({"id": "test-app"})
def test_deploy_unprocessable_entity(): responses.add( responses.PUT, "http://marathon.somedomain.com:8080/v2/apps/test-app", status=422, json=_load_json_fixture("validation_errors"), ) client = MarathonClient("http://marathon.somedomain.com:8080") with pytest.raises(ClientError): client.deploy({"id": "test-app"})
def test_get_application_not_found(): responses.add( responses.GET, "http://marathon.somedomain.com:8080/v2/apps/test-app", status=404, json={"message": "App '/test-app' does not exist"}, ) client = MarathonClient("http://marathon.somedomain.com:8080") with pytest.raises(ClientError): client.get_application("test-app")
def test_get_application(): responses.add( responses.GET, "http://marathon.somedomain.com:8080/v2/apps/test-app", status=200, json=_load_json_fixture("valid_app"), ) client = MarathonClient("http://marathon.somedomain.com:8080") application = client.get_application("test-app") assert application["id"] == "/test-app" assert application["cmd"] is None
def test_get_deployment(): responses.add( responses.GET, "http://marathon.somedomain.com:8080/v2/deployments", status=200, json=_load_json_fixture("deployments"), ) client = MarathonClient("http://marathon.somedomain.com:8080") deployment = client.get_deployment("97c136bf-5a28-4821-9d94-480d9fbb01c8") assert deployment is not None assert deployment["id"] == "97c136bf-5a28-4821-9d94-480d9fbb01c8"
def test_deployment_check_with_deployment_in_progress(mock_get_deployment): """ Test that deployment.check() returns False when the app has a deployment in progress. """ deploy_in_progress = { "id": "97c136bf-5a28-4821-9d94-480d9fbb01c8", "version": "2015-09-30T09:09:17.614Z", "affectedApps": ["/foo"], "steps": [[{ "action": "StartApplication", "app": "/foo" }], [{ "action": "ScaleApplication", "app": "/foo" }]], "currentActions": [{ "action": "ScaleApplication", "app": "/foo" }], "currentStep": 2, "totalSteps": 2 } mock_get_deployment.return_value = deploy_in_progress client = MarathonClient("http://marathon.somedomian.com:8080") deployment = MarathonDeployment(client, "97c136bf-5a28-4821-9d94-480d9fbb01c8") assert not deployment.check()
def test_deployment_check(mock_get_deployment): """ Test that deployment.check() returns True when the app has deployed successfully. """ mock_get_deployment.side_effect = DeploymentNotFound("1234") client = MarathonClient("http://marathon.somedomian.com:8080") deployment = MarathonDeployment(client, '1234') assert deployment.check()
def test_deployment_wait_with_timeout(mock_deployment_check): """ Test that deployment.wait() spins until a deployment succeeds. """ mock_deployment_check.side_effect = [False, False, False] client = MarathonClient("http://marathon.somedomain.com:8080") deployment = MarathonDeployment(client, '1234') with pytest.raises(DeploymentFailed): deployment.wait(timeout=1, check_interval_secs=0.5) assert mock_deployment_check.call_count == 2
def _validate_marathon_client(ctx, _, __): """Validates that all options required to initialise a marathon client have been set properly and securely. A client is then initialised and returned to the command function. """ _c = ctx.params _validate_authentication(ctx, _c["marathon_url"], "Marathon") return MarathonClient(_c["marathon_url"], _c["username"], _c["password"], _c["dry_run"])
def test_deployment_wait(mock_deployment_check): """ Test that deployment.wait() spins until a deployment succeeds. """ mock_deployment_check.side_effect = [ False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True ] client = MarathonClient("http://marathon.somedomain.com:8080") deployment = MarathonDeployment(client, '1234') deployment.wait(check_interval_secs=0.01) assert mock_deployment_check.call_count == 20
def test_deploy_dry_run(): client = MarathonClient("http://marathon.somedomain.com:8080") client.dry_run = True with pytest.raises(DryRun): client.deploy({"id": "test-app"})
def test_deploy_dry_run(): client = MarathonClient("http://marathon.somedomain.com:8080", dry_run=True) with pytest.raises(DryRun): client.deploy({"id": "test-app"})