Skip to content

Commit 7ed6005

Browse files
author
Frederick Ross
committed
Resolve comments from Itay.
Made a comment more understandable. Added tests for Entity._proper_namespace.
1 parent 9b6e2a2 commit 7ed6005

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

splunklib/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ def _load_atom_entries(response):
193193
entries = r.feed.get('entry', None)
194194
if entries is None: return None
195195
return entries if isinstance(entries, list) else [entries]
196-
# The jobs endpoint doesn't returns a bare <entry> element
197-
# instead of an <entry> element inside a <feed> element.
196+
# Unlike most other endpoints, the jobs endpoint does not return
197+
# its state wrapped in another element, but at the top level.
198+
# For example, in XML, it returns <entry>...</entry> instead of
199+
# <feed><entry>...</entry></feed>.
198200
else:
199201
entries = r.get('entry', None)
200202
if entries is None: return None

tests/test_service.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,33 @@ def test_trailing_with_one_arg_works(self):
150150
self.assertEqual('boris/search/another/path/segment/that runs on', client._trailing(self.template, 'ervicesNS/'))
151151

152152
def test_trailing_with_n_args_works(self):
153-
self.assertEqual('another/path/segment/that runs on', client._trailing(self.template, 'servicesNS/', '/', '/'))
154-
153+
self.assertEqual(
154+
'another/path/segment/that runs on',
155+
client._trailing(self.template, 'servicesNS/', '/', '/')
156+
)
157+
158+
class TestEntityNamespacing(testlib.SDKTestCase):
159+
def test_proper_namespace_with_arguments(self):
160+
entity = self.service.apps['search']
161+
self.assertEquals((None,None,"global"), entity._proper_namespace(sharing="global"))
162+
self.assertEquals((None,"search","app"), entity._proper_namespace(sharing="app", app="search"))
163+
self.assertEquals(
164+
("admin", "search", "user"),
165+
entity._proper_namespace(sharing="user", app="search", owner="admin")
166+
)
167+
168+
def test_proper_namespace_with_entity_namespace(self):
169+
entity = self.service.apps['search']
170+
namespace = (entity.access.owner, entity.access.app, entity.access.sharing)
171+
self.assertEquals(namespace, entity._proper_namespace())
172+
173+
def test_proper_namespace_with_service_namespace(self):
174+
entity = client.Entity(self.service, client.PATH_APPS + "search")
175+
del entity._state['access']
176+
namespace = (self.service.namespace.owner,
177+
self.service.namespace.app,
178+
self.service.namespace.sharing)
179+
self.assertEquals(namespace, entity._proper_namespace())
155180

156181
if __name__ == "__main__":
157182
try:

0 commit comments

Comments
 (0)