diff --git a/docs/1.10/README.md b/docs/1.10/README.md index f51c598ac..b2de015bd 100644 --- a/docs/1.10/README.md +++ b/docs/1.10/README.md @@ -85,5 +85,6 @@ This section describes how developers can build from Harbor source code, customi - [Using Make](build-customize-contribute/use-make.md) - [View and test Harbor REST API via Swagger](build-customize-contribute/configure-swagger.md) - [Registry Landscape](build-customize-contribute/registry-landscape.md) +- [E2E Test Scripting Guide](build-customize-contribute/e2e_api_python_based_scripting_guide.md) See also the list of [Articles from the Harbor Community](https://github.com/goharbor/harbor/blob/master/docs/README.md#articles-from-the-community). \ No newline at end of file diff --git a/docs/1.10/build-customize-contribute/e2e_api_python_based_scripting_guide.md b/docs/1.10/build-customize-contribute/e2e_api_python_based_scripting_guide.md new file mode 100644 index 000000000..3501c7515 --- /dev/null +++ b/docs/1.10/build-customize-contribute/e2e_api_python_based_scripting_guide.md @@ -0,0 +1,74 @@ +**E2E (API) Python Based Test Scripting Guide** + + +**Preparation** + +After getting Harbor source code (git clone https://github.com/goharbor/harbor.git), Harbor E2E API test scripts can be found in tests/apitests/python directory. + +Before scripting, please make sure swagger client has been made by "make swagger_client", then archive "harborclient" will be made + +1. `git clone https://github.com/goharbor/harbor.git` + +2. `cd harbor` + +3. `make swagger_client` + +4. `cd harborclient/` + + +We use $HARBORCLIENT_PATH represent the path of "harborclient" you've made by "make swagger_client". + +Deploy Harbor instance for testing, and we will use $HARBOR_URL to represent the deployed Harbor in this document. + +Harbor E2E API test scripts will import python library under archive "harborclient", please set OS environment variant for Harbor E2E API test scripts: + + +1. `export HARBOR_HOST=$HARBOR_URL` +2. `export SWAGGER_CLIENT_PATH=$HARBORCLIENT_PATH` + +Until now, we have all preparation work done. + +**Scripting** + +As you can see, we will use python library made by "make swagger_client", in this library, we have all API functions and models, but for more convenience we encapsulate one more level in archive "library", so the script structure is as bellow: + + -library/ + + -test_project_level_policy_content_trust.py + + -test_project_quota.py + + -test_retention.py + + -... + +You can add both library code and script code, since not all APIs have been encapsulated. + + +**Execution Example** + +root@harbor:/harbor/code/harbor# `python ./tests/apitests/python/test_add_sys_label_to_tag.py` + + +2020-03-11 13:40:07,269 DEBUG Starting new HTTPS connection (1): 1.1.1.1:443 +send: 'POST /api/v2.0/users HTTP/1.1\r\nHost: 1.1.1.1\r\nAccept-Encoding: identity\r\nContent-Length: 156\r\nContent-Type: application/json\r\nAccept: application/json\r\nAuthorization: Basic YWRtaW46SGFyYm9yMTIzNDU=\r\nUser-Agent: Swagger-Codegen/1.0.0/python\r\n\r\n{"username": "user-1583934007059", "role_id": 0, "password": "xxxxxxxx", "email": "realname-1583934007059@vmware.com", "realname": "realname-1583934007059"}' +reply: 'HTTP/1.1 201 Created\r\n' +header: Server: nginx +header: Date: Wed, 11 Mar 2020 13:40:07 GMT +header: Content-Length: 0 +header: Connection: keep-alive +header: Location: /api/v2.0/users/9 +header: Set-Cookie: sid=2e05f902f345b855ec33221ade1c6d09; Path=/; Secure; HttpOnly +header: X-Request-Id: 9ba11b26-2cdb-432f-878e-3fed04fa61b1 +header: Strict-Transport-Security: max-age=31536000; includeSubdomains; preload +header: X-Frame-Options: DENY +header: Content-Security-Policy: frame-ancestors 'none' +2020-03-11 13:40:07,482 DEBUG https://1.1.1.1:443 "POST /api/v2.0/users HTTP/1.1" 201 0 +2020-03-11 13:40:07,483 DEBUG response body: + +... + +... + +... +