|
23 | 23 |
|
24 | 24 | import testlib
|
25 | 25 |
|
26 |
| -def create_app(service, name): |
27 |
| - service.apps.create(name) |
28 |
| - testlib.restart(service) |
29 |
| - |
30 |
| -def create_user(service, name, password="changeme", roles="power"): |
31 |
| - service.users.create(name, password=password, roles=roles) |
32 |
| - |
33 | 26 | def delete_app(service, name):
|
34 | 27 | if (service.apps.contains(name)):
|
35 | 28 | service.apps.delete(name)
|
36 | 29 | testlib.restart(service)
|
37 | 30 |
|
38 |
| -def delete_user(service, name): |
39 |
| - if (service.users.contains(name)): |
40 |
| - service.users.delete(name) |
41 |
| - |
42 | 31 | # Verify that we can instantiate and connect to a service, test basic
|
43 | 32 | # interaction with the service and make sure we can connect and interact
|
44 | 33 | # with a variety of namespace configurations.
|
@@ -71,71 +60,51 @@ def test(self):
|
71 | 60 | service_ns = client.connect(**kwargs)
|
72 | 61 | service_ns.apps()
|
73 | 62 |
|
74 |
| - app = "sdk-tests" |
75 |
| - user = "sdk-user" |
76 |
| - delete_app(service, app) |
77 |
| - delete_user(service, user) |
78 |
| - self.assertFalse(service.apps.contains(app)) |
79 |
| - self.assertFalse(service.users.contains(user)) |
| 63 | + appname = "sdk-test-app" |
| 64 | + username = "sdk-test-user" |
| 65 | + delete_app(service, appname) |
| 66 | + if username in service.users: service.users.delete(username) |
| 67 | + self.assertFalse(service.apps.contains(appname)) |
| 68 | + self.assertFalse(service.users.contains(username)) |
80 | 69 |
|
81 | 70 | # App & owner dont exist, verify that the following errors
|
82 |
| - kwargs.update({ 'app': app, 'owner': user }) |
| 71 | + kwargs.update({ 'app': appname, 'owner': username }) |
83 | 72 | with self.assertRaises(HTTPError):
|
84 | 73 | service_ns = client.connect(**kwargs)
|
85 | 74 | service_ns.apps()
|
86 | 75 |
|
87 | 76 | # Validate namespace permutations with new app & user
|
88 |
| - create_app(service, app) |
89 |
| - create_user(service, user) |
| 77 | + service.apps.create(appname) |
| 78 | + service.users.create(username, password="changeme", roles="power") |
90 | 79 |
|
91 |
| - kwargs.update({ 'app': app, 'owner': None }) |
| 80 | + kwargs.update({ 'app': appname, 'owner': None }) |
92 | 81 | service_ns = client.connect(**kwargs)
|
93 | 82 | service_ns.apps()
|
94 | 83 |
|
95 |
| - kwargs.update({ 'app': app, 'owner': "-" }) |
| 84 | + kwargs.update({ 'app': appname, 'owner': "-" }) |
96 | 85 | service_ns = client.connect(**kwargs)
|
97 | 86 | service_ns.apps()
|
98 | 87 |
|
99 |
| - kwargs.update({ 'app': None, 'owner': user }) |
| 88 | + kwargs.update({ 'app': None, 'owner': username }) |
100 | 89 | service_ns = client.connect(**kwargs)
|
101 | 90 | service_ns.apps()
|
102 | 91 |
|
103 |
| - kwargs.update({ 'app': "-", 'owner': user }) |
| 92 | + kwargs.update({ 'app': "-", 'owner': username }) |
104 | 93 | service_ns = client.connect(**kwargs)
|
105 | 94 | service_ns.apps()
|
106 | 95 |
|
107 |
| - kwargs.update({ 'app': app, 'owner': user }) |
| 96 | + kwargs.update({ 'app': appname, 'owner': username }) |
108 | 97 | service_ns = client.connect(**kwargs)
|
109 | 98 | service_ns.apps()
|
110 | 99 |
|
111 | 100 | # Cleanup
|
112 |
| - delete_app(service, app) |
113 |
| - delete_user(service, user) |
| 101 | + delete_app(service, appname) |
| 102 | + service.users.delete(username) |
114 | 103 |
|
115 |
| - self.assertFalse(service.apps.contains(app)) |
116 |
| - self.assertFalse(service.users.contains(user)) |
| 104 | + self.assertFalse(service.apps.contains(appname)) |
| 105 | + self.assertFalse(service.users.contains(username)) |
117 | 106 |
|
118 | 107 | class ClientTestCase(testlib.TestCase):
|
119 |
| - def test_apps(self): |
120 |
| - service = client.connect(**self.opts.kwargs) |
121 |
| - |
122 |
| - for app in service.apps: app.refresh() |
123 |
| - |
124 |
| - delete_app(service, 'sdk-tests') |
125 |
| - self.assertFalse(service.apps.contains('sdk-tests')) |
126 |
| - |
127 |
| - create_app(service, 'sdk-tests') |
128 |
| - self.assertTrue(service.apps.contains('sdk-tests')) |
129 |
| - |
130 |
| - testapp = service.apps['sdk-tests'] |
131 |
| - self.assertTrue(testapp['author'] != "Splunk") |
132 |
| - testapp.update(author="Splunk") |
133 |
| - testapp.refresh() |
134 |
| - self.assertTrue(testapp['author'] == "Splunk") |
135 |
| - |
136 |
| - delete_app(service, 'sdk-tests') |
137 |
| - self.assertFalse(service.apps.contains('sdk-tests')) |
138 |
| - |
139 | 108 | def test_capabilities(self):
|
140 | 109 | service = client.connect(**self.opts.kwargs)
|
141 | 110 |
|
@@ -163,8 +132,7 @@ def test_confs(self):
|
163 | 132 |
|
164 | 133 | for conf in service.confs:
|
165 | 134 | for stanza in conf: stanza.refresh()
|
166 |
| - # no need to refresh every conf file for the test |
167 |
| - break |
| 135 | + break # no need to refresh every conf file for the test |
168 | 136 |
|
169 | 137 | self.assertTrue(service.confs.contains('props'))
|
170 | 138 | props = service.confs['props']
|
@@ -553,53 +521,5 @@ def test_settings(self):
|
553 | 521 | updated = settings['sessionTimeout']
|
554 | 522 | self.assertEqual(updated, original)
|
555 | 523 |
|
556 |
| - def test_users(self): |
557 |
| - service = client.connect(**self.opts.kwargs) |
558 |
| - users = service.users |
559 |
| - roles = service.roles |
560 |
| - |
561 |
| - # Verify that we can read the users collection |
562 |
| - for user in users: |
563 |
| - for role in user.content.roles: |
564 |
| - self.assertTrue(roles.contains(role)) |
565 |
| - |
566 |
| - if users.contains("sdk-user"): users.delete("sdk-user") |
567 |
| - self.assertFalse(users.contains("sdk-user")) |
568 |
| - |
569 |
| - user = users.create("sdk-user", password="changeme", roles="power") |
570 |
| - self.assertTrue(users.contains("sdk-user")) |
571 |
| - |
572 |
| - # Verify the new user has the expected attributes |
573 |
| - self.assertTrue('email' in user.content) |
574 |
| - self.assertTrue('password' in user.content) |
575 |
| - self.assertTrue('realname' in user.content) |
576 |
| - self.assertTrue('roles' in user.content) |
577 |
| - |
578 |
| - # Verify that we can update the user |
579 |
| - self.assertTrue(user['email'] is None) |
580 |
| - user.update(email="foo@bar.com") |
581 |
| - user.refresh() |
582 |
| - self.assertTrue(user['email'] == "foo@bar.com") |
583 |
| - |
584 |
| - # Verify that we can delete the user |
585 |
| - users.delete("sdk-user") |
586 |
| - self.assertFalse(users.contains("sdk-user")) |
587 |
| - |
588 |
| - # Splunk lowercases user names, verify the casing works as expected |
589 |
| - self.assertFalse(users.contains("sdk-user")) |
590 |
| - self.assertFalse(users.contains("SDK-User")) |
591 |
| - |
592 |
| - user = users.create("SDK-User", password="changeme", roles="power") |
593 |
| - self.assertTrue(user.name == "sdk-user") |
594 |
| - self.assertTrue(users.contains("SDK-User")) |
595 |
| - self.assertTrue(users.contains("sdk-user")) |
596 |
| - |
597 |
| - user = users['SDK-User'] |
598 |
| - self.assertTrue(user.name == "sdk-user") |
599 |
| - |
600 |
| - users.delete("SDK-User") |
601 |
| - self.assertFalse(users.contains("SDK-User")) |
602 |
| - self.assertFalse(users.contains("sdk-user")) |
603 |
| - |
604 | 524 | if __name__ == "__main__":
|
605 | 525 | testlib.main()
|
0 commit comments