Skip to content

Commit

Permalink
test extension
Browse files Browse the repository at this point in the history
  • Loading branch information
KissPeter committed Nov 16, 2019
1 parent f2eb476 commit 2a884f2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 96 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ addons:

script:
- python fuzzer.py -h
- pip3 install -r test/requirements_for_test.txt
- cd test && pytest test.py
9 changes: 4 additions & 5 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setup_class(cls):
cls.test_app_url = "http://127.0.0.1:5000/"
if not get_test_server_pid():
print('Start test app')
os.system("python3 ./test_application.py &")
os.system("python3 ./test_application.py 2>&1 | logger -t $0 &")
with open('./test_swagger_definition.json', 'r') as f:
cls.swagger = json.loads(f.read())

Expand Down Expand Up @@ -60,8 +60,7 @@ def test_integer_status_code(self):
self.fuzz(self.swagger)
last_call = self.query_last_call()
# last_call field:
# "path": "/exception/\u001f/\u001c\u007f\u0000N@",
last_value_sent = last_call['path'].replace('/exception/', '')
# "req_path": "/exception/\u001f/\u001c\u007f\u0000N@",
last_value_sent = last_call['req_path'].replace('/exception/', '')
assert not isinstance(last_value_sent, int), last_value_sent
# TODO Check why status code is not presented
# assert last_call['status_code'] == 500, last_call['status_code'] + "Received"
assert last_call['resp_status'] == 500, last_call['resp_status'] + "Received"
39 changes: 17 additions & 22 deletions test/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def __init__(self):
self.last_request_data = dict()

def set_data(self, data=None):
self.last_request_data = data
if data is not None:
self.last_request_data.update(data)

def get_data(self):
return self.last_request_data
Expand Down Expand Up @@ -52,27 +53,21 @@ def last_call():
return _return


@app.endpoint('index')
def save_request(path):
last_request = {
'status': request.args.get('status'),
'time': time.time(),
'path': request.path,
'script_root': request.script_root,
'url': request.url,
'base_url': request.base_url,
'url_root': request.url_root,
'method': request.method,
'headers': extract(request.headers),
'data': request.data.decode(encoding='UTF-8'),
'host': request.host,
'args': extract(request.args),
'form': extract(request.form),
'json': request.json,
'cookies': extract(request.cookies)
}
last_request_data.set_data(last_request)
return ''
@app.after_request
def log_the_status_code(response):
last_request_data.set_data({
'resp_body': response.get_data(),
'resp_headers': extract(response.headers),
'resp_status': response.status_code,
'req_path': request.path,
'req_url': request.url,
'req_method': request.method,
'req_headers': extract(request.headers),
'req_form': extract(request.form),
'req_json': request.json,
'req_data': request.data.decode(encoding='UTF-8')
})
return response


if __name__ == '__main__':
Expand Down
69 changes: 0 additions & 69 deletions test/test_swagger_definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,75 +22,6 @@

]
}
},
"/get": {
"get": {
"parameters": [
{
"name": "headerparam",
"in": "header",
"required": true,
"type": "number",
"format": "double"
},
{
"name": "pathparam",
"in": "path",
"required": true,
"type": "string",
"format": "double"
},
{
"name": "queryparam",
"in": "query",
"required": true,
"type": "string",
"format": "double"
}

]
}
},
"/other_methods": {
"post": {
"parameters": [
{
"name": "headerparam",
"in": "header",
"required": true,
"type": "number",
"format": "double"
},
{
"name": "pathparam",
"in": "path",
"required": true,
"type": "string",
"format": "double"
},
{
"name": "queryparam",
"in": "query",
"required": true,
"type": "string",
"format": "double"
},
{
"name": "bodyparam",
"in": "body",
"required": true,
"type": "number",
"format": "double"
},
{
"name": "formDataparam",
"in": "formData",
"required": true,
"type": "number",
"format": "double"
}
]
}
}
}
}

0 comments on commit 2a884f2

Please sign in to comment.