Skip to content

Commit 88c8df3

Browse files
committed
Merge branch '0.1.6'
2 parents 6ecbd1d + 3329a79 commit 88c8df3

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.5
2+
current_version = 0.1.6
33
commit = False
44
tag = False
55
files = setup.py netuitive/__init__.py

HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
History
44
-------
55

6+
0.1.6 (2016-05-20)
7+
---------------------
8+
9+
* fix handling of http errors
10+
611
0.1.5 (2016-05-03)
712
---------------------
813

netuitive/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
__author__ = 'Netuitive, Inc'
4-
__version__ = '0.1.5'
4+
__version__ = '0.1.6'
55

66
from .client import Client # nopep8
77
from .element import Element # nopep8

netuitive/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ def post(self, element):
104104
raise Exception(errmsg)
105105

106106
except urllib2.HTTPError as e:
107-
self.disabled = True
108107
logging.debug("Response code: %d", e.code)
109108

110109
if e.code in self.kill_codes:
110+
self.disabled = True
111+
111112
logging.exception('Posting has been disabled.'
112113
'See previous errors for details.')
113114
else:
@@ -146,10 +147,10 @@ def post_event(self, event):
146147
return(True)
147148

148149
except urllib2.HTTPError as e:
149-
self.disabled = True
150150
logging.debug("Response code: %d", e.code)
151151

152152
if e.code in self.kill_codes:
153+
self.disabled = True
153154
logging.exception('Posting has been disabled.'
154155
'See previous errors for details.')
155156
else:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
setup(
2626
name='netuitive',
27-
version='0.1.5',
27+
version='0.1.6',
2828
description="Python Client for Netuitive Cloud",
2929
long_description=readme + '\n\n' + history,
3030
author="Netuitive",

tests/test_netuitive_client.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,31 @@ def test_kill_switch_418(self, mock_logging, mock_post):
251251
self.assertEqual(mock_logging.exception.call_args_list[0][0][
252252
0], 'Posting has been disabled.See previous errors for details.')
253253

254+
@mock.patch('netuitive.client.urllib2.urlopen')
255+
@mock.patch('netuitive.client.logging')
256+
def test_not_kill_switch_504(self, mock_logging, mock_post):
257+
258+
mock_post.return_value = MockResponse(code=504)
259+
260+
a = netuitive.Client(api_key='apikey')
261+
mock_post.side_effect = urllib2.HTTPError(a.url, 504, '', {}, None)
262+
263+
e = netuitive.Element()
264+
265+
e.add_sample(
266+
'nonsparseDataStrategy', 1434110794, 1, 'COUNTER', host='hostname')
267+
268+
resp = a.post(e)
269+
resp2 = a.post(e)
270+
271+
self.assertNotEqual(resp, True)
272+
self.assertFalse(resp2)
273+
274+
self.assertFalse(a.disabled)
275+
276+
self.assertEqual(mock_logging.exception.call_args_list[0][0][
277+
0], 'error posting payload to api ingest endpoint (%s): %s')
278+
254279
def tearDown(self):
255280
pass
256281

@@ -359,6 +384,27 @@ def test_kill_switch_418(self, mock_logging, mock_post):
359384
self.assertEqual(mock_logging.exception.call_args_list[0][0][
360385
0], 'Posting has been disabled.See previous errors for details.')
361386

387+
@mock.patch('netuitive.client.urllib2.urlopen')
388+
@mock.patch('netuitive.client.logging')
389+
def test_not_kill_switch_504(self, mock_logging, mock_post):
390+
391+
mock_post.return_value = MockResponse(code=504)
392+
# test infrastructure endpoint url creation
393+
a = netuitive.Client(api_key='apikey')
394+
mock_post.side_effect = urllib2.HTTPError(a.url, 504, '', {}, None)
395+
396+
e = netuitive.Event(
397+
'test', 'INFO', 'test event', 'big old test message', 'INFO')
398+
399+
resp = a.post_event(e)
400+
resp2 = a.post_event(e)
401+
402+
self.assertNotEqual(resp, True)
403+
self.assertFalse(resp2)
404+
self.assertFalse(a.disabled)
405+
self.assertEqual(mock_logging.exception.call_args_list[0][0][
406+
0], 'error posting payload to api ingest endpoint (%s): %s')
407+
362408
def tearDown(self):
363409
pass
364410

0 commit comments

Comments
 (0)