From d178cd41a83aef2e12f3e6a4429c50ebffeeb593 Mon Sep 17 00:00:00 2001 From: Dalton Barreto Date: Thu, 26 Oct 2017 15:08:12 -0200 Subject: [PATCH 1/3] Removes id validation from MarathonGroup() This validation was preventig the use of the root group (`/`), both from `MarathonGroup().from_json()` and `MarathonClient().get_group("/")` Fixes issue #227 --- marathon/models/group.py | 2 +- tests/test_model_group.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/test_model_group.py diff --git a/marathon/models/group.py b/marathon/models/group.py index c7c0339..5c946c6 100644 --- a/marathon/models/group.py +++ b/marathon/models/group.py @@ -36,5 +36,5 @@ def __init__(self, apps=None, dependencies=None, # p if isinstance(p, MarathonPod) else MarathonPod().from_json(p) # for p in (pods or []) # ] - self.id = assert_valid_id(id) + self.id = id self.version = version diff --git a/tests/test_model_group.py b/tests/test_model_group.py new file mode 100644 index 0000000..98925b1 --- /dev/null +++ b/tests/test_model_group.py @@ -0,0 +1,20 @@ +# encoding: utf-8 + +from marathon.models.group import MarathonGroup +import unittest + + +class MarathonGroupTest(unittest.TestCase): + + def test_from_json_parses_root_group(self): + data = { + "id": "/", + "groups": [ + {"id": "/foo", "apps": []}, + {"id": "/bla", "apps": []}, + ], + "apps": [] + } + group = MarathonGroup().from_json(data) + self.assertEqual("/", group.id) + From 800f90f334f80fb40c1bd7ce77476615609bdcb6 Mon Sep 17 00:00:00 2001 From: Dalton Barreto Date: Thu, 26 Oct 2017 16:23:07 -0200 Subject: [PATCH 2/3] Fixing flake8 errors --- marathon/models/group.py | 2 +- tests/test_model_group.py | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/marathon/models/group.py b/marathon/models/group.py index 5c946c6..bb4f6bc 100644 --- a/marathon/models/group.py +++ b/marathon/models/group.py @@ -1,4 +1,4 @@ -from .base import MarathonResource, assert_valid_id +from .base import MarathonResource from .app import MarathonApp diff --git a/tests/test_model_group.py b/tests/test_model_group.py index 98925b1..fb84c04 100644 --- a/tests/test_model_group.py +++ b/tests/test_model_group.py @@ -7,14 +7,13 @@ class MarathonGroupTest(unittest.TestCase): def test_from_json_parses_root_group(self): - data = { - "id": "/", - "groups": [ - {"id": "/foo", "apps": []}, - {"id": "/bla", "apps": []}, - ], - "apps": [] - } - group = MarathonGroup().from_json(data) - self.assertEqual("/", group.id) - + data = { + "id": "/", + "groups": [ + {"id": "/foo", "apps": []}, + {"id": "/bla", "apps": []}, + ], + "apps": [] + } + group = MarathonGroup().from_json(data) + self.assertEqual("/", group.id) From 015e5014833713bcfd8bea16bd865b41cb0b3954 Mon Sep 17 00:00:00 2001 From: Dalton Barreto Date: Fri, 27 Oct 2017 10:55:36 -0200 Subject: [PATCH 3/3] Fixing E722 flake8 errors E722: do not use bare except --- marathon/models/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/marathon/models/base.py b/marathon/models/base.py index ecc8030..db77076 100644 --- a/marathon/models/base.py +++ b/marathon/models/base.py @@ -13,7 +13,7 @@ def __repr__(self): def __eq__(self, other): try: return self.__dict__ == other.__dict__ - except: + except Exception: return False def __hash__(self): @@ -68,7 +68,7 @@ def __repr__(self): def __eq__(self, other): try: return self.__dict__ == other.__dict__ - except: + except Exception: return False def __hash__(self):