44"""
55import json
66import uuid
7+ import random
78
89import httmock
910
@@ -55,6 +56,18 @@ class TestCase(base.TestCase):
5556 def uuidv4 ():
5657 return str (uuid .uuid4 ())
5758
59+ @staticmethod
60+ def random ():
61+ return str (random .random ())
62+
63+ def _generate_policies (self ):
64+ sample = self .consul .acl .create_policy (self .random ())
65+ sample_update = self .consul .acl .create_policy (self .random ())
66+ return [dict (ID = sample ["ID" ]), dict (ID = sample_update ["ID" ])]
67+
68+ def _generate_roles (self ):
69+ return [dict (ID = self .consul .acl .create_role (self .random ()))]
70+
5871 def test_bootstrap_request_exception (self ):
5972 @httmock .all_requests
6073 def response_content (_url_unused , _request ):
@@ -176,7 +189,7 @@ def test_create_and_read_policy(self):
176189 self .assertEqual (result ['Rules' ], ACL_NEW_RULES )
177190
178191 def test_create_and_update_policy (self ):
179- value = self .consul .acl .create_policy ("unittest_read_policy " ,
192+ value = self .consul .acl .create_policy ("unittest_update_policy " ,
180193 rules = ACL_NEW_RULES )
181194 result = self .consul .acl .update_policy (value ["ID" ],
182195 value ["Name" ],
@@ -197,34 +210,33 @@ def test_list_policy_exception(self):
197210 def test_create_role (self ):
198211 result = self .consul .acl .create_role (
199212 "unittest_create_role" ,
200- policies = POLICYLINKS_SAMPLE ,
201- service_identities = SERVICE_IDENTITIES_SAMPLE )
202- self .assertEqual (result [0 ]['ID' ], POLICYLINKS_SAMPLE [0 ]['ID' ])
213+ policies = self . _generate_policies () ,
214+ service_identities = SERVICE_IDENTITIES_SAMPLE ,
215+ self .assertEqual (result ['ServiceIdentities' ][ 0 ]['ID' ], SERVICE_IDENTITIES_SAMPLE [0 ]['ID' ])
203216
204217 def test_create_and_read_role (self ):
205218 value = self .consul .acl .create_role (
206219 "unittest_read_role" ,
207- policies = POLICYLINKS_SAMPLE ,
220+ policies = self . _generate_policies () ,
208221 service_identities = SERVICE_IDENTITIES_SAMPLE )
209222 result = self .consul .acl .read_role (value ["ID" ])
210- self .assertEqual (result ['Policies' ][0 ]['ID' ],
211- POLICYLINKS_SAMPLE [0 ]["ID" ])
223+ self .assertEqual (result ['ID' ], value ['ID' ])
212224
213225 def test_create_and_update_role (self ):
214226 value = self .consul .acl .create_role (
215- "unittest_read_role " ,
216- policies = POLICYLINKS_SAMPLE ,
227+ "unittest_update_role " ,
228+ policies = self . _generate_policies () ,
217229 service_identities = SERVICE_IDENTITIES_SAMPLE )
218230 result = self .consul .acl .update_role (
219231 value ["ID" ],
220- "unittest_read_role " ,
232+ "unittest_update_role " ,
221233 policies = POLICYLINKS_UPDATE_SAMPLE )
222234 self .assertGreater (result ["ModifyIndex" ], result ["CreateIndex" ])
223235
224236 def test_create_and_delete_role (self ):
225237 value = self .consul .acl .create_role (
226238 "unittest_delete_role" ,
227- policies = POLICYLINKS_SAMPLE ,
239+ policies = self . _generate_policies () ,
228240 service_identities = SERVICE_IDENTITIES_SAMPLE )
229241 result = self .consul .acl .delete_role (value ["ID" ])
230242 self .assertTrue (result )
@@ -240,8 +252,8 @@ def test_create_token(self):
240252 result = self .consul .acl .create_token (
241253 accessor_id = accessor_id ,
242254 secret_id = secret_id ,
243- roles = ROLELINKS_SAMPLE ,
244- policies = POLICYLINKS_SAMPLE ,
255+ roles = self . _generate_roles () ,
256+ policies = self . _generate_policies () ,
245257 service_identities = SERVICE_IDENTITIES_SAMPLE )
246258 self .assertEqual (result ['AccessorID' ], accessor_id )
247259 self .assertEqual (result ['SecretID' ], secret_id )
@@ -252,8 +264,8 @@ def test_create_and_read_token(self):
252264 value = self .consul .acl .create_token (
253265 accessor_id = accessor_id ,
254266 secret_id = secret_id ,
255- roles = ROLELINKS_SAMPLE ,
256- policies = POLICYLINKS_SAMPLE ,
267+ roles = self . _generate_roles () ,
268+ policies = self . _generate_policies () ,
257269 service_identities = SERVICE_IDENTITIES_SAMPLE )
258270 result = self .consul .acl .read_token (value ["AccessorID" ])
259271 self .assertEqual (result ['AccessorID' ], accessor_id )
@@ -264,11 +276,11 @@ def test_create_and_update_token(self):
264276 value = self .consul .acl .create_token (
265277 accessor_id = accessor_id ,
266278 secret_id = secret_id ,
267- roles = ROLELINKS_SAMPLE ,
268- policies = POLICYLINKS_SAMPLE ,
279+ roles = self . _generate_roles () ,
280+ policies = self . _generate_policies () ,
269281 service_identities = SERVICE_IDENTITIES_SAMPLE )
270282 result = self .consul .acl .update_token (
271- value ["AccessorID" ], policies = POLICYLINKS_UPDATE_SAMPLE )
283+ value ["AccessorID" ], policies = self . _generate_policies () )
272284 self .assertGreater (result ["ModifyIndex" ], result ["CreateIndex" ])
273285
274286 def test_create_and_clone_token (self ):
0 commit comments