Verified Commit c8c1e0ac authored by Johannes Visintini's avatar Johannes Visintini
Browse files

Change API version to a optional parameter

parent d56c4fa5
......@@ -2,16 +2,21 @@
This small script checks the given ohsome API and performs an request for every endpoint present in the swagger files or requests given in a json file.
## Installation
```bash
% pip3 install -r requirements.txt
```
## Usage
### Requests from Swagger JSON
Check all endpoints with default values read from the swagger files:
```bash
% python3 check-ohsome-api.py v1
% python3 check-ohsome-api.py -a v1
Getting Swagger jsons
Running requests
100%|████████████████████████████████████████████████████████████| 135/135 [10:27<00:00, 4.65s/it]
......@@ -20,9 +25,13 @@ Status Amount
200 100.00 %
```
Check requests given in `example-requests.json`:
### Requests from File
Check requests given in [example-requests.json](example-requests.json):
```bash
% python3 check-ohsome-api.py v1 -r example-requests.json
% python3 check-ohsome-api.py -a v1 -r example-requests.json
Running requests
POST 400: https://api.ohsome.org/v1/elements/count
{'time': '2010-01-01/2016-08-01/P2Y2M2D', 'filter': 'highway=residential and type:way', 'note': 'bboxes missing on purpose'}
......@@ -33,18 +42,35 @@ Status Amount
400 33.33 %
```
Usage:
### Check Local Instance
Check requests given in [example-requests.json](example-requests.json) with local running ohsome API:
```bash
% python3 check-ohsome-api.py -b http://localhost:8080 -r example-requests.json
Running requests
POST 400: http://localhost:8080/elements/count
{'time': '2010-01-01/2016-08-01/P2Y2M2D', 'filter': 'highway=residential and type:way', 'note': 'bboxes missing on purpose'}
100%|████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 11.03it/s]
Result:
Status Amount
200 66.67 %
400 33.33 %
```
### Arguments help
```bash
% python3 check-ohsome-api.py -h
usage: check-ohsome-api.py [-h] [-b BASE_URL] [-r REQUESTS_JSON] [-d] api_version
usage: check-ohsome-api.py [-h] [-a API_VERSION] [-b BASE_URL] [-r REQUESTS_JSON] [-d]
test ohsome API based on available paths in swagger files
positional arguments:
api_version api version path to be tested
optional arguments:
-h, --help show this help message and exit
-a API_VERSION, --api_version API_VERSION
api version path to be tested
-b BASE_URL, --base-url BASE_URL
base url
-r REQUESTS_JSON, --requests-json REQUESTS_JSON
......
......@@ -70,13 +70,16 @@ def print_results(status_codes, args):
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='test ohsome API based on available paths in swagger files')
parser.add_argument('api_version', type=str, help='api version path to be tested')
parser.add_argument('-a', '--api_version', type=str, help='api version path to be tested')
parser.add_argument('-b', '--base-url', type=str, default='https://api.ohsome.org', help='base url')
parser.add_argument('-r', '--requests-json', type=str, help='use the requests in this file instead of getting them from swagger files')
parser.add_argument('-d', '--debug', action='store_true', help='show debug output')
args = parser.parse_args()
base_url = "{}/{}".format(args.base_url, args.api_version)
if args.api_version:
base_url = "{}/{}".format(args.base_url, args.api_version)
else:
base_url = args.base_url
specs = ["Data Aggregation", "Data Extraction", "Metadata"]
if args.requests_json:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment