11from __future__ import absolute_import
22from tests import testlib
33
4+ import unittest
5+ import os
6+ import sys
7+
48try :
59 from utils import *
610except ImportError :
711 raise Exception ("Add the SDK repository to your PYTHONPATH to run the test cases "
812 "(e.g., export PYTHONPATH=~/splunk-sdk-python." )
913
10-
1114TEST_DICT = {
12- 'username' :'admin' ,
13- 'password' :'changeme' ,
14- 'port' : 8089 ,
15- 'host' : 'localhost' ,
16- 'scheme' : 'https'
17- }
15+ 'username' : 'admin' ,
16+ 'password' : 'changeme' ,
17+ 'port' : 8089 ,
18+ 'host' : 'localhost' ,
19+ 'scheme' : 'https'
20+ }
21+
1822
1923class TestUtils (testlib .SDKTestCase ):
2024 def setUp (self ):
@@ -23,16 +27,16 @@ def setUp(self):
2327 # Test dslice when a dict is passed to change key names
2428 def test_dslice_dict_args (self ):
2529 args = {
26- 'username' :'user-name' ,
27- 'password' :'new_password' ,
28- 'port' : 'admin_port' ,
29- 'foo' :'bar'
30- }
30+ 'username' : 'user-name' ,
31+ 'password' : 'new_password' ,
32+ 'port' : 'admin_port' ,
33+ 'foo' : 'bar'
34+ }
3135 expected = {
32- 'user-name' :'admin' ,
33- 'new_password' :'changeme' ,
34- 'admin_port' :8089
35- }
36+ 'user-name' : 'admin' ,
37+ 'new_password' : 'changeme' ,
38+ 'admin_port' : 8089
39+ }
3640 self .assertTrue (expected == dslice (TEST_DICT , args ))
3741
3842 # Test dslice when a list is passed
@@ -43,40 +47,66 @@ def test_dslice_list_args(self):
4347 'port' ,
4448 'host' ,
4549 'foo'
46- ]
50+ ]
4751 expected = {
48- 'username' :'admin' ,
49- 'password' :'changeme' ,
50- 'port' :8089 ,
51- 'host' :'localhost'
52- }
52+ 'username' : 'admin' ,
53+ 'password' : 'changeme' ,
54+ 'port' : 8089 ,
55+ 'host' : 'localhost'
56+ }
5357 self .assertTrue (expected == dslice (TEST_DICT , test_list ))
5458
5559 # Test dslice when a single string is passed
5660 def test_dslice_arg (self ):
5761 test_arg = 'username'
5862 expected = {
59- 'username' :'admin'
60- }
63+ 'username' : 'admin'
64+ }
6165 self .assertTrue (expected == dslice (TEST_DICT , test_arg ))
6266
6367 # Test dslice using all three types of arguments
6468 def test_dslice_all_args (self ):
6569 test_args = [
66- {'username' :'new_username' },
70+ {'username' : 'new_username' },
6771 ['password' ,
68- 'host' ],
72+ 'host' ],
6973 'port'
7074 ]
7175 expected = {
72- 'new_username' :'admin' ,
73- 'password' :'changeme' ,
74- 'host' :'localhost' ,
75- 'port' :8089
76+ 'new_username' : 'admin' ,
77+ 'password' : 'changeme' ,
78+ 'host' : 'localhost' ,
79+ 'port' : 8089
7680 }
7781 self .assertTrue (expected == dslice (TEST_DICT , * test_args ))
7882
7983
84+ class FilePermissionTest (unittest .TestCase ):
85+
86+ def setUp (self ):
87+ super (FilePermissionTest , self ).setUp ()
88+
89+ # Check for any change in the default file permission(i.e 644) for all files within splunklib
90+ def test_filePermissions (self ):
91+
92+ def checkFilePermissions (dir_path ):
93+ for file in os .listdir (dir_path ):
94+ if file .__contains__ ('pycache' ):
95+ continue
96+ path = os .path .join (dir_path , file )
97+ if os .path .isfile (path ):
98+ permission = oct (os .stat (path ).st_mode )
99+ if sys .version_info >= (3 , 0 ):
100+ self .assertEqual (permission , '0o100644' )
101+ else :
102+ self .assertEqual (permission , '0100644' )
103+ else :
104+ checkFilePermissions (path )
105+
106+ dir_path = os .path .join ('..' , 'splunklib' )
107+ checkFilePermissions (dir_path )
108+
109+
80110if __name__ == "__main__" :
81111 try :
82112 import unittest2 as unittest
0 commit comments