Skip to content

Commit

Permalink
increase test application robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
KissPeter committed Nov 17, 2019
1 parent 623f8c9 commit e391758
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions test/test_application.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python2.7
from functools import wraps

from flask import Flask, jsonify, request
import json
from flask import Flask, request
from werkzeug.routing import Rule

from apifuzzer.utils import try_b64encode

class LastRequestData(object):

Expand All @@ -18,7 +18,10 @@ def set_data(self, data=None):
self.last_request_data.update(data)

def get_data(self):
return self.last_request_data
try:
return json.dumps(self.last_request_data, ensure_ascii=False, indent=2, sort_keys=True)
except TypeError as e:
return 'Error: {}, latest data: {}'.format(e, self.last_request_data)


def catch_custom_exception(func):
Expand Down Expand Up @@ -50,15 +53,15 @@ def transform(integer_id):

@app.route('/last_call', methods=['GET'])
def last_call():
_return = jsonify(last_request_data.get_data())
_return = last_request_data.get_data()
last_request_data.wipe_data()
return _return


@app.after_request
def log_the_status_code(response):
last_request_data.set_data({
'resp_body': response.get_data(),
'resp_body': str(response.get_data()),
'resp_headers': extract(response.headers),
'resp_status': response.status_code,
'req_path': request.path,
Expand Down

0 comments on commit e391758

Please sign in to comment.