In [ ]:
pio_bundle_pkl_path='pio_bundle.pkl'
test_request_path='data/test_request.json'
test_response_path='data/test_response.json'
In [ ]:
from __future__ import print_function, absolute_import, division
import json
import importlib
import dill as pickle
def test(pio_bundle_pkl_path,
test_request_path,
test_response_path):
with open(pio_bundle_pkl_path, 'rb') as fh:
pio_bundle = pickle.load(fh)
with open(test_request_path, 'rb') as fh:
actual_request = fh.read()
with open(test_response_path, 'rb') as fh:
expected_response = fh.read()
print('Expected Response:')
print(expected_response)
actual_transformed_request = pio_bundle.transform_request(actual_request)
actual_response = pio_bundle.predict(actual_transformed_request)
actual_transformed_response = pio_bundle.transform_response(actual_response)
print('')
print('Actual Response:')
print(actual_transformed_response)
return (json.loads(expected_response.decode('utf-8').strip()) \
== json.loads(actual_transformed_response.strip()))
In [ ]:
test_success = test(pio_bundle_pkl_path,
test_request_path,
test_response_path)
print('')
print('Test Success: %s' % test_success)
In [ ]: