|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# Copyright 2011-2012 Splunk, Inc. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"): you may |
| 6 | +# not use this file except in compliance with the License. You may obtain |
| 7 | +# a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | +# License for the specific language governing permissions and limitations |
| 15 | +# under the License. |
| 16 | + |
| 17 | +import splunklib.client as client |
| 18 | + |
| 19 | +import testlib |
| 20 | + |
| 21 | +class TestCase(testlib.TestCase): |
| 22 | + def check_app(self, app): |
| 23 | + app.name |
| 24 | + app.path |
| 25 | + app.content |
| 26 | + app.metadata |
| 27 | + |
| 28 | + def test_read(self): |
| 29 | + service = client.connect(**self.opts.kwargs) |
| 30 | + |
| 31 | + for app in service.apps: |
| 32 | + self.check_app(app) |
| 33 | + app.refresh() |
| 34 | + self.check_app(app) |
| 35 | + |
| 36 | + def test_crud(self): |
| 37 | + service = client.connect(**self.opts.kwargs) |
| 38 | + |
| 39 | + appname = "sdk-test-app" |
| 40 | + |
| 41 | + testlib.delete_app(service, appname) |
| 42 | + self.assertFalse(appname in service.apps) |
| 43 | + |
| 44 | + kwargs = { |
| 45 | + 'author': "Me", |
| 46 | + 'description': "Test app description", |
| 47 | + 'label': "SDK Test", |
| 48 | + 'manageable': False, |
| 49 | + 'template': "barebones", |
| 50 | + 'visible': True, |
| 51 | + } |
| 52 | + service.apps.create(appname, **kwargs) |
| 53 | + self.assertTrue(appname in service.apps) |
| 54 | + app = service.apps[appname] |
| 55 | + self.assertEqual(app['author'], "Me") |
| 56 | + self.assertEqual(app['label'], "SDK Test") |
| 57 | + self.assertEqual(app['manageable'], "0") |
| 58 | + self.assertEqual(app['visible'], "1") |
| 59 | + |
| 60 | + kwargs = { |
| 61 | + 'author': "SDK", |
| 62 | + 'visible': False, |
| 63 | + } |
| 64 | + app = service.apps[appname] |
| 65 | + app.update(**kwargs) |
| 66 | + app.refresh() |
| 67 | + self.assertEqual(app['author'], "SDK") |
| 68 | + self.assertEqual(app['label'], "SDK Test") |
| 69 | + self.assertEqual(app['manageable'], "0") |
| 70 | + self.assertEqual(app['visible'], "0") |
| 71 | + |
| 72 | + testlib.delete_app(service, appname) |
| 73 | + self.assertFalse(appname in service.apps) |
| 74 | + |
| 75 | +if __name__ == "__main__": |
| 76 | + testlib.main() |
0 commit comments