Skip to content

Commit

Permalink
Merge pull request #54 from Rob-Johnson/make-test-useful
Browse files Browse the repository at this point in the history
implement __eq__ on base models + fix tests to be useful
  • Loading branch information
solarkennedy committed Jul 24, 2015
2 parents 88f4d87 + 5d83e88 commit 89ba805
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
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

0 comments on commit 89ba805

Please sign in to comment.