From 6021d350d077f80bb1ebc3d4089dde205143b8af Mon Sep 17 00:00:00 2001 From: changlong-liu <59815250+changlong-liu@users.noreply.github.com> Date: Fri, 2 Apr 2021 10:07:15 +0800 Subject: [PATCH] max&min test (#790) * max&min test * test Co-authored-by: Qiaoqiao Zhang <55688292+qiaozha@users.noreply.github.com> --- src/generate/CodeModelAz.ts | 4 +- src/generate/CodeModelAzImpl.ts | 43 +++++-- src/generate/renders/CliReport.ts | 6 +- src/generate/renders/extraExt/CliExtReadme.ts | 2 +- src/generate/renders/generated/CliHelp.ts | 2 +- src/generate/renders/tests/CliTestCmdlet.ts | 79 ++++++++---- src/templates/tests/cmdlet/conftest.py.njx | 5 + .../tests/cmdlet/test_negative.py.njx | 12 +- .../tests/cmdlet/test_positive.py.njx | 12 +- src/utils/helper.ts | 5 + .../attestation/input/attestation.json | 6 + ...te_AttestationProvider_MaximumSet_Gen.json | 47 +++++++ ...te_AttestationProvider_MinimumSet_Gen.json | 45 +++++++ .../tests/cmdlet/conftest.py | 5 + .../tests/cmdlet/test_negative.py | 35 ++++-- .../tests/cmdlet/test_positive.py | 23 ++-- .../tests/cmdlet/conftest.py | 5 + .../tests/cmdlet/test_negative.py | 72 +++++------ .../tests/cmdlet/test_positive.py | 72 +++++------ .../expected/tests/cmdlet/test_negative.py | 35 ++++-- .../expected/tests/cmdlet/test_positive.py | 23 ++-- test/unittest/render-cmdlets.ts | 119 ++++++++++++------ test/unittest/render-getRenderData.ts | 2 +- 23 files changed, 468 insertions(+), 191 deletions(-) create mode 100644 test/scenarios/attestation/input/examples/Create_AttestationProvider_MaximumSet_Gen.json create mode 100644 test/scenarios/attestation/input/examples/Create_AttestationProvider_MinimumSet_Gen.json diff --git a/src/generate/CodeModelAz.ts b/src/generate/CodeModelAz.ts index 90669d467..8c32454b2 100644 --- a/src/generate/CodeModelAz.ts +++ b/src/generate/CodeModelAz.ts @@ -78,7 +78,7 @@ export class CommandExample { public Method_IsLongRun: boolean; public MethodParams: MethodParam[]; public ExampleObj: any; - public commandStringItems; + public commandStringItems: string[]; public CommandString: string; public WaitCommandString: string; } @@ -272,7 +272,7 @@ export interface CodeModelAz { AzExample: CommandExample; AzExample_CommandString: string; AzExample_CommandStringItems: string[]; - GetExamples(): CommandExample[]; + GetExamples(includeGenerated: boolean): CommandExample[]; GetSubscriptionKey(): string; GetPreparerEntities(): any[]; GatherInternalResource(); diff --git a/src/generate/CodeModelAzImpl.ts b/src/generate/CodeModelAzImpl.ts index 08ade2107..6077b679b 100644 --- a/src/generate/CodeModelAzImpl.ts +++ b/src/generate/CodeModelAzImpl.ts @@ -31,6 +31,7 @@ import { ToSentence, isNullOrUndefined, ToMultiLine, + isGeneratedExampleId, } from '../utils/helper'; import { CodeGenConstants, @@ -2507,6 +2508,14 @@ export class CodeModelCliImpl implements CodeModelAz { return this.AzExample.CommandString; } + public get AzExample_Id(): string { + return this.AzExample.Id; + } + + public get AzExample_HttpMethod(): string { + return this.AzExample.HttpMethod; + } + public get AzExample_CommandStringItems(): string[] { const items = []; ToMultiLine( @@ -2517,6 +2526,15 @@ export class CodeModelCliImpl implements CodeModelAz { ); return items; } + + public get AzExample_RawCommandStringItems(): string[] { + return this.AzExample.commandStringItems; + } + + public get AzExample_IsGenerated(): boolean { + return isGeneratedExampleId(this.AzExample?.Id); + } + /** * Gets method parameters dict * @returns method parameters dict : key is parameter name, value is the parameter schema @@ -3107,18 +3125,24 @@ export class CodeModelCliImpl implements CodeModelAz { return true; } - public GetExamples(): CommandExample[] { - if (!isNullOrUndefined(this.Method_AzExamples) && this.Method_AzExamples.length > 0) { + public GetExamples(includeGenerated: boolean): CommandExample[] { + if ( + !isNullOrUndefined(this.Method_AzExamples) && + this.Method_AzExamples.length > 0 && + includeGenerated + ) { return this.Method_AzExamples; } const examples: CommandExample[] = []; if (this.Examples) { Object.entries(this.Examples).forEach(([id, exampleObj]) => { - const example = this.CreateCommandExample(id, exampleObj); - if (!isNullOrUndefined(example)) examples.push(example); + if (includeGenerated || !isGeneratedExampleId(id)) { + const example = this.CreateCommandExample(id, exampleObj); + if (!isNullOrUndefined(example)) examples.push(example); + } }); } - this.Method_AzExamples = examples; + if (includeGenerated) this.Method_AzExamples = examples; return examples; } @@ -3429,7 +3453,7 @@ export class CodeModelCliImpl implements CodeModelAz { const dependResources = []; const dependParameters = []; - const examples = this.GetExamples(); + const examples = this.GetExamples(false); // recognize depends by endpoint in examples for (const example of examples) { for (const param of example.Parameters) { @@ -3511,9 +3535,10 @@ export class CodeModelCliImpl implements CodeModelAz { }); if (isNullOrUndefined(this._defaultTestScenario)) { - this._defaultTestScenario = GenerateDefaultTestScenario(this.GetAllExamples()); + const allExamples = this.GetAllExamples(); + this._defaultTestScenario = GenerateDefaultTestScenario(allExamples); this._defaultTestScenario = GenerateDefaultTestScenarioByDependency( - this.GetAllExamples(), + allExamples, this.resourcePool, this._defaultTestScenario, ); @@ -3670,7 +3695,7 @@ export class CodeModelCliImpl implements CodeModelAz { if (isNullOrUndefined(example)) return; examples = [example]; } else { - examples = this.GetExamples(); + examples = this.GetExamples(true); } for (const example of examples) { if (id && !this.matchExample(example, id)) continue; diff --git a/src/generate/renders/CliReport.ts b/src/generate/renders/CliReport.ts index a614b9b75..0169b598c 100644 --- a/src/generate/renders/CliReport.ts +++ b/src/generate/renders/CliReport.ts @@ -69,7 +69,7 @@ export class CliReport extends TemplateBase { converter, ), ], - ['azExample', new RenderInput(['commandStringItems'], {})], + ['azExample', new RenderInput(['commandStringItems'], {}, [['isGenerated', true]])], ]); const dependencies = <[CodeModelTypes, CodeModelTypes][]>[ @@ -185,7 +185,7 @@ export class CliReport extends TemplateBase { do { if (model.SelectFirstMethod()) { do { - if (model.GetExamples().length > 0) { + if (model.GetExamples(false).length > 0) { mo.push( '|[az ' + model.CommandGroup_Name + @@ -256,7 +256,7 @@ export class CliReport extends TemplateBase { '`', ); mo.push(''); - for (const example of model.GetExamples()) { + for (const example of model.GetExamples(false)) { mo.push( '##### { const data = { testData: { className: 'PositiveTest', - cmds: [ + testCases: [ { - id: '/Operation/put/AttestationProviders_Create', - name: 'create_provider', - lines: [ - 'az attestation create-provider ', - '--provider-name "myattestationprovider" ', + exampleInfos: [ + { + id: '/Operation/put/AttestationProviders_Create', + lines: [ + 'az attestation create-provider ', + '--provider-name "myattestationprovider" ', + ], + lastLine: '--resource-group "MyResourceGroup"', + }, + { + id: '/Operation/put/AttestationProviders_Create_MaximumSet_Gen', + lines: [ + 'az attestation create-provider ', + '--provider-name "myattestationprovider" ', + ], + lastLine: '--resource-group "MyResourceGroup"', + }, + { + id: '/Operation/put/AttestationProviders_Create_MinimumSet_Gen', + lines: ['az attestation create-provider '], + lastLine: '--resource-group "MyResourceGroup"', + }, ], - lastLine: '--resource-group "MyResourceGroup"', + functionName: 'create_provider', }, { - id: '/Operation/get/Operations_List', - name: 'list_operation', - lines: [], - lastLine: 'az attestation list-operation', + exampleInfos: [ + { + id: '/Operation/get/Operations_List', + lines: [], + lastLine: 'az attestation list-operation', + }, + ], + functionName: 'list_operation', }, { - id: '/AttestationProviders/get/AttestationProviders_ListByResourceGroup', - name: 'attestation_provider_provider_list', - lines: ['az attestation attestation-provider provider list '], - lastLine: '--resource-group "testrg1"', + exampleInfos: [ + { + id: + '/AttestationProviders/get/AttestationProviders_ListByResourceGroup', + lines: ['az attestation attestation-provider provider list '], + lastLine: '--resource-group "testrg1"', + }, + ], + functionName: 'attestation_provider_provider_list', }, { - id: '/AttestationProviders/get/AttestationProviders_List', - name: 'attestation_provider_provider_list2', - lines: [], - lastLine: 'az attestation attestation-provider provider list', + exampleInfos: [ + { + id: '/AttestationProviders/get/AttestationProviders_List', + lines: [], + lastLine: 'az attestation attestation-provider provider list', + }, + ], + functionName: 'attestation_provider_provider_list2', }, { - id: '/AttestationProviders/get/AttestationProviders_Get', - name: 'attestation_provider_show', - lines: [ - 'az attestation attestation-provider show ', - '--provider-name "myattestationprovider" ', + exampleInfos: [ + { + id: '/AttestationProviders/get/AttestationProviders_Get', + lines: [ + 'az attestation attestation-provider show ', + '--provider-name "myattestationprovider" ', + ], + lastLine: '--resource-group "MyResourceGroup"', + }, ], - lastLine: '--resource-group "MyResourceGroup"', + functionName: 'attestation_provider_show', }, { - id: '/AttestationProviders/patch/AttestationProviders_Update', - name: 'attestation_provider_update', - lines: [ - 'az attestation attestation-provider update ', - '--provider-name "myattestationprovider" ', - '--resource-group "MyResourceGroup" ', + exampleInfos: [ + { + id: '/AttestationProviders/patch/AttestationProviders_Update', + lines: [ + 'az attestation attestation-provider update ', + '--provider-name "myattestationprovider" ', + '--resource-group "MyResourceGroup" ', + ], + lastLine: + '--tags Property1="Value1" Property2="Value2" Property3="Value3"', + }, ], - lastLine: '--tags Property1="Value1" Property2="Value2" Property3="Value3"', + functionName: 'attestation_provider_update', }, { - id: '/AttestationProviders/delete/AttestationProviders_Delete', - name: 'attestation_provider_delete', - lines: [ - 'az attestation attestation-provider delete -y ', - '--provider-name "myattestationprovider" ', + exampleInfos: [ + { + id: '/AttestationProviders/delete/AttestationProviders_Delete', + lines: [ + 'az attestation attestation-provider delete -y ', + '--provider-name "myattestationprovider" ', + ], + lastLine: '--resource-group "sample-resource-group"', + }, ], - lastLine: '--resource-group "sample-resource-group"', + functionName: 'attestation_provider_delete', }, ], }, diff --git a/test/unittest/render-getRenderData.ts b/test/unittest/render-getRenderData.ts index 21ef1db0f..1b41dba65 100644 --- a/test/unittest/render-getRenderData.ts +++ b/test/unittest/render-getRenderData.ts @@ -84,7 +84,7 @@ describe('RenderSetupPy', () => { converter, ), ], - ['azExample', new RenderInput(['commandStringItems'], {})], + ['azExample', new RenderInput(['commandStringItems'], {}, [['isGenerated', true]])], ]); if (arrayOutputFormat) {