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):
example_result = {'hello': 'surveil'} with requests_mock.mock() as m:
httpretty.register_uri(httpretty.GET, example_result = {'hello': 'surveil'}
self.surveil_url + "/test", m.get(self.surveil_url + "/test",
body=json.dumps(example_result)) text=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,27 +11,27 @@
# 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",
service_description="someservice" service_description="someservice"
) )
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,122 +14,114 @@
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": '
'"modulation_period": "night"}]' '"LowImpactOnNight",'
'"modulation_period": "night"}]'
)
) businessimpactmodulations = (self.client.config.
businessimpactmodulations.list())
businessimpactmodulations = (self.client.config. self.assertEqual(
businessimpactmodulations.list()) businessimpactmodulations,
[{"business_impact": 1,
self.assertEqual( "business_impact_modulation_name": "LowImpactOnDay",
businessimpactmodulations, "modulation_period": "day"},
[{"business_impact": 1, {"business_impact": 1,
"business_impact_modulation_name": "LowImpactOnDay", "business_impact_modulation_name": "LowImpactOnNight",
"modulation_period": "day"}, "modulation_period": "night"}, ]
{"business_impact": 1,
"business_impact_modulation_name": "LowImpactOnNight",
"modulation_period": "night"}, ]
)
@httpretty.activate
def test_create(self):
httpretty.register_uri(
httpretty.PUT, "http://localhost:5311/v2/config/"
"businessimpactmodulations",
body='{"business_impact": 1,'
'"business_impact_modulation_name": "testtt",'
'"modulation_period": "day"}'
)
self.client.config.businessimpactmodulations.create(
business_impact=1,
business_impact_modulation_name="testtt",
modulation_period="day"
)
self.assertEqual(
json.loads(httpretty.last_request().body.decode()),
{
"business_impact": 1,
"business_impact_modulation_name": "testtt",
"modulation_period": "day"
}
)
@httpretty.activate
def test_get(self):
httpretty.register_uri(
httpretty.GET,
'http://localhost:5311/v2/config/businessimpactmodulations/'
'LowImpactOnDay',
body='{"business_impact": 1,'
'"business_impact_modulation_name": "LowImpactOnDay",'
'"modulation_period": "day"}'
)
businessimpactmodulation = (
self.client.config.businessimpactmodulations.get(
businessimpactmodulation_name='LowImpactOnDay')
) )
self.assertEqual( def test_create(self):
businessimpactmodulation, with requests_mock.mock() as m:
{"business_impact": 1, m.put("http://localhost:5311/v2/config/"
"business_impact_modulation_name": "LowImpactOnDay", "businessimpactmodulations",
"modulation_period": "day"} text='{"business_impact": 1,'
) '"business_impact_modulation_name": "testtt",'
'"modulation_period": "day"}'
)
self.client.config.businessimpactmodulations.create(
business_impact=1,
business_impact_modulation_name="testtt",
modulation_period="day"
)
self.assertEqual(
json.loads(m.last_request.body),
{
"business_impact": 1,
"business_impact_modulation_name": "testtt",
"modulation_period": "day"
}
)
def test_get(self):
with requests_mock.mock() as m:
m.get('http://localhost:5311/v2/config/businessimpactmodulations/'
'LowImpactOnDay',
text='{"business_impact": 1,'
'"business_impact_modulation_name": "LowImpactOnDay",'
'"modulation_period": "day"}'
)
businessimpactmodulation = (
self.client.config.businessimpactmodulations.get(
businessimpactmodulation_name='LowImpactOnDay')
)
self.assertEqual(
businessimpactmodulation,
{"business_impact": 1,
"business_impact_modulation_name": "LowImpactOnDay",
"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(
businessimpactmodulation_name="LowImpactOnNight", businessimpactmodulation_name="LowImpactOnNight",
businessimpactmodulation={'modulation_period': 'night'} businessimpactmodulation={'modulation_period': 'night'}
) )
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(
businessimpactmodulation_name="name_to_delete", businessimpactmodulation_name="name_to_delete",
) )
self.assertEqual( self.assertEqual(
body, body,
"body" "body"
) )

View File

@ -13,98 +13,93 @@
# 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',
check_period='test', check_period='test',
checkmodulation_name='test' checkmodulation_name='test'
) )
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_period": "test"}]' '"check_command": "test",'
) '"check_period": "test"}]'
)
self.assertEqual( self.assertEqual(
self.client.config.checkmodulations.list(), self.client.config.checkmodulations.list(),
[{"checkmodulation_name": "test", [{"checkmodulation_name": "test",
"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'
) )
self.assertEqual( self.assertEqual(
body, body,
"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"}'
) )
checkmodulation = self.client.config.checkmodulations.get( checkmodulation = self.client.config.checkmodulations.get(
checkmodulation_name='ping_night' checkmodulation_name='ping_night'
) )
self.assertEqual( self.assertEqual(
checkmodulation, checkmodulation,
{"checkmodulation_name": "ping_night", {"checkmodulation_name": "ping_night",
"check_command": "check_ping_night", "check_command": "check_ping_night",
"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',
checkmodulation={"check_command": "updated"} checkmodulation={"check_command": "updated"}
) )
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,99 +14,93 @@
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.client.config.commands.list(),
[{"command_name": "myCommand"}]
) )
self.assertEqual(
self.client.config.commands.list(),
[{"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(
command_name="new_command", command_name="new_command",
command_line="new_line" command_line="new_line"
) )
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(
command_name="command_to_show" command_name="command_to_show"
) )
self.assertEqual( self.assertEqual(
command, command,
{ {
"command_name": "command_to_show", "command_name": "command_to_show",
"command_line": "line" "command_line": "line"
} }
) )
@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(
command_name="command_to_update", command_name="command_to_update",
command={'command_line': "updated command_line"} command={'command_line': "updated command_line"}
) )
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(
command_name="command_to_delete", command_name="command_to_delete",
) )
self.assertEqual( self.assertEqual(
body, body,
"body" "body"
) )

View File

@ -14,108 +14,103 @@
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"}]'
) )
contactgroups = self.client.config.contactgroups.list() contactgroups = self.client.config.contactgroups.list()
self.assertEqual( self.assertEqual(
contactgroups, contactgroups,
[{"contactgroup_name": "novell-admins", [{"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"},
] ]
) )
@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"}'
) )
self.client.config.contactgroups.create( self.client.config.contactgroups.create(
contactgroup_name='John', contactgroup_name='John',
members="marie,bob,joe" members="marie,bob,joe"
) )
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"}'
) )
contactgroup = self.client.config.contactgroups.get( contactgroup = self.client.config.contactgroups.get(
contactgroup_name='novell-admins' contactgroup_name='novell-admins'
) )
self.assertEqual( self.assertEqual(
contactgroup, contactgroup,
{ {
'contactgroup_name': 'novell-admins', 'contactgroup_name': 'novell-admins',
'members': 'jdoe,rtobert,tzach' 'members': 'jdoe,rtobert,tzach'
} }
) )
@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(
contactgroup_name="novell-admins", contactgroup_name="novell-admins",
contactgroup={"members": "updated"} contactgroup={"members": "updated"}
) )
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(
contactgroup_name="novell-admins", contactgroup_name="novell-admins",
) )
self.assertEqual( self.assertEqual(
body, body,
"body" "body"
) )

View File

@ -14,111 +14,98 @@
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"}]'
) )
contacts = self.client.config.contacts.list() contacts = self.client.config.contacts.list()
self.assertEqual( self.assertEqual(
contacts, contacts,
[ [
{
'contact_name': 'bobby',
'email': 'bob@bob.com'
},
{
'contact_name': 'marie',
'email': 'marie@marie.com'
},
]
)
def test_create(self):
with requests_mock.mock() as m:
m.put("http://localhost:5311/v2/config/contacts",
text='{"contact_name": "John"}')
self.client.config.contacts.create(
contact_name='John'
)
self.assertEqual(
json.loads(m.last_request.body),
{
"contact_name": "John"
}
)
def test_get(self):
with requests_mock.mock() as m:
m.get('http://localhost:5311/v2/config/contacts/bobby',
text='{"contact_name": "bobby",'
'"email": "bob@bob.com"}')
contact = self.client.config.contacts.get(
contact_name='bobby'
)
self.assertEqual(
contact,
{ {
'contact_name': 'bobby', 'contact_name': 'bobby',
'email': 'bob@bob.com' 'email': 'bob@bob.com'
}, }
{ )
'contact_name': 'marie',
'email': 'marie@marie.com'
},
]
)
@httpretty.activate
def test_create(self):
httpretty.register_uri(
httpretty.PUT, "http://localhost:5311/v2/config/contacts",
body='{"contact_name": "John"}'
)
self.client.config.contacts.create(
contact_name='John'
)
self.assertEqual(
json.loads(httpretty.last_request().body.decode()),
{
"contact_name": "John"
}
)
@httpretty.activate
def test_get(self):
httpretty.register_uri(
httpretty.GET,
'http://localhost:5311/v2/config/contacts/bobby',
body='{"contact_name": "bobby",'
'"email": "bob@bob.com"}'
)
contact = self.client.config.contacts.get(
contact_name='bobby'
)
self.assertEqual(
contact,
{
'contact_name': 'bobby',
'email': 'bob@bob.com'
}
)
@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",
contact={"email": "updated"} contact={"email": "updated"}
) )
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",
) )
self.assertEqual( self.assertEqual(
body, body,
"body" "body"
) )

View File

@ -14,113 +14,101 @@
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"}]'
) )
hostgroups = self.client.config.hostgroups.list() hostgroups = self.client.config.hostgroups.list()
self.assertEqual( self.assertEqual(
hostgroups, hostgroups,
[ [
{
'hostgroup_name': 'novell-servers',
'members': 'netware1,netware2,netware3,netware4',
},
{
'hostgroup_name': 'otherservers',
'members': 'googul,sfl',
},
]
)
def test_create(self):
with requests_mock.mock() as m:
m.put("http://localhost:5311/v2/config/hostgroups",
text='{"hostgroup_name": "John",'
'"members": "marie,bob,joe"}')
self.client.config.hostgroups.create(
hostgroup_name='John',
members="marie,bob,joe"
)
self.assertEqual(
json.loads(m.last_request.body),
{
"hostgroup_name": "John",
"members": "marie,bob,joe"
}
)
def test_get(self):
with requests_mock.mock() as m:
m.get('http://localhost:5311/v2/config/hostgroups/novell-servers',
text='{"hostgroup_name": "novell-servers",'
'"members": "netware1,netware2,netware3,netware4"}')
hostgroup = self.client.config.hostgroups.get(
hostgroup_name='novell-servers'
)
self.assertEqual(
hostgroup,
{ {
'hostgroup_name': 'novell-servers', 'hostgroup_name': 'novell-servers',
'members': 'netware1,netware2,netware3,netware4', 'members': 'netware1,netware2,netware3,netware4'
}, }
{ )
'hostgroup_name': 'otherservers',
'members': 'googul,sfl',
},
]
)
@httpretty.activate
def test_create(self):
httpretty.register_uri(
httpretty.PUT, "http://localhost:5311/v2/config/hostgroups",
body='{"hostgroup_name": "John",'
'"members": "marie,bob,joe"}'
)
self.client.config.hostgroups.create(
hostgroup_name='John',
members="marie,bob,joe"
)
self.assertEqual(
json.loads(httpretty.last_request().body.decode()),
{
"hostgroup_name": "John",
"members": "marie,bob,joe"
}
)
@httpretty.activate
def test_get(self):
httpretty.register_uri(
httpretty.GET,
'http://localhost:5311/v2/config/hostgroups/novell-servers',
body='{"hostgroup_name": "novell-servers",'
'"members": "netware1,netware2,netware3,netware4"}'
)
hostgroup = self.client.config.hostgroups.get(
hostgroup_name='novell-servers'
)
self.assertEqual(
hostgroup,
{
'hostgroup_name': 'novell-servers',
'members': 'netware1,netware2,netware3,netware4'
}
)
@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",
hostgroup={"members": "updated"} hostgroup={"members": "updated"}
) )
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",
) )
self.assertEqual( self.assertEqual(
body, body,
"body" "body"
) )

View File

@ -14,120 +14,106 @@
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()
self.assertEqual( self.assertEqual(
hosts, hosts,
[{u"host_name": u"host1"}] [{u"host_name": u"host1"}]
) )
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",
address="192.168.2.1" address="192.168.2.1"
) )
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"
) )
self.assertEqual( self.assertEqual(
host, host,
{"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",
host={'address': "192.168.0.1", host={'address': "192.168.0.1",
'check_period': "24x7" 'check_period': "24x7"
} }
) )
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",
) )
self.assertEqual( self.assertEqual(
body, body,
"body" "body"
) )

View File

@ -14,121 +14,110 @@
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()
self.assertEqual( self.assertEqual(
contacts, contacts,
[ [
{
'macromodulation_name': 'HighDuringNight',
'modulation_period': 'night',
'_CRITICAL': 20,
'_WARNING': 10,
},
{
'macromodulation_name': 'LowDuringNight',
'modulation_period': 'night',
'_CRITICAL': 10,
'_WARNING': 20,
}
]
)
def test_create(self):
with requests_mock.mock() as m:
m.put("http://localhost:5311/v2/config/macromodulations",
text='{"macromodulation_name": "TEST_CREATE_MODULATION",'
'"modulation_period": "night"}')
self.client.config.macromodulations.create(
macromodulation_name='TEST_CREATE_MODULATION',
modulation_period='night'
)
self.assertEqual(
json.loads(m.last_request.body),
{
"macromodulation_name": "TEST_CREATE_MODULATION",
"modulation_period": "night"
}
)
def test_get(self):
with requests_mock.mock() as m:
m.get('http://localhost:5311/v2/config/'
'macromodulations/HighDuringNight',
text='{"macromodulation_name": "HighDuringNight",'
'"modulation_period": "night"}')
macromodulation = self.client.config.macromodulations.get(
macromodulation_name='HighDuringNight'
)
self.assertEqual(
macromodulation,
{ {
'macromodulation_name': 'HighDuringNight', 'macromodulation_name': 'HighDuringNight',
'modulation_period': 'night', 'modulation_period': 'night'
'_CRITICAL': 20,
'_WARNING': 10,
},
{
'macromodulation_name': 'LowDuringNight',
'modulation_period': 'night',
'_CRITICAL': 10,
'_WARNING': 20,
} }
] )
)
@httpretty.activate
def test_create(self):
httpretty.register_uri(
httpretty.PUT, "http://localhost:5311/v2/config/macromodulations",
body='{"macromodulation_name": "TEST_CREATE_MODULATION",'
'"modulation_period": "night"}'
)
self.client.config.macromodulations.create(
macromodulation_name='TEST_CREATE_MODULATION',
modulation_period='night'
)
self.assertEqual(
json.loads(httpretty.last_request().body.decode()),
{
"macromodulation_name": "TEST_CREATE_MODULATION",
"modulation_period": "night"
}
)
@httpretty.activate
def test_get(self):
httpretty.register_uri(
httpretty.GET,
'http://localhost:5311/v2/config/macromodulations/HighDuringNight',
body='{"macromodulation_name": "HighDuringNight",'
'"modulation_period": "night"}'
)
macromodulation = self.client.config.macromodulations.get(
macromodulation_name='HighDuringNight'
)
self.assertEqual(
macromodulation,
{
'macromodulation_name': 'HighDuringNight',
'modulation_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/'
'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",
macromodulation={"modulation_period": "updated"} macromodulation={"modulation_period": "updated"}
) )
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",
) )
self.assertEqual( self.assertEqual(
body, body,
"body" "body"
) )

View File

@ -14,52 +14,123 @@
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",'
'"host_notification_options": "d,u",' '"host_notification_options": "d,u",'
'"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"'
'},' '},'
'{' '{'
'"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",'
'"host_notification_options": "d,r,f,u",' '"host_notification_options": "d,r,f,u",'
'"service_notification_options": "w,f,c,r",' '"service_notification_options": "w,f,c,r",'
'"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'
'}' '}'
']' ']')
)
notificationways = self.client.config.notificationways.list() notificationways = self.client.config.notificationways.list()
self.assertEqual( self.assertEqual(
notificationways, notificationways,
[ [
{
'notificationway_name': 'email_in_day',
'host_notification_period': '24x7',
'service_notification_period': '24x7',
'host_notification_options': 'd,u',
'service_notification_options': 'w,c,r',
'host_notification_commands': 'notify-service',
'service_notification_commands': 'notify-host'
},
{
'notificationway_name': 'email_all_time',
'host_notification_period': '24x7',
'service_notification_period': '24x7',
'host_notification_options': 'd,r,f,u',
'service_notification_options': 'w,f,c,r',
'host_notification_commands': 'notify-service',
'service_notification_commands': 'notify-host',
'min_business_impact': 5
}
]
)
def test_create(self):
with requests_mock.mock() as m:
m.put("http://localhost:5311/v2/config/notificationways",
text='{'
'"notificationway_name": "email_in_day",'
'"host_notification_period": "24x7",'
'"service_notification_period": "24x7",'
'"host_notification_options": "d,u",'
'"service_notification_options": "w,c,r",'
'"host_notification_commands": "notify-service",'
'"service_notification_commands": "notify-host"'
'}')
self.client.config.notificationways.create(
notificationway_name='test_create_notification',
host_notification_period='24x7',
service_notification_period='24x7',
host_notification_options='d,r,f,u',
service_notification_options='w,f,c,r',
host_notification_commands='notify-service',
service_notification_commands='notify-host',
min_business_impact=5
)
self.assertEqual(
json.loads(m.last_request.body),
{ {
'notificationway_name': 'email_in_day', 'notificationway_name': 'test_create_notification',
'host_notification_period': '24x7', 'host_notification_period': '24x7',
'service_notification_period': '24x7', 'service_notification_period': '24x7',
'host_notification_options': 'd,u', 'host_notification_options': 'd,r,f,u',
'service_notification_options': 'w,c,r', 'service_notification_options': 'w,f,c,r',
'host_notification_commands': 'notify-service', 'host_notification_commands': 'notify-service',
'service_notification_commands': 'notify-host' 'service_notification_commands': 'notify-host',
}, 'min_business_impact': 5
}
)
def test_get(self):
with requests_mock.mock() as m:
m.get('http://localhost:5311/v2/config/'
'notificationways/email_all_time',
text='{'
'"notificationway_name": "email_all_time",'
'"host_notification_period": "24x7",'
'"service_notification_period": "24x7",'
'"host_notification_options": "d,r,f,u",'
'"service_notification_options": "w,f,c,r",'
'"host_notification_commands": "notify-service",'
'"service_notification_commands": "notify-host",'
'"min_business_impact": 5'
'}')
notificationway = self.client.config.notificationways.get(
notificationway_name='email_all_time'
)
self.assertEqual(
notificationway,
{ {
'notificationway_name': 'email_all_time', 'notificationway_name': 'email_all_time',
'host_notification_period': '24x7', 'host_notification_period': '24x7',
@ -70,118 +141,36 @@ class TestNotificationWays(clienttest.ClientTest):
'service_notification_commands': 'notify-host', 'service_notification_commands': 'notify-host',
'min_business_impact': 5 'min_business_impact': 5
} }
] )
)
@httpretty.activate
def test_create(self):
httpretty.register_uri(
httpretty.PUT, "http://localhost:5311/v2/config/notificationways",
body='{'
'"notificationway_name": "email_in_day",'
'"host_notification_period": "24x7",'
'"service_notification_period": "24x7",'
'"host_notification_options": "d,u",'
'"service_notification_options": "w,c,r",'
'"host_notification_commands": "notify-service",'
'"service_notification_commands": "notify-host"'
'}'
)
self.client.config.notificationways.create(
notificationway_name='test_create_notification',
host_notification_period='24x7',
service_notification_period='24x7',
host_notification_options='d,r,f,u',
service_notification_options='w,f,c,r',
host_notification_commands='notify-service',
service_notification_commands='notify-host',
min_business_impact=5
)
self.assertEqual(
json.loads(httpretty.last_request().body.decode()),
{
'notificationway_name': 'test_create_notification',
'host_notification_period': '24x7',
'service_notification_period': '24x7',
'host_notification_options': 'd,r,f,u',
'service_notification_options': 'w,f,c,r',
'host_notification_commands': 'notify-service',
'service_notification_commands': 'notify-host',
'min_business_impact': 5
}
)
@httpretty.activate
def test_get(self):
httpretty.register_uri(
httpretty.GET,
'http://localhost:5311/v2/config/notificationways/email_all_time',
body='{'
'"notificationway_name": "email_all_time",'
'"host_notification_period": "24x7",'
'"service_notification_period": "24x7",'
'"host_notification_options": "d,r,f,u",'
'"service_notification_options": "w,f,c,r",'
'"host_notification_commands": "notify-service",'
'"service_notification_commands": "notify-host",'
'"min_business_impact": 5'
'}'
)
notificationway = self.client.config.notificationways.get(
notificationway_name='email_all_time'
)
self.assertEqual(
notificationway,
{
'notificationway_name': 'email_all_time',
'host_notification_period': '24x7',
'service_notification_period': '24x7',
'host_notification_options': 'd,r,f,u',
'service_notification_options': 'w,f,c,r',
'host_notification_commands': 'notify-service',
'service_notification_commands': 'notify-host',
'min_business_impact': 5
}
)
@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",
notificationway={"host_notification_period": "updated"} notificationway={"host_notification_period": "updated"}
) )
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",
) )
self.assertEqual( self.assertEqual(
body, body,
"body" "body"
) )

View File

@ -14,131 +14,118 @@
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",'
'"default": 0' '"default": 0'
'},' '},'
'{' '{'
'"realm_name": "Anti-world",' '"realm_name": "Anti-world",'
'"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()
self.assertEqual( self.assertEqual(
realms, realms,
[ [
{
'realm_name': 'World',
'realm_members': 'Europe,America,Asia',
'default': 0
},
{
'realm_name': 'Anti-world',
'realm_members': 'void,black-hole',
'default': 1
},
]
)
def test_create(self):
with requests_mock.mock() as m:
m.put("http://localhost:5311/v2/config/realms",
text='{"realm_name": "John",'
'"realm_members":"marie,bob,joe",'
'"default":1}')
self.client.config.realms.create(
realm_name='John',
realm_members="marie,bob,joe",
default=1
)
self.assertEqual(
json.loads(m.last_request.body),
{
"realm_name": "John",
"realm_members": "marie,bob,joe",
"default": 1
}
)
def test_get(self):
with requests_mock.mock() as m:
m.get('http://localhost:5311/v2/config/realms/bobby',
text='{'
'"realm_name": "World",'
'"realm_members": "Europe,America,Asia",'
'"default": 0'
'}')
realm = self.client.config.realms.get(
realm_name='bobby'
)
self.assertEqual(
realm,
{ {
'realm_name': 'World', 'realm_name': 'World',
'realm_members': 'Europe,America,Asia', 'realm_members': 'Europe,America,Asia',
'default': 0 'default': 0
}, }
{ )
'realm_name': 'Anti-world',
'realm_members': 'void,black-hole',
'default': 1
},
]
)
@httpretty.activate
def test_create(self):
httpretty.register_uri(
httpretty.PUT, "http://localhost:5311/v2/config/realms",
body='{"realm_name": "John",'
'"realm_members":"marie,bob,joe",'
'"default":1}'
)
self.client.config.realms.create(
realm_name='John',
realm_members="marie,bob,joe",
default=1
)
self.assertEqual(
json.loads(httpretty.last_request().body.decode()),
{
"realm_name": "John",
"realm_members": "marie,bob,joe",
"default": 1
}
)
@httpretty.activate
def test_get(self):
httpretty.register_uri(
httpretty.GET,
'http://localhost:5311/v2/config/realms/bobby',
body='{'
'"realm_name": "World",'
'"realm_members": "Europe,America,Asia",'
'"default": 0'
'}'
)
realm = self.client.config.realms.get(
realm_name='bobby'
)
self.assertEqual(
realm,
{
'realm_name': 'World',
'realm_members': 'Europe,America,Asia',
'default': 0
}
)
@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",
realm={"realm_members": "updated"} realm={"realm_members": "updated"}
) )
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",
) )
self.assertEqual( self.assertEqual(
body, body,
"body" "body"
) )

View File

@ -14,116 +14,105 @@
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()
self.assertEqual( self.assertEqual(
servicegroups, servicegroups,
[ [
{
'servicegroup_name': 'dbservices',
'members': 'ms1,SQL Server,ms1,'
'SQL Serverc Agent,ms1,SQL DTC',
},
{
'servicegroup_name': 'otherservices',
'members': 'some,other,member',
},
]
)
def test_create(self):
with requests_mock.mock() as m:
m.put("http://localhost:5311/v2/config/servicegroups",
text='{"servicegroup_name": "John",'
'"members": "marie,bob,joe"}')
self.client.config.servicegroups.create(
servicegroup_name='John',
members="marie,bob,joe"
)
self.assertEqual(
json.loads(m.last_request.body),
{
"servicegroup_name": "John",
"members": "marie,bob,joe"
}
)
def test_get(self):
with requests_mock.mock() as m:
m.get('http://localhost:5311/v2/config/servicegroups/dbservices',
text='{"servicegroup_name": "dbservices",'
'"members": "ms1,SQL Server,ms1,'
'SQL Serverc Agent,ms1,SQL DTC"}')
servicegroup = self.client.config.servicegroups.get(
servicegroup_name='dbservices'
)
self.assertEqual(
servicegroup,
{ {
'servicegroup_name': 'dbservices', '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',
'members': 'some,other,member',
},
]
)
@httpretty.activate
def test_create(self):
httpretty.register_uri(
httpretty.PUT, "http://localhost:5311/v2/config/servicegroups",
body='{"servicegroup_name": "John",'
'"members": "marie,bob,joe"}'
)
self.client.config.servicegroups.create(
servicegroup_name='John',
members="marie,bob,joe"
)
self.assertEqual(
json.loads(httpretty.last_request().body.decode()),
{
"servicegroup_name": "John",
"members": "marie,bob,joe"
}
)
@httpretty.activate
def test_get(self):
httpretty.register_uri(
httpretty.GET,
'http://localhost:5311/v2/config/servicegroups/dbservices',
body='{"servicegroup_name": "dbservices",'
'"members": "ms1,SQL Server,ms1,'
'SQL Serverc Agent,ms1,SQL DTC"}'
)
servicegroup = self.client.config.servicegroups.get(
servicegroup_name='dbservices'
)
self.assertEqual(
servicegroup,
{
'servicegroup_name': 'dbservices',
'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",
servicegroup={"members": "updated"} servicegroup={"members": "updated"}
) )
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",
) )
self.assertEqual( self.assertEqual(
body, body,
"body" "body"
) )

View File

@ -14,96 +14,84 @@
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()
self.assertEqual( self.assertEqual(
services, services,
[{"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", text="body")
body="body"
)
body = self.client.config.services.delete( body = self.client.config.services.delete(
host_name="host_name", host_name="host_name",
service_description="service_description" service_description="service_description"
) )
self.assertEqual( self.assertEqual(
body, body,
"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", text="{}")
body="{}"
)
body = self.client.config.services.get( body = self.client.config.services.get(
host_name="host_name", host_name="host_name",
service_description="service_description" service_description="service_description"
) )
self.assertEqual( self.assertEqual(
body, body,
{} {}
) )

View File

@ -14,126 +14,112 @@
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",'
'"monday": "00:00-09:00,17:00-24:00"' '"monday": "00:00-09:00,17:00-24:00"'
'},' '},'
'{' '{'
'"timeperiod_name": "misc-single-days",' '"timeperiod_name": "misc-single-days",'
'"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() self.assertEqual(
timeperiods,
[
{
'timeperiod_name': 'nonworkhours',
'sunday': '00:00-24:00',
'monday': '00:00-09:00,17:00-24:00'
},
{
'timeperiod_name': 'misc-single-days',
'1999-01-28': '00:00-24:00',
'day 2': '00:00-24:00',
},
]
self.assertEqual( )
timeperiods,
[ def test_create(self):
with requests_mock.mock() as m:
m.put("http://localhost:5311/v2/config/timeperiods",
text='{"timeperiod_name": "John"}')
self.client.config.timeperiods.create(
timeperiod_name='new_periods'
)
self.assertEqual(
json.loads(m.last_request.body),
{
"timeperiod_name": "new_periods"
}
)
def test_get(self):
with requests_mock.mock() as m:
m.get('http://localhost:5311/v2/config/timeperiods/nonworkhours',
text='{'
'"timeperiod_name": "nonworkhours",'
'"sunday": "00:00-24:00",'
'"monday": "00:00-09:00,17:00-24:00"'
'}')
timeperiod = self.client.config.timeperiods.get(
timeperiod_name='nonworkhours'
)
self.assertEqual(
timeperiod,
{ {
'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_name': 'misc-single-days',
'1999-01-28': '00:00-24:00',
'day 2': '00:00-24:00',
},
]
)
@httpretty.activate
def test_create(self):
httpretty.register_uri(
httpretty.PUT, "http://localhost:5311/v2/config/timeperiods",
body='{"timeperiod_name": "John"}'
)
self.client.config.timeperiods.create(
timeperiod_name='new_periods'
)
self.assertEqual(
json.loads(httpretty.last_request().body.decode()),
{
"timeperiod_name": "new_periods"
}
)
@httpretty.activate
def test_get(self):
httpretty.register_uri(
httpretty.GET,
'http://localhost:5311/v2/config/timeperiods/nonworkhours',
body='{'
'"timeperiod_name": "nonworkhours",'
'"sunday": "00:00-24:00",'
'"monday": "00:00-09:00,17:00-24:00"'
'}'
)
timeperiod = self.client.config.timeperiods.get(
timeperiod_name='nonworkhours'
)
self.assertEqual(
timeperiod,
{
'timeperiod_name': 'nonworkhours',
'sunday': '00:00-24:00',
'monday': '00:00-09:00,17:00-24:00'
}
)
@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",
timeperiod={"timeperiod_name": "updated"} timeperiod={"timeperiod_name": "updated"}
) )
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",
) )
self.assertEqual( self.assertEqual(
body, body,
"body" "body"
) )

View File

@ -12,28 +12,28 @@
# 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", '
'"event_type": "ALERT", "output": "Ok"},' '"service_description": "cpu", '
'{"host_name": "sfl.com", "service_description": "cpu", ' '"event_type": "ALERT", "output": "Ok"},'
'"event_type": "ALERT", "output": "Not Ok"}]' '{"host_name": "sfl.com", '
) '"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(
events, events,
[{"host_name": "sfl.com", "service_description": "cpu", [{"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", "service_description": "cpu",
"event_type": "ALERT", "output": "Not Ok"}] "event_type": "ALERT", "output": "Not Ok"}]
) )

View File

@ -14,54 +14,48 @@
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()
self.assertEqual( self.assertEqual(
hosts, hosts,
[{"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")
self.assertEqual( self.assertEqual(
host, host,
{"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,101 +12,99 @@
# 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"}]'
) )
metrics = self.client.status.hosts.metrics.list( metrics = self.client.status.hosts.metrics.list(
'localhost', 'localhost',
'load1' 'load1'
) )
self.assertEqual( self.assertEqual(
metrics, metrics,
[{"min": "2", "warning": "15", "value": "3"}, [{"min": "2", "warning": "15", "value": "3"},
{"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"}]'
) )
live_query = ('{"time_interval": { "start_time": ' live_query = ('{"time_interval": { "start_time": '
'"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',
'load', 'load1',
query=live_query 'load',
) query=live_query
)
self.assertEqual( self.assertEqual(
metrics, metrics,
[{"min": "2", "warning": "15", "value": "3"}, [{"min": "2", "warning": "15", "value": "3"},
{"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',
'load') 'load1',
'load')
self.assertEqual( self.assertEqual(
metrics, metrics,
{"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(
'localhost', 'localhost',
service_description='load') service_description='load')
self.assertEqual( self.assertEqual(
metrics, metrics,
[{"metric_name": "load1"}, {"metric_name": "load5"}] [{"metric_name": "load1"}, {"metric_name": "load5"}]
) )

View File

@ -14,43 +14,38 @@
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()
self.assertEqual( self.assertEqual(
services, services,
[{"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,16 +49,15 @@ 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
def delete(self, businessimpactmodulation_name): def delete(self, businessimpactmodulation_name):
"""Delete a businessimpactmodulation.""" """Delete a businessimpactmodulation."""
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