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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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