How adminceshi/suizibiaopaiapi-master works
1. What this repository is
- A Python-based API test automation framework built around unittest, data-driven with ddt, and driven primarily by Excel test cases.
- The framework is designed not just to send requests, but to also prepare test data in MySQL, validate responses against database-backed expectations, write results back to Excel, generate an HTML report, and email the latest report.
2. Main execution entry point
- run_demo.py is the top-level runner.
- It orchestrates execution of the test suite under testcase/, most notably testcase/testAPI.py, and triggers report generation afterward.
3. Test case layer
- testcase/testAPI.py contains the actual automated API tests.
- These tests are structured with unittest and use ddt so each Excel row becomes a separate test case instance.
- This layer is the boundary between the test framework and the system under test.
4. Test data source and case definition
- The primary test input lives in database/ShuzibiaopaiAPITestCase.xlsx.
- Excel is used to store request parameters, expected values, and result fields, making the suite data-driven rather than hardcoded.
- The lib/readexcel.py and lib/writeexcel.py modules handle reading test rows and writing execution results back into the sheet.
5. Environment and configuration
- config/setting.py centralizes path and runtime configuration.
- database/config.ini appears to hold external configuration such as database and email settings.
- This keeps environment-specific details out of the test logic.
6. Database fixture subsystem
- db_fixture/mysql_db.py and db_fixture/test_data.py implement the test data initialization layer.
- Before tests run, the framework clears and seeds the MySQL database so API responses are predictable and assertions are deterministic.
- This is a key architectural feature: the framework depends on controlled backend state to make API validation reliable.
7. Request/response subsystem
- lib/sendrequests.py is the HTTP client wrapper used by the tests.
- It sends requests to the API under test using parameters coming from the Excel case rows and any data assembled from the database fixture step.
- This module isolates transport concerns from the test logic.
8. Validation flow
- The intended flow is: read one Excel case → prepare/lookup database data → send API request → compare actual response and expected values → record pass/fail.
- The README indicates that the framework also queries the database during validation, then assembles the result into JSON-like expected data for comparison.
- This creates a two-source assertion model: API response + database state.
9. Result persistence
- lib/writeexcel.py writes the outcome of each case back into the Excel test case file or result workbook.
- Generated Excel results are stored under report/excelReport/.
- This gives the suite both machine-readable history and a test-case-level audit trail.
10. HTML reporting
- lib/newReport.py and package/HTMLTestRunner.py generate HTML test reports.
- Final reports are written into report/, with timestamped filenames.
- This is the main human-facing execution artifact for test runs.
11. Email notification
- lib/sendmail.py sends the newest report to a configured mailbox.
- In architecture terms, this is the delivery/notification boundary that pushes results out of the test runner and into an external communication channel.
12. Repository layout as architectural boundaries
- config/ = runtime/path configuration.
- database/ = test case Excel files and external configuration.
- db_fixture/ = database initialization and seed data logic.
- lib/ = core reusable framework services: Excel, HTTP, report, email.
- package/ = vendored third-party reporting dependency.
- report/ = generated outputs.
- testcase/ = actual automated tests.
- share/ = documentation screenshots, not part of runtime flow.
13. End-to-end data flow
- The core pipeline is:
- initialize DB state,
- load Excel-driven cases,
- send API requests,
- query/compare expected data,
- write results to Excel,
- generate HTML report,
- email the latest report.
- The architecture is therefore centered on a test orchestration pipeline with clear separation between data setup, request execution, validation, and reporting.
Main entry points: testAPI.py API tests · run_demo.py Run demo · newReport.py Build report · readexcel.py Read Excel
Components 14
Runtime & tests
Execution entrypoint and automated test layer
Framework services
Reusable helpers for HTTP, Excel, reporting, and email
- Read Excel · Loads test case rows and fields from the workbook
lib/readexcel.py - Write Excel · Persists pass/fail and execution results back to Excel
lib/writeexcel.py - Send requests · Wraps API calls made by the tests
lib/sendrequests.py - Build report · Creates the HTML test report after execution
lib/newReport.py - Send mail · Emails the latest report to configured recipients
lib/sendmail.py - HTML runner · Vendored HTML test runner used to produce reports
package/HTMLTestRunner.py
DB fixtures
MySQL state preparation and seed data
- MySQL setup · Database access and reset/setup support for fixtures
db_fixture/mysql_db.py - Seed data · Prepares controlled backend data for predictable assertions
db_fixture/test_data.py
Test data
Excel cases and external configuration
- Test cases · Primary data-driven source of API test definitions
database/ShuzibiaopaiAPITestCase.xlsx - Config INI · External settings such as database and email configuration
database/config.ini - Settings · Central path and runtime configuration constants
config/setting.py
Generated outputs
Execution artifacts and reports
- Excel results · Workbook copies written as execution output artifacts
report/excelReport/ShuzibiaopaiAPITestCase.xlsx
Connections 16
- Run demo → API tests: executes · Starts the automated API test suite
- Run demo → Build report: generates · Triggers report creation after test execution
- API tests → Read Excel: loads cases · Expands Excel rows into test instances
- API tests → Send requests: calls API · Sends requests for each test case
- API tests → MySQL setup: uses db · Queries or prepares database state for validation
- API tests → Write Excel: records results · Writes case outcomes back to workbook output
- Read Excel → Test cases: reads from · Consumes the Excel-driven test definitions
- Write Excel → Excel results: writes to · Persists results workbook artifacts
- API tests → Seed data: seeds state · Initializes controlled MySQL fixtures before validation
- Seed data → MySQL setup: applies to · Uses database helper to clear and seed backend data
- API tests → Config INI: reads config · Uses external runtime settings for environment-specific values
- API tests → Settings: reads paths · Uses central path and execution settings
- Build report → HTML runner: uses · Relies on vendored HTML test runner for report output
- Build report → Send mail: hands off · Feeds the latest report into email delivery
- Send mail → Config INI: reads config · Uses mailbox and server settings from configuration
- Run demo → HTML runner: report backend · Execution pipeline ends with HTML report generation