Skip to content

Commit

Permalink
raise excplicit error when referencing non-existant environmenmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhooker committed Sep 11, 2012
1 parent ed562f5 commit 3b152bc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 10 additions & 2 deletions jones/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
limitations under the License.
"""

import socket
from collections import Mapping
from kazoo.exceptions import NoNodeException

import socket
import json


class EnvironmentNotFoundException(Exception): pass


class JonesClient(Mapping):
"""An example client for accessing config stored by Jones.
Expand Down Expand Up @@ -53,7 +58,10 @@ def _deserialize(d):
return {}
return dict(l.split(' -> ') for l in d.split('\n'))

nodemap, stat = self.zk.get(self.nodemap_path, self._get_config)
try:
nodemap, stat = self.zk.get(self.nodemap_path, self._get_config)
except NoNodeException:
raise EnvironmentNotFoundException()

try:
conf_path = _deserialize(nodemap)[self.hostname]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from setuptools import setup

VERSION = '0.4'
VERSION = '0.4.1'
NAME = 'jones'

install_requires = [
Expand Down
6 changes: 5 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from tests import fixture
from jones.jones import Jones
from jones.client import JonesClient
from jones.client import JonesClient, EnvironmentNotFoundException
from kazoo.testing import KazooTestCase


Expand Down Expand Up @@ -63,6 +63,10 @@ def test_default_value(self):
self.assertEquals(self.jones_client.get('a'), fixture.CHILD1['a'])
self.assertEquals(self.jones_client.get('notinhere', 1), 1)

def test_raises_with_no_environment(self):
with self.assertRaises(EnvironmentNotFoundException):
JonesClient(self.client, 'newservice')

def test_responds_to_remap(self):
"""test that changing the associations updates config properly."""

Expand Down

0 comments on commit 3b152bc

Please sign in to comment.