Skip to content

Commit

Permalink
[Confluent] Add new test flow and fix bugs (Azure#3587)
Browse files Browse the repository at this point in the history
  • Loading branch information
00Kai0 authored Jul 8, 2021
1 parent 7c6f92b commit 97c5f48
Show file tree
Hide file tree
Showing 7 changed files with 2,072 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/confluent/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Release History
===============

0.3.0
+++++
* `az confluent offer-detail show`: Remove the properties `isRIRequired` and `msrp` from the output.
* `az confluent organization create`: Fix the issue that organization cannot be created with owner/contributor role through a SG assignment.

0.2.0
+++++
* [BREAKING CHANGE] `az confluent organization create`: Remove `--user-detail`, the parameter is now auto-filled by the email address, first name and last name decoded from access token.
Expand Down
2 changes: 1 addition & 1 deletion src/confluent/azext_confluent/azext_metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"azext.isExperimental": true,
"azext.minCliCoreVersion": "2.17.0"
"azext.minCliCoreVersion": "2.25.0"
}
9 changes: 6 additions & 3 deletions src/confluent/azext_confluent/manual/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def confluent_organization_create(cmd,
from azure.cli.command_modules.role.custom import list_role_assignments

token_info = Profile(cli_ctx=cmd.cli_ctx).get_raw_token()[0][2]
decode = jwt.decode(token_info['accessToken'], verify=False, algorithms=['RS256'])
# PyJWT < 2.0.0 is using `verify` to verify token
# PyJWT >= 2.0.0 has moved this paramter in options
# For compatibility, keep two options for now.
decode = jwt.decode(token_info['accessToken'], algorithms=['RS256'], verify=False, options={"verify_signature": False})
body = {}
body['user_detail'] = {}
try:
Expand All @@ -42,8 +45,8 @@ def confluent_organization_create(cmd,

# Check owner or contributor role of subscription
user_object_id = decode['oid']
role_assignments = list_role_assignments(cmd, assignee=user_object_id, role='Owner') + \
list_role_assignments(cmd, assignee=user_object_id, role='Contributor')
role_assignments = list_role_assignments(cmd, assignee=user_object_id, role='Owner', include_inherited=True, include_groups=True) + \
list_role_assignments(cmd, assignee=user_object_id, role='Contributor', include_inherited=True, include_groups=True)
if not role_assignments:
raise UnauthorizedError('You must have Owner or Contributor role of the subscription to create an organization.')

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
|Scenario|Result|ErrorMessage|ErrorStack|ErrorNormalized|StartDt|EndDt|
|step_terms_list|successed||||2021-07-01 10:18:02.406899|2021-07-01 10:18:02.587908|
|step_organization_show|successed||||2021-07-01 10:18:02.902892|2021-07-01 10:18:02.999867|
|step_organization_list|successed||||2021-07-01 10:18:02.999867|2021-07-01 10:18:03.094902|
|step_organization_list2|successed||||2021-07-01 10:18:03.094902|2021-07-01 10:18:03.190902|
|step_organization_update|successed||||2021-07-01 10:18:03.190902|2021-07-01 10:18:03.287868|
|step_organization_delete|successed||||2021-07-01 10:18:03.287868|2021-07-01 10:18:03.506873|
|step_terms_list|successed||||2021-07-07 05:49:18.241849|2021-07-07 05:49:18.473003|
|step_organization_show|successed||||2021-07-07 05:49:18.846170|2021-07-07 05:49:18.948916|
|step_organization_list|successed||||2021-07-07 05:49:18.948916|2021-07-07 05:49:19.053372|
|step_organization_list2|successed||||2021-07-07 05:49:19.054372|2021-07-07 05:49:19.153368|
|step_organization_update|successed||||2021-07-07 05:49:19.154380|2021-07-07 05:49:19.254379|
|step_organization_delete|successed||||2021-07-07 05:49:19.254379|2021-07-07 05:49:19.477328|
Coverage: 6/6
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

import mock
import time

from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer
from azure_devtools.scenario_tests import AllowLargeResponse

from .test_confluent_scenario import mock_jwt_decode, mock_list_role_assignments


class TestTermAcceptFlow(ScenarioTest):

@ResourceGroupPreparer(name_prefix='cli_test_term_accept_basic_flow', location='eastus2euap')
@AllowLargeResponse()
def test_term_accept_basic_flow(self, resource_group):

self.kwargs.update({
'rg': resource_group,
'offerId': 'confluent-cloud-azure-stag',
'planId': 'confluent-cloud-azure-payg-stag',
'publisherId': 'confluentinc',
'namespace': 'Microsoft.Confluent',
'organizationName': 'cliTestOrg-1'
})

self.cmd('az confluent offer-detail show '
'--publisher-id {publisherId} '
'--offer-id {offerId}')

self.cmd('az term accept '
'--product "{offerId}" '
'--plan "{planId}" '
'--publisher "{publisherId}"')

self.cmd('provider register -n {namespace} ')
result = self.cmd('provider show -n {namespace}').get_output_in_json()
while result['registrationState'] != 'Registered':
time.sleep(5)
result = self.cmd('provider show -n {namespace}').get_output_in_json()

with mock.patch('jwt.decode', mock_jwt_decode):
with mock.patch('azure.cli.command_modules.role.custom.list_role_assignments', mock_list_role_assignments):
self.cmd('az confluent organization create '
'--location "eastus2euap" '
'--offer-id "{offerId}" '
'--plan-id "{planId}" '
'--plan-name "Confluent Cloud - Pay as you Go" '
'--publisher-id "{publisherId}" '
'--term-unit "P1M" '
'--tags environment="Dev" '
'--name "{organizationName}" '
'--resource-group "{rg}"')

2 changes: 1 addition & 1 deletion src/confluent/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from setuptools import setup, find_packages

# HISTORY.rst entry.
VERSION = '0.1.0'
VERSION = '0.3.0'
try:
from azext_confluent.manual.version import VERSION
except ImportError:
Expand Down

0 comments on commit 97c5f48

Please sign in to comment.