Change httplib to requests

Change-Id: Id6f10be2b9f68507ff9e579fc3e5ebdfd71ee1f2
This commit is contained in:
Vincent Fournier 2015-08-06 10:54:29 -04:00
parent a7e07a6c84
commit 10633bb397
47 changed files with 1362 additions and 1547 deletions

View File

@ -15,7 +15,6 @@
import requests import requests
import requests.exceptions import requests.exceptions
from six.moves import http_client as httplib
from surveilclient import exc from surveilclient import exc
from surveilclient.openstack.common.py3kcompat import urlutils from surveilclient.openstack.common.py3kcompat import urlutils
@ -79,18 +78,15 @@ class HTTPClient(object):
self.auth_token = access['access']['token'] self.auth_token = access['access']['token']
return self.auth_token['id'] return self.auth_token['id']
def get_connection(self): def _create_complete_url(self, url):
# TODO(aviau): https # TODO(aviau): https
con = httplib.HTTPConnection( return ('http://' + self.endpoint_hostname + ":"
self.endpoint_hostname, + str(self.endpoint_port) + self.endpoint_path + url)
self.endpoint_port
)
return con
def _http_request(self, url, method, **kwargs): def _http_request(self, url, method, **kwargs):
"""Send an http request with the specified characteristics. """Send an http request with the specified characteristics.
Wrapper around httplib.HTTP(S)Connection.request to handle tasks such Wrapper around requests to handle tasks such
as setting headers and error handling. as setting headers and error handling.
""" """
kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {})) kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {}))
@ -99,38 +95,27 @@ class HTTPClient(object):
if self.authenticated: if self.authenticated:
kwargs['headers']['X-Auth-Token'] = self._get_auth_token() kwargs['headers']['X-Auth-Token'] = self._get_auth_token()
conn = self.get_connection() url = self._create_complete_url(url)
request_params = urlutils.urlencode(
kwargs.pop("params", {})
)
request_url = self.endpoint_path + url + '?' + request_params
for attempt in range(3): for attempt in range(3):
try: try:
conn.request(method, request_url, **kwargs) resp = getattr(requests, method.lower())(url, **kwargs)
break break
except ( except (
httplib.BadStatusLine, requests.Timeout,
httplib.IncompleteRead requests.ConnectionError
) as exp: ) as exp:
if attempt == 2: if attempt == 2:
raise exp raise exp
time.sleep(1) time.sleep(1)
resp = conn.getresponse() if 400 <= resp.status_code < 600:
body_str = resp.read()
if 400 <= resp.status < 600:
raise exc.from_response( raise exc.from_response(
response=resp, body=body_str, method=method, url=url) response=resp, body=resp.content, method=method, url=url)
elif resp.status == 300: elif resp.status_code == 300:
raise exc.from_response( raise exc.from_response(
response=resp, body=body_str, method=method, url=url) response=resp, body=resp.content, method=method, url=url)
return resp, body_str return resp
def json_request(self, url, method, **kwargs): def json_request(self, url, method, **kwargs):
"""Send an http request with the specified characteristics. """Send an http request with the specified characteristics.
@ -139,14 +124,11 @@ class HTTPClient(object):
kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {})) kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {}))
kwargs['headers'].setdefault('Content-Type', 'application/json') kwargs['headers'].setdefault('Content-Type', 'application/json')
if 'body' in kwargs: if 'data' in kwargs:
kwargs['body'] = json.dumps(kwargs['body']) kwargs['data'] = json.dumps(kwargs['data'])
resp, body = self.request(url, method, **kwargs) resp, content = self.request(url, method, **kwargs)
if body != "": return resp, resp.json() if content != '' else ''
body = json.loads(body)
return resp, body
def request(self, url, method, **kwargs): def request(self, url, method, **kwargs):
"""Send an http request with the specified characteristics. """Send an http request with the specified characteristics.
@ -154,5 +136,5 @@ class HTTPClient(object):
""" """
kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {})) kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {}))
resp, body = self._http_request(url, method, **kwargs) resp = self._http_request(url, method, **kwargs)
return resp, body.decode() return resp, resp.content.decode()

View File

@ -15,7 +15,7 @@
import json import json
import unittest import unittest
import httpretty import requests_mock
from surveilclient.common import http from surveilclient.common import http
@ -26,18 +26,17 @@ class TestHttp(unittest.TestCase):
self.surveil_url = 'http://surveil:5311/v1' self.surveil_url = 'http://surveil:5311/v1'
self.client = http.HTTPClient(self.surveil_url, authenticated=False) self.client = http.HTTPClient(self.surveil_url, authenticated=False)
@httpretty.activate
def test_json_request_get(self): def test_json_request_get(self):
with requests_mock.mock() as m:
example_result = {'hello': 'surveil'} example_result = {'hello': 'surveil'}
httpretty.register_uri(httpretty.GET, m.get(self.surveil_url + "/test",
self.surveil_url + "/test", text=json.dumps(example_result))
body=json.dumps(example_result))
resp, body = self.client.json_request('/test', 'GET') resp, body = self.client.json_request('/test', 'GET')
self.assertEqual(httpretty.last_request().method, 'GET') self.assertEqual(m.last_request.method, 'GET')
self.assertEqual(body, example_result) self.assertEqual(body, example_result)
self.assertEqual( self.assertEqual(
httpretty.last_request().headers['Content-Type'], m.last_request.headers['Content-Type'],
'application/json' 'application/json'
) )

View File

@ -12,23 +12,22 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestAcknowledge(clienttest.ClientTest): class TestAcknowledge(clienttest.ClientTest):
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/actions/acknowledge", m.post("http://localhost:5311/v2/actions/acknowledge",
body='{"message": "Ack received!"}') text='{"message": "Ack received!"}')
self.client.actions.acknowledge.create( self.client.actions.acknowledge.create(
host_name="somehost" host_name="somehost"
) )
self.assertEqual( self.assertEqual(
httpretty.last_request().body.decode(), m.last_request.body,
u'{"host_name": "somehost"}' u'{"host_name": "somehost"}'
) )

View File

@ -12,23 +12,22 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestDowntime(clienttest.ClientTest): class TestDowntime(clienttest.ClientTest):
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/actions/downtime", m.post("http://localhost:5311/v2/actions/downtime",
body='{"message": "Ack received!"}') text='{"message": "Ack received!"}')
self.client.actions.downtime.create( self.client.actions.downtime.create(
host_name="somehost" host_name="somehost"
) )
self.assertEqual( self.assertEqual(
httpretty.last_request().body.decode(), m.last_request.body,
u'{"host_name": "somehost"}' u'{"host_name": "somehost"}'
) )

View File

@ -11,20 +11,20 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestRecheck(clienttest.ClientTest): class TestRecheck(clienttest.ClientTest):
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/actions/recheck", m.post("http://localhost:5311/v2/actions/recheck",
body='{"message": "Ack received!"}') text='{"message": "Ack received!"}')
self.client.actions.recheck.create( self.client.actions.recheck.create(
host_name="somehost", host_name="somehost",
@ -32,6 +32,6 @@ class TestRecheck(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{"host_name": "somehost", "service_description": "someservice"} {"host_name": "somehost", "service_description": "someservice"}
) )

View File

@ -14,24 +14,23 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestBusinessImpactModulations(clienttest.ClientTest): class TestBusinessImpactModulations(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/" m.post("http://localhost:5311/v2/config/"
"businessimpactmodulations", "businessimpactmodulations",
body='[{"business_impact": 1,' text='[{"business_impact": 1,'
'"business_impact_modulation_name": "LowImpactOnDay",' '"business_impact_modulation_name": "LowImpactOnDay",'
'"modulation_period": "day"},' '"modulation_period": "day"},'
'{"business_impact": 1,' '{"business_impact": 1,'
'"business_impact_modulation_name": "LowImpactOnNight",' '"business_impact_modulation_name": '
'"LowImpactOnNight",'
'"modulation_period": "night"}]' '"modulation_period": "night"}]'
) )
businessimpactmodulations = (self.client.config. businessimpactmodulations = (self.client.config.
@ -47,12 +46,11 @@ class TestBusinessImpactModulations(clienttest.ClientTest):
"modulation_period": "night"}, ] "modulation_period": "night"}, ]
) )
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/" m.put("http://localhost:5311/v2/config/"
"businessimpactmodulations", "businessimpactmodulations",
body='{"business_impact": 1,' text='{"business_impact": 1,'
'"business_impact_modulation_name": "testtt",' '"business_impact_modulation_name": "testtt",'
'"modulation_period": "day"}' '"modulation_period": "day"}'
) )
@ -64,7 +62,7 @@ class TestBusinessImpactModulations(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"business_impact": 1, "business_impact": 1,
"business_impact_modulation_name": "testtt", "business_impact_modulation_name": "testtt",
@ -72,13 +70,11 @@ class TestBusinessImpactModulations(clienttest.ClientTest):
} }
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get('http://localhost:5311/v2/config/businessimpactmodulations/'
'http://localhost:5311/v2/config/businessimpactmodulations/'
'LowImpactOnDay', 'LowImpactOnDay',
body='{"business_impact": 1,' text='{"business_impact": 1,'
'"business_impact_modulation_name": "LowImpactOnDay",' '"business_impact_modulation_name": "LowImpactOnDay",'
'"modulation_period": "day"}' '"modulation_period": "day"}'
) )
@ -95,13 +91,11 @@ class TestBusinessImpactModulations(clienttest.ClientTest):
"modulation_period": "day"} "modulation_period": "day"}
) )
@httpretty.activate
def test_update(self): def test_update(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, m.put('http://localhost:5311/v2/config/'
'http://localhost:5311/v2/config/businessimpactmodulations/' 'businessimpactmodulations/LowImpactOnNight',
'LowImpactOnNight', text='{"test": "test"}'
body='{"test": "test"}'
) )
self.client.config.businessimpactmodulations.update( self.client.config.businessimpactmodulations.update(
@ -110,19 +104,17 @@ class TestBusinessImpactModulations(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"modulation_period": u"night" "modulation_period": u"night"
} }
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, m.delete("http://localhost:5311/v2/config/"
"http://localhost:5311/v2/config/businessimpactmodulations/" "businessimpactmodulations/name_to_delete",
"name_to_delete", text="body"
body="body"
) )
body = self.client.config.businessimpactmodulations.delete( body = self.client.config.businessimpactmodulations.delete(

View File

@ -13,17 +13,16 @@
# under the License. # under the License.
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestCheckModulations(clienttest.ClientTest): class TestCheckModulations(clienttest.ClientTest):
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/checkmodulations", m.put("http://localhost:5311/v2/config/checkmodulations",
body='{"message": "Ack received!"}') text='{"message": "Ack received!"}')
self.client.config.checkmodulations.create( self.client.config.checkmodulations.create(
check_command='test', check_command='test',
@ -32,17 +31,17 @@ class TestCheckModulations(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{"checkmodulation_name": "test", {"checkmodulation_name": "test",
"check_command": "test", "check_command": "test",
"check_period": "test"} "check_period": "test"}
) )
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/checkmodulations", m.post("http://localhost:5311/v2/config/checkmodulations",
body='[{"checkmodulation_name": "test","check_command": "test",' text='[{"checkmodulation_name": "test",'
'"check_command": "test",'
'"check_period": "test"}]' '"check_period": "test"}]'
) )
@ -52,12 +51,11 @@ class TestCheckModulations(clienttest.ClientTest):
"check_command": "test", "check_period": "test"}] "check_command": "test", "check_period": "test"}]
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, "http://localhost:5311/v2/config/" m.delete("http://localhost:5311/v2/config/"
"checkmodulations/checkmodulation_to_delete", "checkmodulations/checkmodulation_to_delete",
body='body') text='body')
body = self.client.config.checkmodulations.delete( body = self.client.config.checkmodulations.delete(
checkmodulation_name='checkmodulation_to_delete' checkmodulation_name='checkmodulation_to_delete'
@ -68,12 +66,11 @@ class TestCheckModulations(clienttest.ClientTest):
"body" "body"
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get('http://localhost:5311/v2/config/checkmodulations/' +
'http://localhost:5311/v2/config/checkmodulations/ping_night', 'ping_night',
body='{"checkmodulation_name": "ping_night",' text='{"checkmodulation_name": "ping_night",'
'"check_command": "check_ping_night",' '"check_command": "check_ping_night",'
'"check_period": "night"}' '"check_period": "night"}'
) )
@ -89,13 +86,11 @@ class TestCheckModulations(clienttest.ClientTest):
"check_period": "night"} "check_period": "night"}
) )
@httpretty.activate
def test_update(self): def test_update(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, m.put('http://localhost:5311/v2/config/checkmodulations/' +
'http://localhost:5311/v2/config/checkmodulations/ping_night', 'ping_night',
body='{"check_command": "updated"}' text='{"check_command": "updated"}')
)
self.client.config.checkmodulations.update( self.client.config.checkmodulations.update(
checkmodulation_name='ping_night', checkmodulation_name='ping_night',
@ -103,7 +98,7 @@ class TestCheckModulations(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"check_command": u"updated" "check_command": u"updated"
} }

View File

@ -14,19 +14,17 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestCommands(clienttest.ClientTest): class TestCommands(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, m.post("http://localhost:5311/v2/config/commands",
"http://localhost:5311/v2/config/commands", text='[{"command_name":"myCommand"}]'
body='[{"command_name":"myCommand"}]'
) )
self.assertEqual( self.assertEqual(
@ -34,11 +32,11 @@ class TestCommands(clienttest.ClientTest):
[{"command_name": "myCommand"}] [{"command_name": "myCommand"}]
) )
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/commands", m.put("http://localhost:5311/v2/config/commands",
body='{"command_name": "new_command", "command_line": "new_line"}' text='{"command_name": "new_command",'
' "command_line": "new_line"}'
) )
self.client.config.commands.create( self.client.config.commands.create(
@ -47,19 +45,18 @@ class TestCommands(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"command_name": "new_command", "command_name": "new_command",
"command_line": "new_line" "command_line": "new_line"
} }
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get("http://localhost:5311/v2/config/commands/command_to_show",
"http://localhost:5311/v2/config/commands/command_to_show", text='{"command_name": "command_to_show",'
body='{"command_name": "command_to_show", "command_line": "line"}' '"command_line": "line"}'
) )
command = self.client.config.commands.get( command = self.client.config.commands.get(
@ -74,12 +71,10 @@ class TestCommands(clienttest.ClientTest):
} }
) )
@httpretty.activate
def test_update(self): def test_update(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, m.put("http://localhost:5311/v2/config/commands/command_to_update",
"http://localhost:5311/v2/config/commands/command_to_update", text='{"command_line": "updated command_line"}'
body='{"command_line": "updated command_line"}'
) )
self.client.config.commands.update( self.client.config.commands.update(
@ -88,18 +83,17 @@ class TestCommands(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"command_line": "updated command_line" "command_line": "updated command_line"
} }
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, m.delete("http://localhost:5311/v2/config/commands/"
"http://localhost:5311/v2/config/commands/command_to_delete", "command_to_delete",
body="body" text="body"
) )
body = self.client.config.commands.delete( body = self.client.config.commands.delete(

View File

@ -14,17 +14,16 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestContactGroups(clienttest.ClientTest): class TestContactGroups(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/contactgroups", m.post("http://localhost:5311/v2/config/contactgroups",
body='[{"contactgroup_name": "novell-admins",' text='[{"contactgroup_name": "novell-admins",'
'"members": "jdoe,rtobert,tzach"},' '"members": "jdoe,rtobert,tzach"},'
'{"contactgroup_name": "linux-adminx",' '{"contactgroup_name": "linux-adminx",'
'"members": "linus,richard"}]' '"members": "linus,richard"}]'
@ -41,11 +40,10 @@ class TestContactGroups(clienttest.ClientTest):
] ]
) )
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/contactgroups", m.put("http://localhost:5311/v2/config/contactgroups",
body='{"contactgroup_name": "John",' text='{"contactgroup_name": "John",'
'"members": "marie,bob,joe"}' '"members": "marie,bob,joe"}'
) )
@ -55,19 +53,18 @@ class TestContactGroups(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"contactgroup_name": "John", "contactgroup_name": "John",
"members": "marie,bob,joe" "members": "marie,bob,joe"
} }
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get('http://localhost:5311/v2/'
'http://localhost:5311/v2/config/contactgroups/novell-admins', 'config/contactgroups/novell-admins',
body='{"contactgroup_name": "novell-admins",' text='{"contactgroup_name": "novell-admins",'
'"members": "jdoe,rtobert,tzach"}' '"members": "jdoe,rtobert,tzach"}'
) )
@ -83,12 +80,11 @@ class TestContactGroups(clienttest.ClientTest):
} }
) )
@httpretty.activate
def test_update(self): def test_update(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, m.put('http://localhost:5311/v2/config/contactgroups/'
'http://localhost:5311/v2/config/contactgroups/novell-admins', 'novell-admins',
body='{"test": "test"}' text='{"test": "test"}'
) )
self.client.config.contactgroups.update( self.client.config.contactgroups.update(
@ -97,18 +93,17 @@ class TestContactGroups(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"members": u"updated" "members": u"updated"
} }
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, m.delete("http://localhost:5311/v2/config/contactgroups/"
"http://localhost:5311/v2/config/contactgroups/novell-admins", "novell-admins",
body="body" text="body"
) )
body = self.client.config.contactgroups.delete( body = self.client.config.contactgroups.delete(

View File

@ -14,17 +14,16 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestContacts(clienttest.ClientTest): class TestContacts(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/contacts", m.post("http://localhost:5311/v2/config/contacts",
body='[{"contact_name": "bobby",' text='[{"contact_name": "bobby",'
'"email": "bob@bob.com"},' '"email": "bob@bob.com"},'
'{"contact_name": "marie",' '{"contact_name": "marie",'
'"email": "marie@marie.com"}]' '"email": "marie@marie.com"}]'
@ -44,35 +43,29 @@ class TestContacts(clienttest.ClientTest):
'email': 'marie@marie.com' 'email': 'marie@marie.com'
}, },
] ]
) )
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/contacts", m.put("http://localhost:5311/v2/config/contacts",
body='{"contact_name": "John"}' text='{"contact_name": "John"}')
)
self.client.config.contacts.create( self.client.config.contacts.create(
contact_name='John' contact_name='John'
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"contact_name": "John" "contact_name": "John"
} }
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get('http://localhost:5311/v2/config/contacts/bobby',
'http://localhost:5311/v2/config/contacts/bobby', text='{"contact_name": "bobby",'
body='{"contact_name": "bobby",' '"email": "bob@bob.com"}')
'"email": "bob@bob.com"}'
)
contact = self.client.config.contacts.get( contact = self.client.config.contacts.get(
contact_name='bobby' contact_name='bobby'
@ -86,13 +79,10 @@ class TestContacts(clienttest.ClientTest):
} }
) )
@httpretty.activate
def test_update(self): def test_update(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, m.put('http://localhost:5311/v2/config/contacts/bob',
'http://localhost:5311/v2/config/contacts/bob', text='{"test": "test"}')
body='{"test": "test"}'
)
self.client.config.contacts.update( self.client.config.contacts.update(
contact_name="bob", contact_name="bob",
@ -100,19 +90,16 @@ class TestContacts(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"email": u"updated" "email": u"updated"
} }
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, m.delete("http://localhost:5311/v2/config/contacts/bob",
"http://localhost:5311/v2/config/contacts/bob", text="body")
body="body"
)
body = self.client.config.contacts.delete( body = self.client.config.contacts.delete(
contact_name="bob", contact_name="bob",

View File

@ -14,17 +14,16 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestHostGroups(clienttest.ClientTest): class TestHostGroups(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/hostgroups", m.post("http://localhost:5311/v2/config/hostgroups",
body='[{"hostgroup_name": "novell-servers",' text='[{"hostgroup_name": "novell-servers",'
'"members": "netware1,netware2,netware3,netware4"},' '"members": "netware1,netware2,netware3,netware4"},'
'{"hostgroup_name": "otherservers",' '{"hostgroup_name": "otherservers",'
'"members": "googul,sfl"}]' '"members": "googul,sfl"}]'
@ -46,13 +45,11 @@ class TestHostGroups(clienttest.ClientTest):
] ]
) )
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/hostgroups", m.put("http://localhost:5311/v2/config/hostgroups",
body='{"hostgroup_name": "John",' text='{"hostgroup_name": "John",'
'"members": "marie,bob,joe"}' '"members": "marie,bob,joe"}')
)
self.client.config.hostgroups.create( self.client.config.hostgroups.create(
hostgroup_name='John', hostgroup_name='John',
@ -60,21 +57,18 @@ class TestHostGroups(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"hostgroup_name": "John", "hostgroup_name": "John",
"members": "marie,bob,joe" "members": "marie,bob,joe"
} }
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get('http://localhost:5311/v2/config/hostgroups/novell-servers',
'http://localhost:5311/v2/config/hostgroups/novell-servers', text='{"hostgroup_name": "novell-servers",'
body='{"hostgroup_name": "novell-servers",' '"members": "netware1,netware2,netware3,netware4"}')
'"members": "netware1,netware2,netware3,netware4"}'
)
hostgroup = self.client.config.hostgroups.get( hostgroup = self.client.config.hostgroups.get(
hostgroup_name='novell-servers' hostgroup_name='novell-servers'
@ -88,13 +82,9 @@ class TestHostGroups(clienttest.ClientTest):
} }
) )
@httpretty.activate
def test_update(self): def test_update(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, m.put('http://localhost:5311/v2/config/hostgroups/novell-servers')
'http://localhost:5311/v2/config/hostgroups/novell-servers',
body='{"test": "test"}'
)
self.client.config.hostgroups.update( self.client.config.hostgroups.update(
hostgroup_name="novell-servers", hostgroup_name="novell-servers",
@ -102,19 +92,17 @@ class TestHostGroups(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"members": u"updated" "members": u"updated"
} }
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, m.delete("http://localhost:5311/v2/"
"http://localhost:5311/v2/config/hostgroups/novell-servers", "config/hostgroups/novell-servers",
body="body" text="body")
)
body = self.client.config.hostgroups.delete( body = self.client.config.hostgroups.delete(
hostgroup_name="novell-servers", hostgroup_name="novell-servers",

View File

@ -14,19 +14,17 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestHosts(clienttest.ClientTest): class TestHosts(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/hosts", m.post("http://localhost:5311/v2/config/hosts",
body='[{"host_name": "host1"}]' text='[{"host_name": "host1"}]')
)
hosts = self.client.config.hosts.list() hosts = self.client.config.hosts.list()
@ -36,31 +34,27 @@ class TestHosts(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"filters": '{"isnot": {"register": ["0"]}}' "filters": '{"isnot": {"register": ["0"]}}'
} }
) )
@httpretty.activate
def test_list_templates(self): def test_list_templates(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/hosts", m.post("http://localhost:5311/v2/config/hosts",
body='[]' text='[]')
)
self.client.config.hosts.list(templates=True) self.client.config.hosts.list(templates=True)
self.assertEqual( self.assertEqual(
httpretty.last_request().path, m.last_request.path,
'/v2/config/hosts?' '/v2/config/hosts'
) )
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/hosts", m.put("http://localhost:5311/v2/config/hosts",
body='{"host_name": "new_host", "address": "192.168.2.1"}' text='{"host_name": "new_host", "address": "192.168.2.1"}')
)
self.client.config.hosts.create( self.client.config.hosts.create(
host_name="new_host", host_name="new_host",
@ -68,20 +62,17 @@ class TestHosts(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"host_name": "new_host", "host_name": "new_host",
"address": "192.168.2.1" "address": "192.168.2.1"
} }
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get("http://localhost:5311/v2/config/hosts/host_name_to_show",
"http://localhost:5311/v2/config/hosts/host_name_to_show", text='{"host_name": "host_name_to_show"}')
body='{"host_name": "host_name_to_show"}'
)
host = self.client.config.hosts.get( host = self.client.config.hosts.get(
host_name="host_name_to_show" host_name="host_name_to_show"
@ -92,13 +83,10 @@ class TestHosts(clienttest.ClientTest):
{"host_name": "host_name_to_show"} {"host_name": "host_name_to_show"}
) )
@httpretty.activate
def test_update(self): def test_update(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, m.put("http://localhost:5311/v2/config/hosts/host_name_to_update",
"http://localhost:5311/v2/config/hosts/host_name_to_update", text='{"test": "test"}')
body='{"test": "test"}'
)
self.client.config.hosts.update( self.client.config.hosts.update(
host_name="host_name_to_update", host_name="host_name_to_update",
@ -108,20 +96,18 @@ class TestHosts(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"check_period": u"24x7", "check_period": u"24x7",
"address": u"192.168.0.1" "address": u"192.168.0.1"
} }
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, m.delete("http://localhost:5311/v2/"
"http://localhost:5311/v2/config/hosts/host_name_to_delete", "config/hosts/host_name_to_delete",
body="body" text="body")
)
body = self.client.config.hosts.delete( body = self.client.config.hosts.delete(
host_name="host_name_to_delete", host_name="host_name_to_delete",

View File

@ -14,25 +14,23 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestMacroModulations(clienttest.ClientTest): class TestMacroModulations(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/macromodulations", m.post("http://localhost:5311/v2/config/macromodulations",
body='[{"macromodulation_name": "HighDuringNight",' text='[{"macromodulation_name": "HighDuringNight",'
'"modulation_period": "night",' '"modulation_period": "night",'
'"_CRITICAL": 20,' '"_CRITICAL": 20,'
'"_WARNING": 10},' '"_WARNING": 10},'
'{"macromodulation_name": "LowDuringNight",' '{"macromodulation_name": "LowDuringNight",'
'"modulation_period": "night",' '"modulation_period": "night",'
'"_CRITICAL": 10,' '"_CRITICAL": 10,'
'"_WARNING": 20}]' '"_WARNING": 20}]')
)
contacts = self.client.config.macromodulations.list() contacts = self.client.config.macromodulations.list()
@ -54,13 +52,11 @@ class TestMacroModulations(clienttest.ClientTest):
] ]
) )
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/macromodulations", m.put("http://localhost:5311/v2/config/macromodulations",
body='{"macromodulation_name": "TEST_CREATE_MODULATION",' text='{"macromodulation_name": "TEST_CREATE_MODULATION",'
'"modulation_period": "night"}' '"modulation_period": "night"}')
)
self.client.config.macromodulations.create( self.client.config.macromodulations.create(
macromodulation_name='TEST_CREATE_MODULATION', macromodulation_name='TEST_CREATE_MODULATION',
@ -68,21 +64,19 @@ class TestMacroModulations(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"macromodulation_name": "TEST_CREATE_MODULATION", "macromodulation_name": "TEST_CREATE_MODULATION",
"modulation_period": "night" "modulation_period": "night"
} }
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get('http://localhost:5311/v2/config/'
'http://localhost:5311/v2/config/macromodulations/HighDuringNight', 'macromodulations/HighDuringNight',
body='{"macromodulation_name": "HighDuringNight",' text='{"macromodulation_name": "HighDuringNight",'
'"modulation_period": "night"}' '"modulation_period": "night"}')
)
macromodulation = self.client.config.macromodulations.get( macromodulation = self.client.config.macromodulations.get(
macromodulation_name='HighDuringNight' macromodulation_name='HighDuringNight'
@ -96,13 +90,11 @@ class TestMacroModulations(clienttest.ClientTest):
} }
) )
@httpretty.activate
def test_update(self): def test_update(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, m.put('http://localhost:5311/v2/config/'
'http://localhost:5311/v2/config/macromodulations/HighDuringNight', 'macromodulations/HighDuringNight',
body='{"test": "test"}' text='{"test": "test"}')
)
self.client.config.macromodulations.update( self.client.config.macromodulations.update(
macromodulation_name="HighDuringNight", macromodulation_name="HighDuringNight",
@ -110,19 +102,16 @@ class TestMacroModulations(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"modulation_period": u"updated" "modulation_period": u"updated"
} }
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, m.delete("http://localhost:5311/v2/config/macromodulations/test",
"http://localhost:5311/v2/config/macromodulations/test", text="body")
body="body"
)
body = self.client.config.macromodulations.delete( body = self.client.config.macromodulations.delete(
macromodulation_name="test", macromodulation_name="test",

View File

@ -14,17 +14,16 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestNotificationWays(clienttest.ClientTest): class TestNotificationWays(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/notificationways", m.post("http://localhost:5311/v2/config/notificationways",
body='[{' text='[{'
'"notificationway_name": "email_in_day",' '"notificationway_name": "email_in_day",'
'"host_notification_period": "24x7",' '"host_notification_period": "24x7",'
'"service_notification_period": "24x7",' '"service_notification_period": "24x7",'
@ -43,8 +42,7 @@ class TestNotificationWays(clienttest.ClientTest):
'"service_notification_commands": "notify-host",' '"service_notification_commands": "notify-host",'
'"min_business_impact": 5' '"min_business_impact": 5'
'}' '}'
']' ']')
)
notificationways = self.client.config.notificationways.list() notificationways = self.client.config.notificationways.list()
@ -74,11 +72,10 @@ class TestNotificationWays(clienttest.ClientTest):
) )
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/notificationways", m.put("http://localhost:5311/v2/config/notificationways",
body='{' text='{'
'"notificationway_name": "email_in_day",' '"notificationway_name": "email_in_day",'
'"host_notification_period": "24x7",' '"host_notification_period": "24x7",'
'"service_notification_period": "24x7",' '"service_notification_period": "24x7",'
@ -86,8 +83,7 @@ class TestNotificationWays(clienttest.ClientTest):
'"service_notification_options": "w,c,r",' '"service_notification_options": "w,c,r",'
'"host_notification_commands": "notify-service",' '"host_notification_commands": "notify-service",'
'"service_notification_commands": "notify-host"' '"service_notification_commands": "notify-host"'
'}' '}')
)
self.client.config.notificationways.create( self.client.config.notificationways.create(
notificationway_name='test_create_notification', notificationway_name='test_create_notification',
@ -101,7 +97,7 @@ class TestNotificationWays(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
'notificationway_name': 'test_create_notification', 'notificationway_name': 'test_create_notification',
'host_notification_period': '24x7', 'host_notification_period': '24x7',
@ -114,12 +110,11 @@ class TestNotificationWays(clienttest.ClientTest):
} }
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get('http://localhost:5311/v2/config/'
'http://localhost:5311/v2/config/notificationways/email_all_time', 'notificationways/email_all_time',
body='{' text='{'
'"notificationway_name": "email_all_time",' '"notificationway_name": "email_all_time",'
'"host_notification_period": "24x7",' '"host_notification_period": "24x7",'
'"service_notification_period": "24x7",' '"service_notification_period": "24x7",'
@ -128,8 +123,7 @@ class TestNotificationWays(clienttest.ClientTest):
'"host_notification_commands": "notify-service",' '"host_notification_commands": "notify-service",'
'"service_notification_commands": "notify-host",' '"service_notification_commands": "notify-host",'
'"min_business_impact": 5' '"min_business_impact": 5'
'}' '}')
)
notificationway = self.client.config.notificationways.get( notificationway = self.client.config.notificationways.get(
notificationway_name='email_all_time' notificationway_name='email_all_time'
@ -149,13 +143,11 @@ class TestNotificationWays(clienttest.ClientTest):
} }
) )
@httpretty.activate
def test_update(self): def test_update(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, m.put('http://localhost:5311/v2/'
'http://localhost:5311/v2/config/notificationways/email_all_time', 'config/notificationways/email_all_time',
body='{"test": "test"}' text='{"test": "test"}')
)
self.client.config.notificationways.update( self.client.config.notificationways.update(
notificationway_name="email_all_time", notificationway_name="email_all_time",
@ -163,19 +155,16 @@ class TestNotificationWays(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"host_notification_period": u"updated" "host_notification_period": u"updated"
} }
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, m.delete("http://localhost:5311/v2/config/notificationways/bob",
"http://localhost:5311/v2/config/notificationways/bob", text="body")
body="body"
)
body = self.client.config.notificationways.delete( body = self.client.config.notificationways.delete(
notificationway_name="bob", notificationway_name="bob",

View File

@ -14,17 +14,16 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestRealms(clienttest.ClientTest): class TestRealms(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/realms", m.post("http://localhost:5311/v2/config/realms",
body='[' text='['
'{' '{'
'"realm_name": "World",' '"realm_name": "World",'
'"realm_members": "Europe,America,Asia",' '"realm_members": "Europe,America,Asia",'
@ -35,8 +34,7 @@ class TestRealms(clienttest.ClientTest):
'"realm_members": "void,black-hole",' '"realm_members": "void,black-hole",'
'"default": 1' '"default": 1'
'}' '}'
']' ']')
)
realms = self.client.config.realms.list() realms = self.client.config.realms.list()
@ -57,14 +55,12 @@ class TestRealms(clienttest.ClientTest):
) )
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/realms", m.put("http://localhost:5311/v2/config/realms",
body='{"realm_name": "John",' text='{"realm_name": "John",'
'"realm_members":"marie,bob,joe",' '"realm_members":"marie,bob,joe",'
'"default":1}' '"default":1}')
)
self.client.config.realms.create( self.client.config.realms.create(
realm_name='John', realm_name='John',
@ -73,7 +69,7 @@ class TestRealms(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"realm_name": "John", "realm_name": "John",
"realm_members": "marie,bob,joe", "realm_members": "marie,bob,joe",
@ -81,17 +77,14 @@ class TestRealms(clienttest.ClientTest):
} }
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get('http://localhost:5311/v2/config/realms/bobby',
'http://localhost:5311/v2/config/realms/bobby', text='{'
body='{'
'"realm_name": "World",' '"realm_name": "World",'
'"realm_members": "Europe,America,Asia",' '"realm_members": "Europe,America,Asia",'
'"default": 0' '"default": 0'
'}' '}')
)
realm = self.client.config.realms.get( realm = self.client.config.realms.get(
realm_name='bobby' realm_name='bobby'
@ -106,13 +99,10 @@ class TestRealms(clienttest.ClientTest):
} }
) )
@httpretty.activate
def test_update(self): def test_update(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, m.put('http://localhost:5311/v2/config/realms/World',
'http://localhost:5311/v2/config/realms/World', text='{"test": "test"}')
body='{"test": "test"}'
)
self.client.config.realms.update( self.client.config.realms.update(
realm_name="World", realm_name="World",
@ -120,19 +110,16 @@ class TestRealms(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"realm_members": u"updated" "realm_members": u"updated"
} }
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, m.delete("http://localhost:5311/v2/config/realms/bob",
"http://localhost:5311/v2/config/realms/bob", text="body")
body="body"
)
body = self.client.config.realms.delete( body = self.client.config.realms.delete(
realm_name="bob", realm_name="bob",

View File

@ -14,22 +14,20 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestServiceGroups(clienttest.ClientTest): class TestServiceGroups(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/servicegroups", m.post("http://localhost:5311/v2/config/servicegroups",
body='[{"servicegroup_name": "dbservices",' text='[{"servicegroup_name": "dbservices",'
'"members": "ms1,SQL Server,ms1,' '"members": "ms1,SQL Server,ms1,'
'SQL Serverc Agent,ms1,SQL DTC"},' 'SQL Serverc Agent,ms1,SQL DTC"},'
'{"servicegroup_name": "otherservices",' '{"servicegroup_name": "otherservices",'
'"members": "some,other,member"}]' '"members": "some,other,member"}]')
)
servicegroups = self.client.config.servicegroups.list() servicegroups = self.client.config.servicegroups.list()
@ -48,13 +46,11 @@ class TestServiceGroups(clienttest.ClientTest):
] ]
) )
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/servicegroups", m.put("http://localhost:5311/v2/config/servicegroups",
body='{"servicegroup_name": "John",' text='{"servicegroup_name": "John",'
'"members": "marie,bob,joe"}' '"members": "marie,bob,joe"}')
)
self.client.config.servicegroups.create( self.client.config.servicegroups.create(
servicegroup_name='John', servicegroup_name='John',
@ -62,22 +58,19 @@ class TestServiceGroups(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"servicegroup_name": "John", "servicegroup_name": "John",
"members": "marie,bob,joe" "members": "marie,bob,joe"
} }
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get('http://localhost:5311/v2/config/servicegroups/dbservices',
'http://localhost:5311/v2/config/servicegroups/dbservices', text='{"servicegroup_name": "dbservices",'
body='{"servicegroup_name": "dbservices",'
'"members": "ms1,SQL Server,ms1,' '"members": "ms1,SQL Server,ms1,'
'SQL Serverc Agent,ms1,SQL DTC"}' 'SQL Serverc Agent,ms1,SQL DTC"}')
)
servicegroup = self.client.config.servicegroups.get( servicegroup = self.client.config.servicegroups.get(
servicegroup_name='dbservices' servicegroup_name='dbservices'
@ -87,17 +80,15 @@ class TestServiceGroups(clienttest.ClientTest):
servicegroup, servicegroup,
{ {
'servicegroup_name': 'dbservices', 'servicegroup_name': 'dbservices',
'members': 'ms1,SQL Server,ms1,SQL Serverc Agent,ms1,SQL DTC' 'members': 'ms1,SQL Server,ms1,'
'SQL Serverc Agent,ms1,SQL DTC'
} }
) )
@httpretty.activate
def test_update(self): def test_update(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, m.put('http://localhost:5311/v2/config/servicegroups/dbservices',
'http://localhost:5311/v2/config/servicegroups/dbservices', text='{"test": "test"}')
body='{"test": "test"}'
)
self.client.config.servicegroups.update( self.client.config.servicegroups.update(
servicegroup_name="dbservices", servicegroup_name="dbservices",
@ -105,19 +96,17 @@ class TestServiceGroups(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"members": u"updated" "members": u"updated"
} }
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, m.delete("http://localhost:5311/v2/config/"
"http://localhost:5311/v2/config/servicegroups/dbservices", "servicegroups/dbservices",
body="body" text="body")
)
body = self.client.config.servicegroups.delete( body = self.client.config.servicegroups.delete(
servicegroup_name="dbservices", servicegroup_name="dbservices",

View File

@ -14,19 +14,17 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestServices(clienttest.ClientTest): class TestServices(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/services", m.post("http://localhost:5311/v2/config/services",
body='[{"service_name": "service1"}]' text='[{"service_name": "service1"}]')
)
services = self.client.config.services.list() services = self.client.config.services.list()
@ -35,49 +33,42 @@ class TestServices(clienttest.ClientTest):
[{"service_name": "service1"}] [{"service_name": "service1"}]
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"filters": '{"isnot": {"register": ["0"]}}' "filters": '{"isnot": {"register": ["0"]}}'
} }
) )
@httpretty.activate
def test_list_templates(self): def test_list_templates(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/services", m.post("http://localhost:5311/v2/config/services",
body='[{"service_name": "service1"}]' text='[{"service_name": "service1"}]')
)
self.client.config.services.list(templates=True) self.client.config.services.list(templates=True)
self.assertEqual( self.assertEqual(
httpretty.last_request().path, m.last_request.path,
'/v2/config/services?' '/v2/config/services'
) )
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/services", m.put("http://localhost:5311/v2/config/services",
body='{"service_name": "new_service"}' text='{"service_name": "new_service"}')
)
self.client.config.services.create( self.client.config.services.create(
service_name="new_service" service_name="new_service"
) )
self.assertEqual( self.assertEqual(
httpretty.last_request().body.decode(), m.last_request.body,
'{"service_name": "new_service"}' '{"service_name": "new_service"}'
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, m.delete("http://localhost:5311/v2/config/hosts/host_name/" +
"http://localhost:5311/v2/config/hosts/host_name/" +
"services/service_description", "services/service_description",
body="body" text="body")
)
body = self.client.config.services.delete( body = self.client.config.services.delete(
host_name="host_name", host_name="host_name",
@ -89,14 +80,11 @@ class TestServices(clienttest.ClientTest):
"body" "body"
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get("http://localhost:5311/v2/config/hosts/host_name/" +
"http://localhost:5311/v2/config/hosts/host_name/" +
"services/service_description", "services/service_description",
body="{}" text="{}")
)
body = self.client.config.services.get( body = self.client.config.services.get(
host_name="host_name", host_name="host_name",

View File

@ -14,17 +14,16 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestTimePeriods(clienttest.ClientTest): class TestTimePeriods(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/config/timeperiods", m.post("http://localhost:5311/v2/config/timeperiods",
body='[' text='['
'{' '{'
'"timeperiod_name": "nonworkhours",' '"timeperiod_name": "nonworkhours",'
'"sunday": "00:00-24:00",' '"sunday": "00:00-24:00",'
@ -35,9 +34,7 @@ class TestTimePeriods(clienttest.ClientTest):
'"1999-01-28": "00:00-24:00",' '"1999-01-28": "00:00-24:00",'
'"day 2": "00:00-24:00"' '"day 2": "00:00-24:00"'
'}' '}'
']' ']')
)
timeperiods = self.client.config.timeperiods.list() timeperiods = self.client.config.timeperiods.list()
@ -58,35 +55,30 @@ class TestTimePeriods(clienttest.ClientTest):
) )
@httpretty.activate
def test_create(self): def test_create(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, "http://localhost:5311/v2/config/timeperiods", m.put("http://localhost:5311/v2/config/timeperiods",
body='{"timeperiod_name": "John"}' text='{"timeperiod_name": "John"}')
)
self.client.config.timeperiods.create( self.client.config.timeperiods.create(
timeperiod_name='new_periods' timeperiod_name='new_periods'
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"timeperiod_name": "new_periods" "timeperiod_name": "new_periods"
} }
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, m.get('http://localhost:5311/v2/config/timeperiods/nonworkhours',
'http://localhost:5311/v2/config/timeperiods/nonworkhours', text='{'
body='{'
'"timeperiod_name": "nonworkhours",' '"timeperiod_name": "nonworkhours",'
'"sunday": "00:00-24:00",' '"sunday": "00:00-24:00",'
'"monday": "00:00-09:00,17:00-24:00"' '"monday": "00:00-09:00,17:00-24:00"'
'}' '}')
)
timeperiod = self.client.config.timeperiods.get( timeperiod = self.client.config.timeperiods.get(
timeperiod_name='nonworkhours' timeperiod_name='nonworkhours'
@ -101,13 +93,10 @@ class TestTimePeriods(clienttest.ClientTest):
} }
) )
@httpretty.activate
def test_update(self): def test_update(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.PUT, m.put('http://localhost:5311/v2/config/timeperiods/nonworkhours',
'http://localhost:5311/v2/config/timeperiods/nonworkhours', text='{"test": "test"}')
body='{"test": "test"}'
)
self.client.config.timeperiods.update( self.client.config.timeperiods.update(
timeperiod_name="nonworkhours", timeperiod_name="nonworkhours",
@ -115,19 +104,16 @@ class TestTimePeriods(clienttest.ClientTest):
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{ {
"timeperiod_name": u"updated" "timeperiod_name": u"updated"
} }
) )
@httpretty.activate
def test_delete(self): def test_delete(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.DELETE, m.delete("http://localhost:5311/v2/config/timeperiods/bob",
"http://localhost:5311/v2/config/timeperiods/bob", text="body")
body="body"
)
body = self.client.config.timeperiods.delete( body = self.client.config.timeperiods.delete(
timeperiod_name="bob", timeperiod_name="bob",

View File

@ -12,22 +12,22 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestEvents(clienttest.ClientTest): class TestEvents(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/status/events", m.post("http://localhost:5311/v2/status/events",
body='[{"host_name": "sfl.com", "service_description": "cpu", ' text='[{"host_name": "sfl.com", '
'"service_description": "cpu", '
'"event_type": "ALERT", "output": "Ok"},' '"event_type": "ALERT", "output": "Ok"},'
'{"host_name": "sfl.com", "service_description": "cpu", ' '{"host_name": "sfl.com", '
'"event_type": "ALERT", "output": "Not Ok"}]' '"service_description": "cpu", '
) '"event_type": "ALERT", "output": "Not Ok"}]')
events = self.client.status.events.list() events = self.client.status.events.list()
self.assertEqual( self.assertEqual(

View File

@ -14,19 +14,17 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestHosts(clienttest.ClientTest): class TestHosts(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/status/hosts", m.post("http://localhost:5311/v2/status/hosts",
body='[{"host_name": "host1"}]' text='[{"host_name": "host1"}]')
)
hosts = self.client.status.hosts.list() hosts = self.client.status.hosts.list()
@ -35,12 +33,10 @@ class TestHosts(clienttest.ClientTest):
[{"host_name": "host1"}] [{"host_name": "host1"}]
) )
@httpretty.activate
def test_get(self): def test_get(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, "http://localhost:5311/v2/status/hosts/hostname", m.get("http://localhost:5311/v2/status/hosts/hostname",
body='{"host_name": "host1"}' text='{"host_name": "host1"}')
)
host = self.client.status.hosts.get("hostname") host = self.client.status.hosts.get("hostname")
@ -49,19 +45,17 @@ class TestHosts(clienttest.ClientTest):
{"host_name": "host1"} {"host_name": "host1"}
) )
@httpretty.activate
def test_submit_host_check_result(self): def test_submit_host_check_result(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/status/hosts/localhost" m.post("http://localhost:5311/v2/status/hosts/localhost"
"/results", "/results",
body='' text='')
)
self.client.status.hosts.submit_check_result( self.client.status.hosts.submit_check_result(
"localhost", output="someoutput" "localhost", output="someoutput"
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{"output": u"someoutput"} {"output": u"someoutput"}
) )

View File

@ -12,19 +12,18 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestMetrics(clienttest.ClientTest): class TestMetrics(clienttest.ClientTest):
@httpretty.activate
def test_list_host_metrics(self): def test_list_host_metrics(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/status/" m.post("http://localhost:5311/v2/status/"
"hosts/localhost/metrics/load1", "hosts/localhost/metrics/load1",
body='[{"min": "2", "warning": "15", "value": "3"},' text='[{"min": "2", "warning": "15", "value": "3"},'
'{"min": "5", "warning": "200", "value": "150"}]' '{"min": "5", "warning": "200", "value": "150"}]'
) )
@ -39,12 +38,11 @@ class TestMetrics(clienttest.ClientTest):
{"min": "5", "warning": "200", "value": "150"}] {"min": "5", "warning": "200", "value": "150"}]
) )
@httpretty.activate
def test_list_host_metrics_service(self): def test_list_host_metrics_service(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/status/hosts/localhost" m.post("http://localhost:5311/v2/status/hosts/localhost"
"/services/load/metrics/load1", "/services/load/metrics/load1",
body='[{"min": "2", "warning": "15", "value": "3"},' text='[{"min": "2", "warning": "15", "value": "3"},'
'{"min": "5", "warning": "200", "value": "150"}]' '{"min": "5", "warning": "200", "value": "150"}]'
) )
@ -52,7 +50,8 @@ class TestMetrics(clienttest.ClientTest):
'"2015-05-22T13:38:08Z",' '"2015-05-22T13:38:08Z",'
'"end_time": "2015-05-22T13:38:08Z"}}') '"end_time": "2015-05-22T13:38:08Z"}}')
metrics = self.client.status.hosts.metrics.list('localhost', 'load1', metrics = self.client.status.hosts.metrics.list('localhost',
'load1',
'load', 'load',
query=live_query query=live_query
) )
@ -63,30 +62,30 @@ class TestMetrics(clienttest.ClientTest):
{"min": "5", "warning": "200", "value": "150"}] {"min": "5", "warning": "200", "value": "150"}]
) )
@httpretty.activate
def test_show_host_metrics(self): def test_show_host_metrics(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, "http://localhost:5311/v2/status/hosts/localhost" m.get("http://localhost:5311/v2/status/hosts/localhost"
"/metrics/load1", "/metrics/load1",
body='{"min": "2", "warning": "15", "value": "3"}' text='{"min": "2", "warning": "15", "value": "3"}'
) )
metrics = self.client.status.hosts.metrics.get('localhost', 'load1') metrics = self.client.status.hosts.metrics.get('localhost',
'load1')
self.assertEqual( self.assertEqual(
metrics, metrics,
{"min": "2", "warning": "15", "value": "3"} {"min": "2", "warning": "15", "value": "3"}
) )
@httpretty.activate
def test_show_host_service_metrics(self): def test_show_host_service_metrics(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, "http://localhost:5311/v2/status/hosts/localhost" m.get("http://localhost:5311/v2/status/hosts/localhost"
"/services/load/metrics/load1", "/services/load/metrics/load1",
body='{"value": "3"}' text='{"value": "3"}'
) )
metrics = self.client.status.hosts.metrics.get('localhost', 'load1', metrics = self.client.status.hosts.metrics.get('localhost',
'load1',
'load') 'load')
self.assertEqual( self.assertEqual(
@ -94,12 +93,11 @@ class TestMetrics(clienttest.ClientTest):
{"value": "3"} {"value": "3"}
) )
@httpretty.activate
def test_show_host_service(self): def test_show_host_service(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.GET, "http://localhost:5311/v2/status/hosts/localhost" m.get("http://localhost:5311/v2/status/hosts/localhost"
"/services/load/metrics", "/services/load/metrics",
body='[{"metric_name": "load1"},{"metric_name": "load5"}]' text='[{"metric_name": "load1"},{"metric_name": "load5"}]'
) )
metrics = self.client.status.hosts.metrics.get( metrics = self.client.status.hosts.metrics.get(

View File

@ -14,19 +14,17 @@
import json import json
import httpretty import requests_mock
from surveilclient.tests.v2_0 import clienttest from surveilclient.tests.v2_0 import clienttest
class TestServices(clienttest.ClientTest): class TestServices(clienttest.ClientTest):
@httpretty.activate
def test_list(self): def test_list(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, "http://localhost:5311/v2/status/services", m.post("http://localhost:5311/v2/status/services",
body='[{"service_name": "service1"}]' text='[{"service_name": "service1"}]')
)
services = self.client.status.services.list() services = self.client.status.services.list()
@ -35,22 +33,19 @@ class TestServices(clienttest.ClientTest):
[{"service_name": "service1"}] [{"service_name": "service1"}]
) )
@httpretty.activate
def test_submit_service_check_result(self): def test_submit_service_check_result(self):
httpretty.register_uri( with requests_mock.mock() as m:
httpretty.POST, m.post("http://localhost:5311/v2/status/hosts/localhost/"
"http://localhost:5311/v2/status/hosts/localhost" + "services/testservice/results",
"/services/testservice/results", text='')
body=''
)
self.client.status.services.submit_check_result( self.client.status.services.submit_check_result(
"localhost", "localhost",
'testservice', 'testservice',
output="someoutputt" output="someoutput"
) )
self.assertEqual( self.assertEqual(
json.loads(httpretty.last_request().body.decode()), json.loads(m.last_request.body),
{"output": u"someoutputt"} {"output": u"someoutput"}
) )

View File

@ -33,6 +33,6 @@ class Client(object):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
'/reload_config', '/reload_config',
'POST', 'POST',
body='' # Must send empty body data='' # Must send empty body
) )
return body return body

View File

@ -29,6 +29,6 @@ class HostsManager(surveil_manager.SurveilManager):
"""Create a new host.""" """Create a new host."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
HostsManager.base_url, 'POST', HostsManager.base_url, 'POST',
body=kwargs data=kwargs
) )
return body return body

View File

@ -29,6 +29,6 @@ class ServicesManager(surveil_manager.SurveilManager):
"""Create a new host.""" """Create a new host."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ServicesManager.base_url, 'POST', ServicesManager.base_url, 'POST',
body=kwargs data=kwargs
) )
return body return body

View File

@ -22,6 +22,6 @@ class AcknowledgeManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
self.base_url, self.base_url,
'POST', 'POST',
body=kwargs, data=kwargs,
) )
return body return body

View File

@ -22,6 +22,6 @@ class DowntimeManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
self.base_url, self.base_url,
'POST', 'POST',
body=kwargs, data=kwargs,
) )
return body return body

View File

@ -22,6 +22,6 @@ class RecheckManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
self.base_url, self.base_url,
'POST', 'POST',
body=kwargs, data=kwargs,
) )
return body return body

View File

@ -58,6 +58,6 @@ class ConfigManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
self.base_url + '/reload_config', self.base_url + '/reload_config',
'POST', 'POST',
body='' # Must send empty body data='' # Must send empty body
) )
return body return body

View File

@ -23,7 +23,7 @@ class BusinessImpactModulationsManager(surveil_manager.SurveilManager):
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
BusinessImpactModulationsManager.base_url, 'POST', BusinessImpactModulationsManager.base_url, 'POST',
body=query data=query
) )
return body return body
@ -31,7 +31,7 @@ class BusinessImpactModulationsManager(surveil_manager.SurveilManager):
"""Create a new businessimpactmodulation.""" """Create a new businessimpactmodulation."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
BusinessImpactModulationsManager.base_url, 'PUT', BusinessImpactModulationsManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
@ -40,7 +40,7 @@ class BusinessImpactModulationsManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
BusinessImpactModulationsManager.base_url + '/' + BusinessImpactModulationsManager.base_url + '/' +
businessimpactmodulation_name, 'GET', businessimpactmodulation_name, 'GET',
body='' data=''
) )
return body return body
@ -49,7 +49,7 @@ class BusinessImpactModulationsManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
BusinessImpactModulationsManager.base_url + '/' + BusinessImpactModulationsManager.base_url + '/' +
businessimpactmodulation_name, 'PUT', businessimpactmodulation_name, 'PUT',
body=businessimpactmodulation data=businessimpactmodulation
) )
return body return body
@ -58,7 +58,6 @@ class BusinessImpactModulationsManager(surveil_manager.SurveilManager):
resp, body = self.http_client.request( resp, body = self.http_client.request(
BusinessImpactModulationsManager.base_url + "/" + BusinessImpactModulationsManager.base_url + "/" +
businessimpactmodulation_name, businessimpactmodulation_name,
'DELETE', 'DELETE'
body=''
) )
return body return body

View File

@ -22,7 +22,7 @@ class CheckModulationsManager(surveil_manager.SurveilManager):
"""Get a list of checkmodulations.""" """Get a list of checkmodulations."""
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
CheckModulationsManager.base_url, 'POST', body=query CheckModulationsManager.base_url, 'POST', data=query
) )
return body return body
@ -30,7 +30,7 @@ class CheckModulationsManager(surveil_manager.SurveilManager):
"""Create a new checkmodulation.""" """Create a new checkmodulation."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
CheckModulationsManager.base_url, 'PUT', CheckModulationsManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
@ -39,7 +39,7 @@ class CheckModulationsManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
CheckModulationsManager.base_url + '/' + CheckModulationsManager.base_url + '/' +
checkmodulation_name, 'GET', checkmodulation_name, 'GET',
body='' data=''
) )
return body return body
@ -48,7 +48,7 @@ class CheckModulationsManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
CheckModulationsManager.base_url + '/' + CheckModulationsManager.base_url + '/' +
checkmodulation_name, 'PUT', checkmodulation_name, 'PUT',
body=checkmodulation data=checkmodulation
) )
return body return body
@ -56,7 +56,6 @@ class CheckModulationsManager(surveil_manager.SurveilManager):
"""Delete a checkmodulation.""" """Delete a checkmodulation."""
resp, body = self.http_client.request( resp, body = self.http_client.request(
CheckModulationsManager.base_url+"/" + checkmodulation_name, CheckModulationsManager.base_url+"/" + checkmodulation_name,
'DELETE', 'DELETE'
body=''
) )
return body return body

View File

@ -23,7 +23,7 @@ class CommandsManager(surveil_manager.SurveilManager):
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
CommandsManager.base_url, 'POST', CommandsManager.base_url, 'POST',
body=query data=query
) )
return body return body
@ -31,7 +31,7 @@ class CommandsManager(surveil_manager.SurveilManager):
"""Create a new command.""" """Create a new command."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
CommandsManager.base_url, 'PUT', CommandsManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
@ -39,7 +39,7 @@ class CommandsManager(surveil_manager.SurveilManager):
"""Get a new command.""" """Get a new command."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
CommandsManager.base_url + '/' + command_name, 'GET', CommandsManager.base_url + '/' + command_name, 'GET',
body='' data=''
) )
return body return body
@ -47,7 +47,7 @@ class CommandsManager(surveil_manager.SurveilManager):
"""Update a command.""" """Update a command."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
CommandsManager.base_url + '/' + command_name, 'PUT', CommandsManager.base_url + '/' + command_name, 'PUT',
body=command data=command
) )
return body return body
@ -55,7 +55,6 @@ class CommandsManager(surveil_manager.SurveilManager):
"""Delete a command.""" """Delete a command."""
resp, body = self.http_client.request( resp, body = self.http_client.request(
CommandsManager.base_url + "/" + command_name, CommandsManager.base_url + "/" + command_name,
'DELETE', 'DELETE'
body=''
) )
return body return body

View File

@ -23,7 +23,7 @@ class ContactGroupsManager(surveil_manager.SurveilManager):
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ContactGroupsManager.base_url, 'POST', ContactGroupsManager.base_url, 'POST',
body=query data=query
) )
return body return body
@ -31,7 +31,7 @@ class ContactGroupsManager(surveil_manager.SurveilManager):
"""Create a new contactgroup.""" """Create a new contactgroup."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ContactGroupsManager.base_url, 'PUT', ContactGroupsManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
@ -39,7 +39,7 @@ class ContactGroupsManager(surveil_manager.SurveilManager):
"""Get a new contactgroup.""" """Get a new contactgroup."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ContactGroupsManager.base_url + '/' + contactgroup_name, 'GET', ContactGroupsManager.base_url + '/' + contactgroup_name, 'GET',
body='' data=''
) )
return body return body
@ -47,7 +47,7 @@ class ContactGroupsManager(surveil_manager.SurveilManager):
"""Update a contactgroup.""" """Update a contactgroup."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ContactGroupsManager.base_url + '/' + contactgroup_name, 'PUT', ContactGroupsManager.base_url + '/' + contactgroup_name, 'PUT',
body=contactgroup data=contactgroup
) )
return body return body
@ -55,7 +55,6 @@ class ContactGroupsManager(surveil_manager.SurveilManager):
"""Delete a contactgroup.""" """Delete a contactgroup."""
resp, body = self.http_client.request( resp, body = self.http_client.request(
ContactGroupsManager.base_url + "/" + contactgroup_name, ContactGroupsManager.base_url + "/" + contactgroup_name,
'DELETE', 'DELETE'
body=''
) )
return body return body

View File

@ -22,7 +22,7 @@ class ContactsManager(surveil_manager.SurveilManager):
"""Get a list of contacts.""" """Get a list of contacts."""
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ContactsManager.base_url, 'POST', body=query ContactsManager.base_url, 'POST', data=query
) )
return body return body
@ -30,7 +30,7 @@ class ContactsManager(surveil_manager.SurveilManager):
"""Create a new contact.""" """Create a new contact."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ContactsManager.base_url, 'PUT', ContactsManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
@ -38,7 +38,7 @@ class ContactsManager(surveil_manager.SurveilManager):
"""Get a new contact.""" """Get a new contact."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ContactsManager.base_url + '/' + contact_name, 'GET', ContactsManager.base_url + '/' + contact_name, 'GET',
body='' data=''
) )
return body return body
@ -46,7 +46,7 @@ class ContactsManager(surveil_manager.SurveilManager):
"""Update a contact.""" """Update a contact."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ContactsManager.base_url + '/' + contact_name, 'PUT', ContactsManager.base_url + '/' + contact_name, 'PUT',
body=contact data=contact
) )
return body return body
@ -54,7 +54,6 @@ class ContactsManager(surveil_manager.SurveilManager):
"""Delete a contact.""" """Delete a contact."""
resp, body = self.http_client.request( resp, body = self.http_client.request(
ContactsManager.base_url + "/" + contact_name, ContactsManager.base_url + "/" + contact_name,
'DELETE', 'DELETE'
body=''
) )
return body return body

View File

@ -23,7 +23,7 @@ class HostGroupsManager(surveil_manager.SurveilManager):
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
HostGroupsManager.base_url, 'POST', HostGroupsManager.base_url, 'POST',
body=query data=query
) )
return body return body
@ -31,7 +31,7 @@ class HostGroupsManager(surveil_manager.SurveilManager):
"""Create a new hostgroup.""" """Create a new hostgroup."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
HostGroupsManager.base_url, 'PUT', HostGroupsManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
@ -39,7 +39,7 @@ class HostGroupsManager(surveil_manager.SurveilManager):
"""Get a new hostgroup.""" """Get a new hostgroup."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
HostGroupsManager.base_url + '/' + hostgroup_name, 'GET', HostGroupsManager.base_url + '/' + hostgroup_name, 'GET',
body='' data=''
) )
return body return body
@ -47,7 +47,7 @@ class HostGroupsManager(surveil_manager.SurveilManager):
"""Update a hostgroup.""" """Update a hostgroup."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
HostGroupsManager.base_url + '/' + hostgroup_name, 'PUT', HostGroupsManager.base_url + '/' + hostgroup_name, 'PUT',
body=hostgroup data=hostgroup
) )
return body return body
@ -55,7 +55,6 @@ class HostGroupsManager(surveil_manager.SurveilManager):
"""Delete a hostgroup.""" """Delete a hostgroup."""
resp, body = self.http_client.request( resp, body = self.http_client.request(
HostGroupsManager.base_url + "/" + hostgroup_name, HostGroupsManager.base_url + "/" + hostgroup_name,
'DELETE', 'DELETE'
body=''
) )
return body return body

View File

@ -36,7 +36,7 @@ class HostsManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
HostsManager.base_url, 'POST', HostsManager.base_url, 'POST',
body=query data=query
) )
return body return body
@ -44,7 +44,7 @@ class HostsManager(surveil_manager.SurveilManager):
"""Create a new host.""" """Create a new host."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
HostsManager.base_url, 'PUT', HostsManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
@ -52,7 +52,7 @@ class HostsManager(surveil_manager.SurveilManager):
"""Get a new host.""" """Get a new host."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
HostsManager.base_url + '/' + host_name, 'GET', HostsManager.base_url + '/' + host_name, 'GET',
body='' data=''
) )
return body return body
@ -60,14 +60,13 @@ class HostsManager(surveil_manager.SurveilManager):
"""Update a host.""" """Update a host."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
HostsManager.base_url + '/' + host_name, 'PUT', HostsManager.base_url + '/' + host_name, 'PUT',
body=host data=host
) )
return body return body
def delete(self, host_name): def delete(self, host_name):
"""Delete a host.""" """Delete a host."""
resp, body = self.http_client.request( resp, body = self.http_client.request(
HostsManager.base_url + '/' + host_name, 'DELETE', HostsManager.base_url + '/' + host_name, 'DELETE'
body=''
) )
return body return body

View File

@ -23,7 +23,7 @@ class MacroModulationsManager(surveil_manager.SurveilManager):
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
MacroModulationsManager.base_url, 'POST', MacroModulationsManager.base_url, 'POST',
body=query data=query
) )
return body return body
@ -31,7 +31,7 @@ class MacroModulationsManager(surveil_manager.SurveilManager):
"""Create a new macromodulation.""" """Create a new macromodulation."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
MacroModulationsManager.base_url, 'PUT', MacroModulationsManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
@ -40,7 +40,7 @@ class MacroModulationsManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
MacroModulationsManager.base_url + '/' + MacroModulationsManager.base_url + '/' +
macromodulation_name, 'GET', macromodulation_name, 'GET',
body='' data=''
) )
return body return body
@ -49,7 +49,7 @@ class MacroModulationsManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
MacroModulationsManager.base_url + '/' + MacroModulationsManager.base_url + '/' +
macromodulation_name, 'PUT', macromodulation_name, 'PUT',
body=macromodulation data=macromodulation
) )
return body return body
@ -57,7 +57,6 @@ class MacroModulationsManager(surveil_manager.SurveilManager):
"""Delete a macromodulation.""" """Delete a macromodulation."""
resp, body = self.http_client.request( resp, body = self.http_client.request(
MacroModulationsManager.base_url + "/" + macromodulation_name, MacroModulationsManager.base_url + "/" + macromodulation_name,
'DELETE', 'DELETE'
body=''
) )
return body return body

View File

@ -23,7 +23,7 @@ class NotificationWaysManager(surveil_manager.SurveilManager):
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
NotificationWaysManager.base_url, 'POST', NotificationWaysManager.base_url, 'POST',
body=query data=query
) )
return body return body
@ -31,7 +31,7 @@ class NotificationWaysManager(surveil_manager.SurveilManager):
"""Create a new notificationway.""" """Create a new notificationway."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
NotificationWaysManager.base_url, 'PUT', NotificationWaysManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
@ -39,8 +39,7 @@ class NotificationWaysManager(surveil_manager.SurveilManager):
"""Get a new notificationway.""" """Get a new notificationway."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
NotificationWaysManager.base_url + '/' + NotificationWaysManager.base_url + '/' +
notificationway_name, 'GET', notificationway_name, 'GET'
body=''
) )
return body return body
@ -49,7 +48,7 @@ class NotificationWaysManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
NotificationWaysManager.base_url + '/' + NotificationWaysManager.base_url + '/' +
notificationway_name, 'PUT', notificationway_name, 'PUT',
body=notificationway data=notificationway
) )
return body return body
@ -57,7 +56,6 @@ class NotificationWaysManager(surveil_manager.SurveilManager):
"""Delete a command.""" """Delete a command."""
resp, body = self.http_client.request( resp, body = self.http_client.request(
NotificationWaysManager.base_url + "/" + notificationway_name, NotificationWaysManager.base_url + "/" + notificationway_name,
'DELETE', 'DELETE'
body=''
) )
return body return body

View File

@ -23,7 +23,7 @@ class RealmsManager(surveil_manager.SurveilManager):
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
RealmsManager.base_url, 'POST', RealmsManager.base_url, 'POST',
body=query data=query
) )
return body return body
@ -31,7 +31,7 @@ class RealmsManager(surveil_manager.SurveilManager):
"""Create a new realm.""" """Create a new realm."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
RealmsManager.base_url, 'PUT', RealmsManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
@ -39,7 +39,7 @@ class RealmsManager(surveil_manager.SurveilManager):
"""Get a new realm.""" """Get a new realm."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
RealmsManager.base_url + '/' + realm_name, 'GET', RealmsManager.base_url + '/' + realm_name, 'GET',
body='' data=''
) )
return body return body
@ -47,7 +47,7 @@ class RealmsManager(surveil_manager.SurveilManager):
"""Update a realm.""" """Update a realm."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
RealmsManager.base_url + '/' + realm_name, 'PUT', RealmsManager.base_url + '/' + realm_name, 'PUT',
body=realm data=realm
) )
return body return body
@ -55,7 +55,6 @@ class RealmsManager(surveil_manager.SurveilManager):
"""Delete a realm.""" """Delete a realm."""
resp, body = self.http_client.request( resp, body = self.http_client.request(
RealmsManager.base_url + "/" + realm_name, RealmsManager.base_url + "/" + realm_name,
'DELETE', 'DELETE'
body=''
) )
return body return body

View File

@ -23,7 +23,7 @@ class ServiceGroupsManager(surveil_manager.SurveilManager):
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ServiceGroupsManager.base_url, 'POST', ServiceGroupsManager.base_url, 'POST',
body=query data=query
) )
return body return body
@ -31,15 +31,14 @@ class ServiceGroupsManager(surveil_manager.SurveilManager):
"""Create a new servicegroup.""" """Create a new servicegroup."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ServiceGroupsManager.base_url, 'PUT', ServiceGroupsManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
def get(self, servicegroup_name): def get(self, servicegroup_name):
"""Get a new servicegroup.""" """Get a new servicegroup."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ServiceGroupsManager.base_url + '/' + servicegroup_name, 'GET', ServiceGroupsManager.base_url + '/' + servicegroup_name, 'GET'
body=''
) )
return body return body
@ -47,7 +46,7 @@ class ServiceGroupsManager(surveil_manager.SurveilManager):
"""Update a servicegroup.""" """Update a servicegroup."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ServiceGroupsManager.base_url + '/' + servicegroup_name, 'PUT', ServiceGroupsManager.base_url + '/' + servicegroup_name, 'PUT',
body=servicegroup data=servicegroup
) )
return body return body
@ -55,7 +54,6 @@ class ServiceGroupsManager(surveil_manager.SurveilManager):
"""Delete a servicegroup.""" """Delete a servicegroup."""
resp, body = self.http_client.request( resp, body = self.http_client.request(
ServiceGroupsManager.base_url + "/" + servicegroup_name, ServiceGroupsManager.base_url + "/" + servicegroup_name,
'DELETE', 'DELETE'
body=''
) )
return body return body

View File

@ -36,7 +36,7 @@ class ServicesManager(surveil_manager.SurveilManager):
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ServicesManager.base_url, 'POST', ServicesManager.base_url, 'POST',
body=query data=query
) )
return body return body
@ -44,7 +44,7 @@ class ServicesManager(surveil_manager.SurveilManager):
"""Create a new host.""" """Create a new host."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ServicesManager.base_url, 'PUT', ServicesManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
@ -53,8 +53,7 @@ class ServicesManager(surveil_manager.SurveilManager):
resp, body = self.http_client.request( resp, body = self.http_client.request(
'/config/hosts' + '/' '/config/hosts' + '/'
+ host_name + '/services/' + service_description, + host_name + '/services/' + service_description,
'DELETE', 'DELETE'
body=''
) )
return body return body
@ -64,6 +63,6 @@ class ServicesManager(surveil_manager.SurveilManager):
'/config/hosts/' + host_name + '/config/hosts/' + host_name +
'/services/' + service_description, '/services/' + service_description,
'GET', 'GET',
body='' data=''
) )
return body return body

View File

@ -23,7 +23,7 @@ class TimePeriodsManager(surveil_manager.SurveilManager):
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
TimePeriodsManager.base_url, 'POST', TimePeriodsManager.base_url, 'POST',
body=query data=query
) )
return body return body
@ -31,15 +31,14 @@ class TimePeriodsManager(surveil_manager.SurveilManager):
"""Create a new timeperiod.""" """Create a new timeperiod."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
TimePeriodsManager.base_url, 'PUT', TimePeriodsManager.base_url, 'PUT',
body=kwargs data=kwargs
) )
return body return body
def get(self, timeperiod_name): def get(self, timeperiod_name):
"""Get a new timeperiod.""" """Get a new timeperiod."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
TimePeriodsManager.base_url + '/' + timeperiod_name, 'GET', TimePeriodsManager.base_url + '/' + timeperiod_name, 'GET'
body=''
) )
return body return body
@ -47,7 +46,7 @@ class TimePeriodsManager(surveil_manager.SurveilManager):
"""Update a timeperiod.""" """Update a timeperiod."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
TimePeriodsManager.base_url + '/' + timeperiod_name, 'PUT', TimePeriodsManager.base_url + '/' + timeperiod_name, 'PUT',
body=timeperiod data=timeperiod
) )
return body return body
@ -55,7 +54,6 @@ class TimePeriodsManager(surveil_manager.SurveilManager):
"""Delete a timeperiod.""" """Delete a timeperiod."""
resp, body = self.http_client.request( resp, body = self.http_client.request(
TimePeriodsManager.base_url + "/" + timeperiod_name, TimePeriodsManager.base_url + "/" + timeperiod_name,
'DELETE', 'DELETE'
body=''
) )
return body return body

View File

@ -22,6 +22,6 @@ class EventsManager(surveil_manager.SurveilManager):
"""List events.""" """List events."""
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
EventsManager.base_url, 'POST', body=query EventsManager.base_url, 'POST', data=query
) )
return body return body

View File

@ -27,7 +27,7 @@ class HostsManager(surveil_manager.SurveilManager):
"""Get a list of hosts.""" """Get a list of hosts."""
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
HostsManager.base_url, 'POST', body=query HostsManager.base_url, 'POST', data=query
) )
return body return body
@ -42,6 +42,6 @@ class HostsManager(surveil_manager.SurveilManager):
"""Submit a check result.""" """Submit a check result."""
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
HostsManager.base_url + '/' + host_name + '/results', 'POST', HostsManager.base_url + '/' + host_name + '/results', 'POST',
body=kwargs data=kwargs
) )
return body return body

View File

@ -34,7 +34,7 @@ class MetricsManager(surveil_manager.SurveilManager):
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
self._create_url(host_name, service_description, metric_name), self._create_url(host_name, service_description, metric_name),
'POST', body=query) 'POST', data=query)
return body return body

View File

@ -22,7 +22,7 @@ class ServicesManager(surveil_manager.SurveilManager):
"""Get a list of services.""" """Get a list of services."""
query = query or {} query = query or {}
resp, body = self.http_client.json_request( resp, body = self.http_client.json_request(
ServicesManager.base_url, 'POST', body=query ServicesManager.base_url, 'POST', data=query
) )
return body return body
@ -32,6 +32,6 @@ class ServicesManager(surveil_manager.SurveilManager):
'/status/hosts/%s/services/%s/results' % (host_name, '/status/hosts/%s/services/%s/results' % (host_name,
service_description), service_description),
'POST', 'POST',
body=kwargs data=kwargs
) )
return body return body

View File

@ -4,4 +4,4 @@ sphinx
oslosphinx oslosphinx
testrepository testrepository
mox3>=0.7.0 mox3>=0.7.0
httpretty==0.8.3 requests_mock