Skip to content

Commit 09dab48

Browse files
committed
Test updates
1 parent 0d92d40 commit 09dab48

9 files changed

Lines changed: 383 additions & 149 deletions

File tree

consulate/utils.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,23 @@ def maybe_encode(value):
4040
return value
4141

4242

43-
def response_ok(response, raise_on_404=True):
43+
def _response_error(response):
44+
return (response.body.decode('utf-8')
45+
if hasattr(response, 'body') and response.body
46+
else str(response.status_code))
47+
48+
49+
def response_ok(response, raise_on_404=False):
4450
if response.status_code == 200:
4551
return True
4652
elif response.status_code == 400:
47-
raise exceptions.ClientError(
48-
response.body.decode('utf-8')
49-
if hasattr(response, 'body') else str(response.status_code))
53+
raise exceptions.ClientError(_response_error(response))
5054
elif response.status_code == 401:
51-
raise exceptions.ACLDisabled(
52-
response.body.decode('utf-8')
53-
if hasattr(response, 'body') else str(response.status_code))
55+
raise exceptions.ACLDisabled(_response_error(response))
5456
elif response.status_code == 403:
55-
raise exceptions.Forbidden(
56-
response.body.decode('utf-8')
57-
if hasattr(response, 'body') else str(response.status_code))
57+
raise exceptions.Forbidden(_response_error(response))
5858
elif response.status_code == 404 and raise_on_404:
59-
raise exceptions.NotFound(
60-
response.body.decode('utf-8')
61-
if hasattr(response, 'body') else str(response.status_code))
59+
raise exceptions.NotFound(_response_error(response))
6260
elif response.status_code == 500:
63-
raise exceptions.ServerError(
64-
response.body.decode('utf-8')
65-
if hasattr(response, 'body') else str(response.status_code))
61+
raise exceptions.ServerError(_response_error(response))
6662
return False
File renamed without changes.

tests/catalog_tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from . import base
2+
3+
4+
class TestCatalog(base.TestCase):
5+
def test_catalog_registration(self):
6+
self.consul.catalog.register('test-service', address='10.0.0.1')
7+
self.assertIn('test-service',
8+
[n['Node'] for n in self.consul.catalog.nodes()])
9+
self.consul.catalog.deregister('test-service')
10+
self.assertNotIn('test-service',
11+
[n['Node'] for n in self.consul.catalog.nodes()])

tests/event_tests.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import uuid
2+
3+
from . import base
4+
5+
6+
class TestEvent(base.TestCase):
7+
def test_fire(self):
8+
event_name = 'test-event-%s' % str(uuid.uuid4())[0:8]
9+
response = self.consul.event.fire(event_name)
10+
events = self.consul.event.list(event_name)
11+
if isinstance(events, dict):
12+
self.assertEqual(event_name, events.get('Name'))
13+
self.assertEqual(response, events.get('ID'))
14+
elif isinstance(events, dict):
15+
self.assertIn(event_name, [e.get('Name') for e in events])
16+
self.assertIn(response, [e.get('ID') for e in events])
17+
else:
18+
assert False, 'Unexpected return type'

tests/kv-tests.py

Lines changed: 0 additions & 133 deletions
This file was deleted.

0 commit comments

Comments
 (0)