diff --git a/marathon/models/base.py b/marathon/models/base.py index ac28f73..01a528a 100644 --- a/marathon/models/base.py +++ b/marathon/models/base.py @@ -10,6 +10,9 @@ class MarathonObject(object): def __repr__(self): return "{clazz}::{obj}".format(clazz=self.__class__.__name__, obj=self.to_json()) + def __eq__(self, other): + return self.__dict__ == other.__dict__ + def json_repr(self, minimal=False): """Construct a JSON-friendly representation of the object. @@ -52,6 +55,11 @@ def __repr__(self): else: return "{clazz}::{obj}".format(clazz=self.__class__.__name__, obj=self.to_json()) + def __eq__(self, other): + return self.__dict__ == other.__dict__ + + def __str__(self): + return "{clazz}::".format(clazz=self.__class__.__name__) + str(self.__dict__) # See: https://github.com/mesosphere/marathon/blob/2a9d1d20ec2f1cfcc49fbb1c0e7348b26418ef38/src/main/scala/mesosphere/marathon/api/ModelValidation.scala#L224 ID_PATTERN = re.compile('^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])|(\\.|\\.\\.)$') diff --git a/marathon/models/deployment.py b/marathon/models/deployment.py index dfbf8fd..e73afe8 100644 --- a/marathon/models/deployment.py +++ b/marathon/models/deployment.py @@ -50,6 +50,7 @@ def __init__(self, action=None, app=None, apps=None, type=None): self.apps = apps self.type = type # TODO: Remove builtin shadow + class MarathonDeploymentPlan(MarathonObject): def __init__(self, original=None, target=None, steps=None, id=None, version=None): self.original = MarathonDeploymentOriginalState.from_json(original) diff --git a/tests/test_api.py b/tests/test_api.py index 8b35924..05bbd17 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,12 +1,22 @@ import mock import requests_mock from marathon import MarathonClient +from marathon import models @requests_mock.mock() def test_get_deployments(m): - fake_response = '[ { "affectedApps": [ "/test" ], "id": "867ed450-f6a8-4d33-9b0e-e11c5513990b", "steps": [ [ { "action": "ScaleApplication", "app": "/test" } ] ], "currentActions": [ { "action": "ScaleApplication", "app": "/test" } ], "version": "2014-08-26T08:18:03.595Z", "currentStep": 1, "totalSteps": 1 } ]' + fake_response = '[ { "affectedApps": [ "/test" ], "id": "fakeid", "steps": [ [ { "action": "ScaleApplication", "app": "/test" } ] ], "currentActions": [ { "action": "ScaleApplication", "app": "/test" } ], "version": "fakeversion", "currentStep": 1, "totalSteps": 1 } ]' m.get('http://fake_server/v2/deployments', text=fake_response) mock_client = MarathonClient(servers='http://fake_server') - response = mock_client.list_deployments() - print response + actual_deployments = mock_client.list_deployments() + expected_deployments = [ models.MarathonDeployment( + id=u"fakeid", + steps=[[models.MarathonDeploymentAction(action="ScaleApplication", app="/test")]], + current_actions=[models.MarathonDeploymentAction(action="ScaleApplication", app="/test")], + current_step=1, + total_steps=1, + affected_apps=[u"/test"], + version=u"fakeversion" + )] + assert expected_deployments == actual_deployments