From e099a3889eba506c9c66ed3e06eac2c2febcb75c Mon Sep 17 00:00:00 2001 From: saady Date: Thu, 20 Apr 2017 22:46:05 +0100 Subject: [PATCH] get/post definitions --- pyrabbit/api.py | 24 ++++++++++++++++++++++-- tests/test_pyrabbit.py | 5 +++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pyrabbit/api.py b/pyrabbit/api.py index 2e2b487..2ec1fdb 100644 --- a/pyrabbit/api.py +++ b/pyrabbit/api.py @@ -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"} @@ -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 diff --git a/tests/test_pyrabbit.py b/tests/test_pyrabbit.py index c064e25..0676b95 100644 --- a/tests/test_pyrabbit.py +++ b/tests/test_pyrabbit.py @@ -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') @@ -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}