mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-04 07:50:56 +00:00
[python][fastapi] various minor improvements (#9672)
* fix python fastapi tests, update readme, add CI test * update FILES * use virtualenv * fix pom.xml * skip flake8
This commit is contained in:
parent
8c268c9578
commit
088bca1580
@ -285,7 +285,7 @@ public class PythonFastAPIServerCodegen extends AbstractPythonCodegen {
|
|||||||
System.out.println("# https://opencollective.com/openapi_generator/donate #");
|
System.out.println("# https://opencollective.com/openapi_generator/donate #");
|
||||||
System.out.println("# #");
|
System.out.println("# #");
|
||||||
System.out.println("# This generator's contributed by Nikita Vakula (https://github.com/krjakbrjak)#");
|
System.out.println("# This generator's contributed by Nikita Vakula (https://github.com/krjakbrjak)#");
|
||||||
System.out.println("# Please support his work directly via https://paypal.me/krjakbrjaki \uD83D\uDE4F #");
|
System.out.println("# Please support his work directly via https://paypal.me/krjakbrjak \uD83D\uDE4F #");
|
||||||
System.out.println("################################################################################");
|
System.out.println("################################################################################");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ Python >= 3.6
|
|||||||
|
|
||||||
To run the server, please execute the following from the root directory:
|
To run the server, please execute the following from the root directory:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
pip3 install -r requirements.txt
|
pip3 install -r requirements.txt
|
||||||
uvicorn main:app --host 0.0.0.0 --port {{serverPort}}
|
uvicorn main:app --host 0.0.0.0 --port {{serverPort}}
|
||||||
```
|
```
|
||||||
|
|
||||||
and open your browser at `http://localhost:{{serverPort}}/docs/` to see the docs.
|
and open your browser at `http://localhost:{{serverPort}}/docs/` to see the docs.
|
||||||
@ -30,3 +30,12 @@ To run the server on a Docker container, please execute the following from the r
|
|||||||
```bash
|
```bash
|
||||||
docker-compose up --build
|
docker-compose up --build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
|
||||||
|
To run the tests:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip3 install pytest
|
||||||
|
PYTHONPATH=src pytest tests
|
||||||
|
```
|
||||||
|
@ -47,7 +47,8 @@ def test_{{operationId}}(client: TestClient):
|
|||||||
params=params,{{/-first}}{{/queryParams}}
|
params=params,{{/-first}}{{/queryParams}}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
|
1
pom.xml
1
pom.xml
@ -1187,6 +1187,7 @@
|
|||||||
<!-- servers -->
|
<!-- servers -->
|
||||||
<module>samples/server/petstore/python-aiohttp</module>
|
<module>samples/server/petstore/python-aiohttp</module>
|
||||||
<module>samples/server/petstore/python-aiohttp-srclayout</module>
|
<module>samples/server/petstore/python-aiohttp-srclayout</module>
|
||||||
|
<module>samples/server/petstore/python-fastapi</module>
|
||||||
<module>samples/server/petstore/python-flask</module>
|
<module>samples/server/petstore/python-flask</module>
|
||||||
<!-- TODO: will move these to Github action
|
<!-- TODO: will move these to Github action
|
||||||
<module>samples/server/petstore/php-slim4</module>
|
<module>samples/server/petstore/php-slim4</module>
|
||||||
|
@ -13,9 +13,9 @@ Python >= 3.6
|
|||||||
|
|
||||||
To run the server, please execute the following from the root directory:
|
To run the server, please execute the following from the root directory:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
pip3 install -r requirements.txt
|
pip3 install -r requirements.txt
|
||||||
uvicorn main:app --host 0.0.0.0 --port 8080
|
uvicorn main:app --host 0.0.0.0 --port 8080
|
||||||
```
|
```
|
||||||
|
|
||||||
and open your browser at `http://localhost:8080/docs/` to see the docs.
|
and open your browser at `http://localhost:8080/docs/` to see the docs.
|
||||||
@ -27,3 +27,12 @@ To run the server on a Docker container, please execute the following from the r
|
|||||||
```bash
|
```bash
|
||||||
docker-compose up --build
|
docker-compose up --build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
|
||||||
|
To run the tests:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip3 install pytest
|
||||||
|
PYTHONPATH=src pytest tests
|
||||||
|
```
|
||||||
|
43
samples/server/petstore/python-fastapi/pom.xml
Normal file
43
samples/server/petstore/python-fastapi/pom.xml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<project>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.openapitools</groupId>
|
||||||
|
<artifactId>PythonFastAPITests</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>Python FastAPI Server</name>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-dependencies</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>test</id>
|
||||||
|
<phase>integration-test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>exec</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<executable>./test_python3.sh</executable>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
33
samples/server/petstore/python-fastapi/test_python3.sh
Executable file
33
samples/server/petstore/python-fastapi/test_python3.sh
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
REQUIREMENTS_FILE=requirements.txt
|
||||||
|
REQUIREMENTS_OUT=requirements.txt.log
|
||||||
|
SETUP_OUT=*.egg-info
|
||||||
|
VENV=.venv
|
||||||
|
DEACTIVE=false
|
||||||
|
|
||||||
|
export LC_ALL=en_US.UTF-8
|
||||||
|
export LANG=en_US.UTF-8
|
||||||
|
|
||||||
|
### set virtualenv
|
||||||
|
if [ -z "$VIRTUAL_ENV" ]; then
|
||||||
|
virtualenv $VENV --no-site-packages --always-copy --python python3
|
||||||
|
source $VENV/bin/activate
|
||||||
|
DEACTIVE=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
### install dependencies
|
||||||
|
pip install -r $REQUIREMENTS_FILE | tee -a $REQUIREMENTS_OUT
|
||||||
|
|
||||||
|
### run tests
|
||||||
|
PYTHONPATH=src pytest tests
|
||||||
|
|
||||||
|
### static analysis of code
|
||||||
|
#flake8 --show-source src/
|
||||||
|
|
||||||
|
### deactivate virtualenv
|
||||||
|
if [ $DEACTIVE == true ]; then
|
||||||
|
deactivate
|
||||||
|
fi
|
@ -2,11 +2,9 @@
|
|||||||
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
import json
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from openapi_server.models.api_response import ApiResponse
|
from openapi_server.models.api_response import ApiResponse # noqa: F401
|
||||||
from openapi_server.models.pet import Pet
|
from openapi_server.models.pet import Pet # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
def test_add_pet(client: TestClient):
|
def test_add_pet(client: TestClient):
|
||||||
@ -15,17 +13,19 @@ def test_add_pet(client: TestClient):
|
|||||||
Add a new pet to the store
|
Add a new pet to the store
|
||||||
"""
|
"""
|
||||||
pet = {"photo_urls":["photoUrls","photoUrls"],"name":"doggie","id":0,"category":{"name":"name","id":6},"tags":[{"name":"name","id":1},{"name":"name","id":1}],"status":"available"}
|
pet = {"photo_urls":["photoUrls","photoUrls"],"name":"doggie","id":0,"category":{"name":"name","id":6},"tags":[{"name":"name","id":1},{"name":"name","id":1}],"status":"available"}
|
||||||
headers = {
|
|
||||||
'Authorization': 'Bearer special-key',
|
headers = {
|
||||||
|
"Authorization": "Bearer special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'POST',
|
"POST",
|
||||||
'/pet',
|
"/pet",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=pet,
|
json=pet,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_delete_pet(client: TestClient):
|
def test_delete_pet(client: TestClient):
|
||||||
@ -33,17 +33,19 @@ def test_delete_pet(client: TestClient):
|
|||||||
|
|
||||||
Deletes a pet
|
Deletes a pet
|
||||||
"""
|
"""
|
||||||
headers = {
|
|
||||||
'api_key': 'api_key_example',
|
headers = {
|
||||||
'Authorization': 'Bearer special-key',
|
"api_key": 'api_key_example',
|
||||||
|
"Authorization": "Bearer special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'DELETE',
|
"DELETE",
|
||||||
'/pet/{petId}'.format(petId=56),
|
"/pet/{petId}".format(petId=56),
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_find_pets_by_status(client: TestClient):
|
def test_find_pets_by_status(client: TestClient):
|
||||||
@ -52,17 +54,18 @@ def test_find_pets_by_status(client: TestClient):
|
|||||||
Finds Pets by status
|
Finds Pets by status
|
||||||
"""
|
"""
|
||||||
params = [("status", ['status_example'])]
|
params = [("status", ['status_example'])]
|
||||||
headers = {
|
headers = {
|
||||||
'Authorization': 'Bearer special-key',
|
"Authorization": "Bearer special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'GET',
|
"GET",
|
||||||
'/pet/findByStatus',
|
"/pet/findByStatus",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
params=params,
|
params=params,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_find_pets_by_tags(client: TestClient):
|
def test_find_pets_by_tags(client: TestClient):
|
||||||
@ -71,17 +74,18 @@ def test_find_pets_by_tags(client: TestClient):
|
|||||||
Finds Pets by tags
|
Finds Pets by tags
|
||||||
"""
|
"""
|
||||||
params = [("tags", ['tags_example'])]
|
params = [("tags", ['tags_example'])]
|
||||||
headers = {
|
headers = {
|
||||||
'Authorization': 'Bearer special-key',
|
"Authorization": "Bearer special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'GET',
|
"GET",
|
||||||
'/pet/findByTags',
|
"/pet/findByTags",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
params=params,
|
params=params,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_get_pet_by_id(client: TestClient):
|
def test_get_pet_by_id(client: TestClient):
|
||||||
@ -89,16 +93,18 @@ def test_get_pet_by_id(client: TestClient):
|
|||||||
|
|
||||||
Find pet by ID
|
Find pet by ID
|
||||||
"""
|
"""
|
||||||
headers = {
|
|
||||||
'api_key': 'special-key',
|
headers = {
|
||||||
|
"api_key": "special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'GET',
|
"GET",
|
||||||
'/pet/{petId}'.format(petId=56),
|
"/pet/{petId}".format(petId=56),
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_update_pet(client: TestClient):
|
def test_update_pet(client: TestClient):
|
||||||
@ -107,17 +113,19 @@ def test_update_pet(client: TestClient):
|
|||||||
Update an existing pet
|
Update an existing pet
|
||||||
"""
|
"""
|
||||||
pet = {"photo_urls":["photoUrls","photoUrls"],"name":"doggie","id":0,"category":{"name":"name","id":6},"tags":[{"name":"name","id":1},{"name":"name","id":1}],"status":"available"}
|
pet = {"photo_urls":["photoUrls","photoUrls"],"name":"doggie","id":0,"category":{"name":"name","id":6},"tags":[{"name":"name","id":1},{"name":"name","id":1}],"status":"available"}
|
||||||
headers = {
|
|
||||||
'Authorization': 'Bearer special-key',
|
headers = {
|
||||||
|
"Authorization": "Bearer special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'PUT',
|
"PUT",
|
||||||
'/pet',
|
"/pet",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=pet,
|
json=pet,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_update_pet_with_form(client: TestClient):
|
def test_update_pet_with_form(client: TestClient):
|
||||||
@ -125,21 +133,23 @@ def test_update_pet_with_form(client: TestClient):
|
|||||||
|
|
||||||
Updates a pet in the store with form data
|
Updates a pet in the store with form data
|
||||||
"""
|
"""
|
||||||
headers = {
|
|
||||||
'Authorization': 'Bearer special-key',
|
headers = {
|
||||||
|
"Authorization": "Bearer special-key",
|
||||||
}
|
}
|
||||||
data = {
|
data = {
|
||||||
'name': 'name_example',
|
"name": 'name_example',
|
||||||
'status': 'status_example'
|
"status": 'status_example'
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'POST',
|
"POST",
|
||||||
'/pet/{petId}'.format(petId=56),
|
"/pet/{petId}".format(petId=56),
|
||||||
headers=headers,
|
headers=headers,
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_upload_file(client: TestClient):
|
def test_upload_file(client: TestClient):
|
||||||
@ -147,19 +157,21 @@ def test_upload_file(client: TestClient):
|
|||||||
|
|
||||||
uploads an image
|
uploads an image
|
||||||
"""
|
"""
|
||||||
headers = {
|
|
||||||
'Authorization': 'Bearer special-key',
|
headers = {
|
||||||
|
"Authorization": "Bearer special-key",
|
||||||
}
|
}
|
||||||
data = {
|
data = {
|
||||||
'additional_metadata': 'additional_metadata_example',
|
"additional_metadata": 'additional_metadata_example',
|
||||||
'file': '/path/to/file'
|
"file": '/path/to/file'
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'POST',
|
"POST",
|
||||||
'/pet/{petId}/uploadImage'.format(petId=56),
|
"/pet/{petId}/uploadImage".format(petId=56),
|
||||||
headers=headers,
|
headers=headers,
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
import json
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from openapi_server.models.order import Order
|
from openapi_server.models.order import Order # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
def test_delete_order(client: TestClient):
|
def test_delete_order(client: TestClient):
|
||||||
@ -13,15 +11,17 @@ def test_delete_order(client: TestClient):
|
|||||||
|
|
||||||
Delete purchase order by ID
|
Delete purchase order by ID
|
||||||
"""
|
"""
|
||||||
headers = {
|
|
||||||
|
headers = {
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'DELETE',
|
"DELETE",
|
||||||
'/store/order/{orderId}'.format(orderId='order_id_example'),
|
"/store/order/{orderId}".format(orderId='order_id_example'),
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_get_inventory(client: TestClient):
|
def test_get_inventory(client: TestClient):
|
||||||
@ -29,16 +29,18 @@ def test_get_inventory(client: TestClient):
|
|||||||
|
|
||||||
Returns pet inventories by status
|
Returns pet inventories by status
|
||||||
"""
|
"""
|
||||||
headers = {
|
|
||||||
'api_key': 'special-key',
|
headers = {
|
||||||
|
"api_key": "special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'GET',
|
"GET",
|
||||||
'/store/inventory',
|
"/store/inventory",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_get_order_by_id(client: TestClient):
|
def test_get_order_by_id(client: TestClient):
|
||||||
@ -46,15 +48,17 @@ def test_get_order_by_id(client: TestClient):
|
|||||||
|
|
||||||
Find purchase order by ID
|
Find purchase order by ID
|
||||||
"""
|
"""
|
||||||
headers = {
|
|
||||||
|
headers = {
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'GET',
|
"GET",
|
||||||
'/store/order/{orderId}'.format(orderId=56),
|
"/store/order/{orderId}".format(orderId=56),
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_place_order(client: TestClient):
|
def test_place_order(client: TestClient):
|
||||||
@ -63,14 +67,16 @@ def test_place_order(client: TestClient):
|
|||||||
Place an order for a pet
|
Place an order for a pet
|
||||||
"""
|
"""
|
||||||
order = {"pet_id":6,"quantity":1,"id":0,"ship_date":"2000-01-23T04:56:07.000+00:00","complete":0,"status":"placed"}
|
order = {"pet_id":6,"quantity":1,"id":0,"ship_date":"2000-01-23T04:56:07.000+00:00","complete":0,"status":"placed"}
|
||||||
headers = {
|
|
||||||
|
headers = {
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'POST',
|
"POST",
|
||||||
'/store/order',
|
"/store/order",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=order,
|
json=order,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
import json
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from openapi_server.models.user import User
|
from openapi_server.models.user import User # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
def test_create_user(client: TestClient):
|
def test_create_user(client: TestClient):
|
||||||
@ -14,17 +12,19 @@ def test_create_user(client: TestClient):
|
|||||||
Create user
|
Create user
|
||||||
"""
|
"""
|
||||||
user = {"first_name":"firstName","last_name":"lastName","password":"password","user_status":6,"phone":"phone","id":0,"email":"email","username":"username"}
|
user = {"first_name":"firstName","last_name":"lastName","password":"password","user_status":6,"phone":"phone","id":0,"email":"email","username":"username"}
|
||||||
headers = {
|
|
||||||
'api_key': 'special-key',
|
headers = {
|
||||||
|
"api_key": "special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'POST',
|
"POST",
|
||||||
'/user',
|
"/user",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=user,
|
json=user,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_create_users_with_array_input(client: TestClient):
|
def test_create_users_with_array_input(client: TestClient):
|
||||||
@ -33,17 +33,19 @@ def test_create_users_with_array_input(client: TestClient):
|
|||||||
Creates list of users with given input array
|
Creates list of users with given input array
|
||||||
"""
|
"""
|
||||||
user = [{"first_name":"firstName","last_name":"lastName","password":"password","user_status":6,"phone":"phone","id":0,"email":"email","username":"username"}]
|
user = [{"first_name":"firstName","last_name":"lastName","password":"password","user_status":6,"phone":"phone","id":0,"email":"email","username":"username"}]
|
||||||
headers = {
|
|
||||||
'api_key': 'special-key',
|
headers = {
|
||||||
|
"api_key": "special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'POST',
|
"POST",
|
||||||
'/user/createWithArray',
|
"/user/createWithArray",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=user,
|
json=user,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_create_users_with_list_input(client: TestClient):
|
def test_create_users_with_list_input(client: TestClient):
|
||||||
@ -52,17 +54,19 @@ def test_create_users_with_list_input(client: TestClient):
|
|||||||
Creates list of users with given input array
|
Creates list of users with given input array
|
||||||
"""
|
"""
|
||||||
user = [{"first_name":"firstName","last_name":"lastName","password":"password","user_status":6,"phone":"phone","id":0,"email":"email","username":"username"}]
|
user = [{"first_name":"firstName","last_name":"lastName","password":"password","user_status":6,"phone":"phone","id":0,"email":"email","username":"username"}]
|
||||||
headers = {
|
|
||||||
'api_key': 'special-key',
|
headers = {
|
||||||
|
"api_key": "special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'POST',
|
"POST",
|
||||||
'/user/createWithList',
|
"/user/createWithList",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=user,
|
json=user,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_delete_user(client: TestClient):
|
def test_delete_user(client: TestClient):
|
||||||
@ -70,16 +74,18 @@ def test_delete_user(client: TestClient):
|
|||||||
|
|
||||||
Delete user
|
Delete user
|
||||||
"""
|
"""
|
||||||
headers = {
|
|
||||||
'api_key': 'special-key',
|
headers = {
|
||||||
|
"api_key": "special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'DELETE',
|
"DELETE",
|
||||||
'/user/{username}'.format(username='username_example'),
|
"/user/{username}".format(username='username_example'),
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_get_user_by_name(client: TestClient):
|
def test_get_user_by_name(client: TestClient):
|
||||||
@ -87,15 +93,17 @@ def test_get_user_by_name(client: TestClient):
|
|||||||
|
|
||||||
Get user by user name
|
Get user by user name
|
||||||
"""
|
"""
|
||||||
headers = {
|
|
||||||
|
headers = {
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'GET',
|
"GET",
|
||||||
'/user/{username}'.format(username='username_example'),
|
"/user/{username}".format(username='username_example'),
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_login_user(client: TestClient):
|
def test_login_user(client: TestClient):
|
||||||
@ -103,18 +111,18 @@ def test_login_user(client: TestClient):
|
|||||||
|
|
||||||
Logs user into the system
|
Logs user into the system
|
||||||
"""
|
"""
|
||||||
params = [("username", 'username_example'),
|
params = [("username", 'username_example'), ("password", 'password_example')]
|
||||||
("password", 'password_example')]
|
headers = {
|
||||||
headers = {
|
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'GET',
|
"GET",
|
||||||
'/user/login',
|
"/user/login",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
params=params,
|
params=params,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_logout_user(client: TestClient):
|
def test_logout_user(client: TestClient):
|
||||||
@ -122,16 +130,18 @@ def test_logout_user(client: TestClient):
|
|||||||
|
|
||||||
Logs out current logged in user session
|
Logs out current logged in user session
|
||||||
"""
|
"""
|
||||||
headers = {
|
|
||||||
'api_key': 'special-key',
|
headers = {
|
||||||
|
"api_key": "special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'GET',
|
"GET",
|
||||||
'/user/logout',
|
"/user/logout",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_update_user(client: TestClient):
|
def test_update_user(client: TestClient):
|
||||||
@ -140,15 +150,17 @@ def test_update_user(client: TestClient):
|
|||||||
Updated user
|
Updated user
|
||||||
"""
|
"""
|
||||||
user = {"first_name":"firstName","last_name":"lastName","password":"password","user_status":6,"phone":"phone","id":0,"email":"email","username":"username"}
|
user = {"first_name":"firstName","last_name":"lastName","password":"password","user_status":6,"phone":"phone","id":0,"email":"email","username":"username"}
|
||||||
headers = {
|
|
||||||
'api_key': 'special-key',
|
headers = {
|
||||||
|
"api_key": "special-key",
|
||||||
}
|
}
|
||||||
response = client.request(
|
response = client.request(
|
||||||
'PUT',
|
"PUT",
|
||||||
'/user/{username}'.format(username='username_example'),
|
"/user/{username}".format(username='username_example'),
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=user,
|
json=user,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
# uncomment below to assert the status code of the HTTP response
|
||||||
|
#assert response.status_code == 200
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user