mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-22 16:48:30 +01:00
Merge pull request #11048 from danfengliu/add-doc-for-api-script-guide
Add doc for e2e API scripting guide
This commit is contained in:
commit
1c647bd0cc
@ -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).
|
@ -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:
|
||||
|
||||
...
|
||||
|
||||
...
|
||||
|
||||
...
|
||||
|
Loading…
Reference in New Issue
Block a user