Skip to content

Commit

Permalink
increased test coverage for marathon_tools
Browse files Browse the repository at this point in the history
  • Loading branch information
mjksmith committed Mar 9, 2016
1 parent a30b846 commit 858f2a5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
10 changes: 7 additions & 3 deletions paasta_tools/marathon_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ def __repr__(self):
)

def copy(self):
return self.__class__(self.service, self.instance, dict(self.config_dict), dict(self.branch_dict))
return self.__class__(
service=self.service,
instance=self.instance,
cluster=self.cluster,
config_dict=dict(self.config_dict),
branch_dict=dict(self.branch_dict),
)

def get_min_instances(self):
return self.config_dict.get('min_instances', 1)
Expand Down Expand Up @@ -703,8 +709,6 @@ def get_proxy_port_for_instance(name, instance, cluster=None, soa_dir=DEFAULT_SO
:param cluster: The cluster to read the configuration for
:param soa_dir: The SOA config directory to read from
:returns: The proxy_port for the service instance, or None if not defined"""
if not cluster:
cluster = load_system_paasta_config().get_cluster()
namespace = read_namespace_for_service_instance(name, instance, cluster, soa_dir)
nerve_dict = load_service_namespace_config(name, namespace, soa_dir)
return nerve_dict.get('proxy_port')
Expand Down
65 changes: 65 additions & 0 deletions tests/test_marathon_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2159,3 +2159,68 @@ def test_create_complete_config():
):
marathon_tools.create_complete_config('service', 'instance', soa_dir=mock.Mock())
mock_format_marathon_app_dict.assert_called_once_with()


def test_marathon_config_key_errors():
fake_marathon_config = marathon_tools.MarathonConfig({}, '')
with raises(marathon_tools.MarathonNotConfigured):
fake_marathon_config.get_url()
with raises(marathon_tools.MarathonNotConfigured):
fake_marathon_config.get_username()
with raises(marathon_tools.MarathonNotConfigured):
fake_marathon_config.get_password()


def test_marathon_service_config_copy():
fake_marathon_service_config = marathon_tools.MarathonServiceConfig(
service='fake-service',
instance='fake-instance',
cluster='fake-cluster',
config_dict={'elem': 'test'},
branch_dict={'elem2': 'test2'},
)
fake_marathon_service_config_2 = fake_marathon_service_config.copy()
assert fake_marathon_service_config is not fake_marathon_service_config_2
assert fake_marathon_service_config == fake_marathon_service_config_2


def test_marathon_service_config_get_healthchecks_invalid_type():
fake_marathon_service_config = marathon_tools.MarathonServiceConfig(
service='fake-service',
instance='fake-instance',
cluster='fake-cluster',
config_dict={},
branch_dict={},
)
with mock.patch.object(marathon_tools.MarathonServiceConfig, 'get_healthcheck_mode', autospec=True,
return_value='fake-mode'):
with raises(marathon_tools.InvalidMarathonHealthcheckMode):
fake_marathon_service_config.get_healthchecks(mock.Mock())


def test_marathon_service_config_get_desired_state_human_invalid_desired_state():
fake_marathon_service_config = marathon_tools.MarathonServiceConfig(
service='fake-service',
instance='fake-instance',
cluster='fake-cluster',
config_dict={},
branch_dict={},
)
with mock.patch.object(marathon_tools.MarathonServiceConfig, 'get_desired_state', autospec=True,
return_value='fake-state'):
assert 'Unknown (desired_state: fake-state)' in fake_marathon_service_config.get_desired_state_human()


def test_read_namespace_for_service_instance_no_cluster():
mock_get_cluster = mock.Mock()
with contextlib.nested(
mock.patch('paasta_tools.marathon_tools.service_configuration_lib.read_extra_service_information',
autospec=True),
mock.patch('paasta_tools.marathon_tools.load_system_paasta_config', autospec=True,
return_value=mock.Mock(get_cluster=mock_get_cluster)),
) as (
_,
_,
):
marathon_tools.read_namespace_for_service_instance(mock.Mock(), mock.Mock())
mock_get_cluster.assert_called_once_with()

0 comments on commit 858f2a5

Please sign in to comment.