Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement __eq__ on base models + fix tests to be useful #54

Merged
merged 2 commits into from
Jul 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions marathon/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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])|(\\.|\\.\\.)$')
Expand Down
1 change: 1 addition & 0 deletions marathon/models/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 13 additions & 3 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -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