Automating Pricing Estimator Testing with a Flask‑Based Python Service Integrated into Java
This article describes how a Python Flask service was created and integrated with Java to automate the validation of complex Excel‑based mapping rules in a pricing estimator system, dramatically reducing manual effort and improving test speed and accuracy.
In the previous article the pricing estimator system was introduced and the challenges of testing its mapping logic were outlined; this follow‑up explains how the identified problems were solved and further optimizations were made.
Background
The estimator workflow involves many mapping steps (SPU, external inspection items, etc.) configured manually in Excel files, making validation time‑consuming and error‑prone when done manually.
Overall Process
The first version used a Python script to filter Excel data. The new version service‑ifies the script, adds a front‑end UI, and connects Java, Python, and the inspection service via HTTP.
Users trigger a request from the front end, the Java service calls the inspection service, parses the report, and forwards the request to the Python service, which performs the mapping and writes results to the server; the Java service then reads the results and returns them for display.
Solution 3.1 – Python Script Maintenance
Problem
The script was embedded in the Java service, requiring a full redeployment for any change.
Solution
Encapsulate the script as an HTTP endpoint using Flask, allowing independent updates without affecting other services.
Implementation
Flask was chosen for its lightweight nature. A minimal Flask app is shown below:
from flask import Flask, request
app = Flask(__name__)
@app.route('/out')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000, debug=True)Running this script and visiting http://127.0.0.1:5000/out displays "Hello World!".
The service defines an endpoint /req that accepts GET and POST, extracts parameters via request.values, and performs the mapping logic.
Solution 3.2 – Excel File Handling
Problem
Excel mapping templates were packaged inside the Java service, causing frequent redeployments when they changed and path issues on the server.
Solution
Store Excel files on the server separately; updating the mapping only requires uploading a new Excel file.
Overall Effect
The first‑phase tool wrote mapping results to Excel; the new front‑end now displays results directly. In a test scenario, entering category, scenario, and inspection code and clicking execute completes the entire pricing flow in about 3 seconds, showing the final price and each mapping condition clearly.
Future Improvements
Decouple Java and Python services to avoid requiring them on the same server for Excel access.
Enable diffing of expected vs. actual results and display differences on the front end.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
