forked from splunk/splunk-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app.py
More file actions
executable file
·109 lines (96 loc) · 3.74 KB
/
test_app.py
File metadata and controls
executable file
·109 lines (96 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
#
# Copyright 2011-2015 Splunk, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"): you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# 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 testlib
import logging
import splunklib.client as client
class TestApp(testlib.SDKTestCase):
app = None
app_name = None
def setUp(self):
super(TestApp, self).setUp()
if self.app is None:
for app in self.service.apps:
if app.name.startswith('delete-me'):
self.service.apps.delete(app.name)
# Creating apps takes 0.8s, which is too long to wait for
# each test in this test suite. Therefore we create one
# app and reuse it. Since apps are rather less fraught
# than entities like indexes, this is okay.
self.app_name = testlib.tmpname()
self.app = self.service.apps.create(self.app_name)
logging.debug("Creating app %s", self.app_name)
else:
logging.debug("App %s already exists. Skipping creation.", self.app_name)
if self.service.restart_required:
self.service.restart(120)
return
def tearDown(self):
super(TestApp, self).tearDown()
# The rest of this will leave Splunk in a state requiring a restart.
# It doesn't actually matter, though.
self.service = client.connect(**self.opts.kwargs)
for app in self.service.apps:
app_name = app.name
if app_name.startswith('delete-me'):
self.service.apps.delete(app_name)
self.assertEventuallyTrue(lambda: app_name not in self.service.apps)
self.clear_restart_message()
def test_app_integrity(self):
self.check_entity(self.app)
self.app.setupInfo
self.app['setupInfo']
def test_disable_enable(self):
self.app.disable()
self.app.refresh()
self.assertEqual(self.app['disabled'], '1')
self.app.enable()
self.app.refresh()
self.assertEqual(self.app['disabled'], '0')
def test_update(self):
kwargs = {
'author': "Me",
'description': "Test app description",
'label': "SDK Test",
'version': "1.2",
'visible': True,
}
self.app.update(**kwargs)
self.app.refresh()
self.assertEqual(self.app['author'], "Me")
self.assertEqual(self.app['label'], "SDK Test")
self.assertEqual(self.app['version'], "1.2")
self.assertEqual(self.app['visible'], "1")
def test_delete(self):
name = testlib.tmpname()
app = self.service.apps.create(name)
self.assertTrue(name in self.service.apps)
self.service.apps.delete(name)
self.assertFalse(name in self.service.apps)
self.clear_restart_message() # We don't actually have to restart here.
def test_package(self):
p = self.app.package()
self.assertEqual(p.name, self.app_name)
self.assertTrue(p.path.endswith(self.app_name + '.spl'))
self.assertTrue(p.url.endswith(self.app_name + '.spl'))
def test_updateInfo(self):
p = self.app.updateInfo()
self.assertTrue(p is not None)
if __name__ == "__main__":
try:
import unittest2 as unittest
except ImportError:
import unittest
unittest.main()