-
Notifications
You must be signed in to change notification settings - Fork 7
/
apotheosis_tests.py
67 lines (61 loc) · 2.23 KB
/
apotheosis_tests.py
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
from oauth2client.client import GoogleCredentials
import oauth2client
from googleapiclient import discovery
import unittest
import json
import imp
import time
import subprocess
import os
apotheosis = imp.load_source("apotheosis", os.getcwd() + "/apotheosis")
#these can be taken from the defaults or filled in:
test_resource = apotheosis.default_resource
test_member = apotheosis.default_member
test_role = apotheosis.default_role
test_service_account = apotheosis.default_service_account
class TestGetToken(unittest.TestCase):
def test_get_token(self):
token = apotheosis.get_token(test_service_account)
try:
token
token = True
except:
token = False
self.assertTrue(token)
class TestModifyPolicies(unittest.TestCase):
def test_modify_policy(self):
policy = { "bindings": [
{
"role": "roles/owner",
"members": [
"user:[email protected]",
"group:[email protected]",
"domain:google.com",
"serviceAccount:[email protected]"
]
},
{
"role": "roles/viewer",
"members": ["user:[email protected]"]
}
]
}
policy_copy_of_original = json.loads(json.dumps(policy))
role = "roles/viewer"
member = "user:[email protected]"
policy_with_addition = apotheosis.modify_policy_add_member(policy, role, member)
for binding in policy_with_addition['bindings']:
if binding['role'] == role:
self.assertTrue(member in binding['members'])
policy_with_removal = apotheosis.modify_policy_remove_member(policy, role, member)
for binding in policy_with_removal['bindings']:
if binding['role'] == role:
self.assertTrue(member not in binding['members'])
self.assertTrue(policy_with_removal == policy_copy_of_original)
class ApotheosisSuccessfulRun(unittest.TestCase):
def test_sucessful_run(self):
test_resource = apotheosis.default_resource
result = apotheosis.add_role(test_role, test_member, test_resource, test_service_account)
self.assertTrue(result)
if __name__ == '__main__':
unittest.main()