Merge "[Core] Make iterations numeration starting from `1'"

This commit is contained in:
Jenkins 2016-08-01 23:45:29 +00:00 committed by Gerrit Code Review
commit 2a08398705
2 changed files with 8 additions and 5 deletions

View File

@ -90,12 +90,15 @@ class UserContextMixin(object):
else: else:
# Second and last case - 'round_robin'. # Second and last case - 'round_robin'.
tenants_amount = len(context_obj["tenants"]) tenants_amount = len(context_obj["tenants"])
tenant_id = sorted(context_obj["tenants"].keys())[ # NOTE(amaretskiy): iteration is subtracted by `1' because it
context_obj["iteration"] % tenants_amount] # starts from `1' but we count from `0'
tenant_index = int((context_obj["iteration"] - 1) % tenants_amount)
tenant_id = sorted(context_obj["tenants"].keys())[tenant_index]
tenant = context_obj["tenants"][tenant_id] tenant = context_obj["tenants"][tenant_id]
users = context_obj["tenants"][tenant_id]["users"] users = context_obj["tenants"][tenant_id]["users"]
user = users[ user_index = int(((context_obj["iteration"] - 1) / tenants_amount)
int(context_obj["iteration"] / tenants_amount) % len(users)] % len(users))
user = users[user_index]
scenario_ctx["user"], scenario_ctx["tenant"] = user, tenant scenario_ctx["user"], scenario_ctx["tenant"] = user, tenant

View File

@ -120,7 +120,7 @@ class UserContextMixinTestCase(test.TestCase):
} }
expected_ids = ["0_0", "1_0", "0_1", "1_1"] * 4 expected_ids = ["0_0", "1_0", "0_1", "1_1"] * 4
mapped_ids = [] mapped_ids = []
for i in range(16): for i in range(1, 17):
context["iteration"] = i context["iteration"] = i
user = self.mixin.map_for_scenario(context) user = self.mixin.map_for_scenario(context)
mapped_ids.append(user["user"]["id"]) mapped_ids.append(user["user"]["id"])