File: generating-integration-test.md

package info (click to toggle)
python-azure 20251014%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 766,472 kB
  • sloc: python: 6,314,744; ansic: 804; javascript: 287; makefile: 198; sh: 198; xml: 109
file content (107 lines) | stat: -rw-r--r-- 3,942 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Generating Python SDK Integration Test

Integration test can be generated from swagger examples using **autorest**.

## Prerequisites

You can install autorest following generic autorest documentation.
The best way of using **autorest.cli** is Docker container.

You need to clone following directories locally. I have added Python SDK here as well, it's not necessary, but may be useful.

    git clone https://github.com/Azure/azure-rest-api-specs.git
    git clone https://github.com/Azure/azure-sdk-for-python.git

For simplicity let's assume they are cloned under **c:\dev** directory on Windows machine.

The easiest way to use **autorest.cli** is the container:

    docker run -it --rm -v c:\dev:/_ mcr.microsoft.com/azure-cli/tools

You can also use the container without mapping your local folders:

    docker run -it --rm mcr.microsoft.com/azure-cli/tools

but you will need to make sure embedded copy of repositories are up to date:

    cd /_/azure-sdk-for-python; git pull
    cd /_/azure-rest-api-specs; git pull

## Configuration in **readme.cli.md** File

>NOTE: The same configuration will be used to generate Azure CLI commands tests.

In order to generate Python integration test you will need to create **readme.cli.md** file next to **readme.md** file in Azure REST API specification repository:

The minimal file should have following format:

    ## CLI

    These settings apply only when `--cli` is specified on the command line.

    ``` yaml $(cli)
    cli:
      namespace: azure.mgmt.attestation
    ```

## Generating Test

Run:

    autorest --cli --use-extension="{'@autorest/cli':'latest'}" --python-integration-test --output-folder=/_/azure-sdk-for-python /_/azure-rest-api-specs/specification/attestation/resource-manager/readme.md

You will get output like this:

    AutoRest code generation utility [version: 2.0.4407; node: v10.15.0]
    (C) 2018 Microsoft Corporation.
    https://aka.ms/autorest
    Loading AutoRest core      '/root/.autorest/@microsoft.azure_autorest-core@2.0.4407/node_modules/@microsoft.azure/autorest-core/dist' (2.0.4407)
    Loading AutoRest extension '@autorest/cli' (latest->0.1.889)
    Loading AutoRest extension '@microsoft.azure/autorest.modeler' (2.3.45->2.3.45)
    WARNING:
    WARNING: NO TEST SCENARIO PROVIDED - DEFAULT WILL BE USED
    WARNING: ADD FOLLOWING SECTION TO readme.cli.md FILE TO MODIFY IT
    WARNING: --------------------------------------------------------
    WARNING:   test-scenario:
    WARNING:     - name: AttestationProviders_Create
    WARNING:     - name: AttestationProviders_Get
    WARNING:     - name: AttestationProviders_ListByResourceGroup
    WARNING:     - name: AttestationProviders_List
    WARNING:     - name: Operations_List
    WARNING:     - name: AttestationProviders_Delete
    WARNING: --------------------------------------------------------

Default test-scenario was generated, you can copy and paste it into **readme.cli.md** file:


    ## CLI

    These settings apply only when `--cli` is specified on the command line.

    ``` yaml $(cli)
    cli:
      namespace: azure.mgmt.attestation
    test-scenario:
    - name: AttestationProviders_Create
    - name: AttestationProviders_Get
    - name: AttestationProviders_ListByResourceGroup
    - name: AttestationProviders_List
    - name: Operations_List
    - name: AttestationProviders_Delete
    ```

Now you can rerun **autorest** command and warning won't be visible any longer.
You can rearrange sequence or disable particular tests.

## Running Test

To run tests, refer to the documentation at
[/doc/dev/mgmt/tests.md](https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/mgmt/tests.md).

## Fixing Test

It's obvious that when running test for the first time something is not going to work.

The best approach is to:
- fix the test manually
- when the test is fully working backpropagate any changes to readme file and examples in swagger.