Skip to content

Commit 1ca24bf

Browse files
author
Frederick Ross
committed
Renamed clearRestartMessage and installAppFromCollection with underscores.
Add fake_splunk_version context manager.
1 parent b26b3dc commit 1ca24bf

File tree

7 files changed

+26
-11
lines changed

7 files changed

+26
-11
lines changed

tests/test_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def tearDown(self):
5050
if app_name.startswith('delete-me'):
5151
self.service.apps.delete(app_name)
5252
self.assertEventuallyTrue(lambda: app_name not in self.service.apps)
53-
self.clearRestartMessage()
53+
self.clear_restart_message()
5454

5555
def test_app_integrity(self):
5656
self.check_entity(self.app)
@@ -86,7 +86,7 @@ def test_delete(self):
8686
self.assertTrue(name in self.service.apps)
8787
self.service.apps.delete(name)
8888
self.assertFalse(name in self.service.apps)
89-
self.clearRestartMessage() # We don't actually have to restart here.
89+
self.clear_restart_message() # We don't actually have to restart here.
9090

9191
def test_package(self):
9292
p = self.app.package()

tests/test_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_submit_via_attached_socket(self):
108108
self.assertEventuallyTrue(lambda: self.totalEventCount() == eventCount+1, timeout=60)
109109

110110
def test_upload(self):
111-
self.installAppFromCollection("file_to_upload")
111+
self.install_app_from_collection("file_to_upload")
112112

113113
eventCount = int(self.index['totalEventCount'])
114114

tests/test_input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_inputs_list_on_one_kind_with_search(self):
5959
self.assertEqual(expected, found)
6060

6161
def test_oneshot(self):
62-
self.installAppFromCollection('file_to_upload')
62+
self.install_app_from_collection('file_to_upload')
6363

6464
index_name = testlib.tmpname()
6565
index = self.service.indexes.create(index_name)
@@ -124,7 +124,7 @@ def test_lists_modular_inputs(self):
124124
else:
125125
# Install modular inputs to list, and restart
126126
# so they'll show up.
127-
self.installAppFromCollection("modular-inputs")
127+
self.install_app_from_collection("modular-inputs")
128128
self.uncheckedRestartSplunk()
129129

130130
inputs = self.service.inputs

tests/test_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_read_jobs(self):
114114
class TestJobWithDelayedDone(testlib.SDKTestCase):
115115
def setUp(self):
116116
super(TestJobWithDelayedDone, self).setUp()
117-
self.installAppFromCollection("sleep_command")
117+
self.install_app_from_collection("sleep_command")
118118
self.query = "search index=_internal | sleep done=100"
119119
self.job = self.service.jobs.create(
120120
query=self.query,

tests/test_modular_input_kinds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class ModularInputKindTestCase(testlib.SDKTestCase):
2121
def setUp(self):
2222
super(ModularInputKindTestCase, self).setUp()
23-
self.installAppFromCollection("modular-inputs")
23+
self.install_app_from_collection("modular-inputs")
2424
self.uncheckedRestartSplunk()
2525

2626
def test_list_arguments(self):

tests/test_service.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ def test_splunk_version(self):
101101
for p in v:
102102
self.assertTrue(isinstance(p, int) and p >= 0)
103103

104+
for version in [(4,3,3), (5,), (5,0,1)]:
105+
with self.fake_splunk_version(version):
106+
self.assertEqual(version, self.service.splunk_version)
107+
104108
class TestSettings(testlib.SDKTestCase):
105109
def test_read_settings(self):
106110
settings = self.service.settings

tests/testlib.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# under the License.
1616

1717
"""Shared unit test utilities."""
18+
import contextlib
1819

1920
import sys
2021
# Run the test suite on the SDK without installing it.
@@ -125,7 +126,7 @@ def check_entity(self, entity):
125126
continue
126127
raise
127128

128-
def clearRestartMessage(self):
129+
def clear_restart_message(self):
129130
"""Tell Splunk to forget that it needs to be restarted.
130131
131132
This is used mostly in cases such as deleting a temporary application.
@@ -142,7 +143,17 @@ def clearRestartMessage(self):
142143
else:
143144
raise
144145

145-
def installAppFromCollection(self, name):
146+
@contextlib.contextmanager
147+
def fake_splunk_version(self, version):
148+
original_version = self.service.splunk_version
149+
try:
150+
self.service._splunk_version = version
151+
yield
152+
finally:
153+
self.service._splunk_version = original_version
154+
155+
156+
def install_app_from_collection(self, name):
146157
collectionName = 'sdk-app-collection'
147158
if collectionName not in self.service.apps:
148159
raise ValueError("sdk-test-application not installed in splunkd")
@@ -159,7 +170,7 @@ def pathInApp(self, appName, pathComponents):
159170
"""Return a path to *pathComponents* in *appName*.
160171
161172
`pathInApp` is used to refer to files in applications installed with
162-
`installAppFromCollection`. For example, the app `file_to_upload` in
173+
`install_app_from_collection`. For example, the app `file_to_upload` in
163174
the collection contains `log.txt`. To get the path to it, call::
164175
165176
pathInApp('file_to_upload', ['log.txt'])
@@ -228,4 +239,4 @@ def tearDown(self):
228239
self.service.apps.delete(appName)
229240
wait(lambda: appName not in self.service.apps)
230241
if self.service.restart_required:
231-
self.clearRestartMessage()
242+
self.clear_restart_message()

0 commit comments

Comments
 (0)