Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get/post definitions #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions pyrabbit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class Client(object):
'vhost_permissions': 'permissions/%s/%s',
'users_by_name': 'users/%s',
'user_permissions': 'users/%s/permissions',
'vhost_permissions_get': 'vhosts/%s/permissions'
}
'vhost_permissions_get': 'vhosts/%s/permissions',
'definitions': 'definitions'}

json_headers = {"content-type": "application/json"}

Expand Down Expand Up @@ -799,3 +799,23 @@ def delete_user(self, username):
"""
path = Client.urls['users_by_name'] % username
return self._call(path, 'DELETE')


def get_definitions(self):
"""
Get definitions
"""
path = Client.urls['definitions']
definitions = self.http.do_call(path, 'GET')
return definitions


def set_definitions(self, definitions):
"""
Set definitions
"""
body = json.dumps(definitions)
path = Client.urls['definitions']
definitions = self.http.do_call(path, 'POST', body,
headers=Client.json_headers)
return definitions
5 changes: 5 additions & 0 deletions tests/test_pyrabbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pyrabbit
from mock import Mock, patch


class TestClient(unittest.TestCase):
def setUp(self):
self.client = pyrabbit.api.Client('localhost:55672/api', 'guest', 'guest')
Expand Down Expand Up @@ -78,6 +79,10 @@ def test_get_named_exchange(self):
def test_get_users(self):
with patch('pyrabbit.http.HTTPClient.do_call') as do_call:
self.assertTrue(self.client.get_users())

def test_get_definitions(self):
with patch('pyrabbit.http.HTTPClient.do_call') as do_call:
self.assertTrue(self.client.get_definitions())

def test_get_queue_depth(self):
q = {'messages': 4}
Expand Down