# adminceshi/suizibiaopaiapi-master architecture

> Architecture diagram of the GitHub repository adminceshi/suizibiaopaiapi-master, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adminceshi/suizibiaopaiapi-master
- Repository: https://github.com/adminceshi/suizibiaopaiapi-master

## Overview

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: [`testcase/testAPI.py`](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/testcase/testAPI.py) (API tests), [`run_demo.py`](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/run_demo.py) (Run demo), [`lib/newReport.py`](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/lib/newReport.py) (Build report), [`lib/readexcel.py`](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/lib/readexcel.py) (Read Excel)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime & tests"]
  node_run_demo["Run demo<br/>runner<br/>[run_demo.py]"]
  node_test_api["API tests<br/>unittest/ddt<br/>[testAPI.py]"]
end

subgraph group_framework["Framework services"]
  node_read_excel["Read Excel<br/>excel reader<br/>[readexcel.py]"]
  node_write_excel["Write Excel<br/>excel writer<br/>[writeexcel.py]"]
  node_send_requests["Send requests<br/>HTTP client<br/>[sendrequests.py]"]
  node_new_report["Build report<br/>report generator<br/>[newReport.py]"]
  node_send_mail["Send mail<br/>notification<br/>[sendmail.py]"]
  node_html_runner["HTML runner<br/>reporting lib<br/>[HTMLTestRunner.py]"]
end

subgraph group_fixtures["DB fixtures"]
  node_mysql_db[("MySQL setup<br/>db helper<br/>[mysql_db.py]")]
  node_test_data["Seed data<br/>db seed<br/>[test_data.py]"]
end

subgraph group_data["Test data"]
  node_cases_xlsx["Test cases<br/>excel cases"]
  node_config_ini["Config INI<br/>runtime config<br/>[config.ini]"]
  node_setting_py["Settings<br/>paths config<br/>[setting.py]"]
end

subgraph group_outputs["Generated outputs"]
  node_excel_report["Excel results<br/>result workbook"]
end

node_run_demo -->|"executes"| node_test_api
node_run_demo -->|"generates"| node_new_report
node_test_api -->|"loads cases"| node_read_excel
node_test_api -->|"calls API"| node_send_requests
node_test_api -->|"uses db"| node_mysql_db
node_test_api -->|"records results"| node_write_excel
node_read_excel -->|"reads from"| node_cases_xlsx
node_write_excel -->|"writes to"| node_excel_report
node_test_api -->|"seeds state"| node_test_data
node_test_data -->|"applies to"| node_mysql_db
node_test_api -->|"reads config"| node_config_ini
node_test_api -->|"reads paths"| node_setting_py
node_new_report -->|"uses"| node_html_runner
node_new_report -->|"hands off"| node_send_mail
node_send_mail -->|"reads config"| node_config_ini
node_run_demo -.->|"report backend"| node_html_runner

click node_run_demo "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/run_demo.py"
click node_test_api "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/testcase/testAPI.py"
click node_read_excel "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/lib/readexcel.py"
click node_write_excel "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/lib/writeexcel.py"
click node_send_requests "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/lib/sendrequests.py"
click node_new_report "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/lib/newReport.py"
click node_send_mail "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/lib/sendmail.py"
click node_mysql_db "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/db_fixture/mysql_db.py"
click node_test_data "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/db_fixture/test_data.py"
click node_cases_xlsx "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/database/ShuzibiaopaiAPITestCase.xlsx"
click node_config_ini "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/database/config.ini"
click node_setting_py "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/config/setting.py"
click node_html_runner "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/package/HTMLTestRunner.py"
click node_excel_report "https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/report/excelReport/ShuzibiaopaiAPITestCase.xlsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_run_demo,node_test_api toneBlue
class node_read_excel,node_write_excel,node_send_requests,node_new_report,node_send_mail,node_html_runner toneAmber
class node_mysql_db,node_test_data toneMint
class node_cases_xlsx,node_config_ini,node_setting_py toneRose
class node_excel_report toneIndigo
```

## Components

### Runtime & tests

Execution entrypoint and automated test layer

- [Run demo](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/run_demo.py): runner · Top-level execution script that launches the suite and report flow · `run_demo.py`
- [API tests](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/testcase/testAPI.py): unittest/ddt · Data-driven test cases expanded from Excel rows · `testcase/testAPI.py`

### Framework services

Reusable helpers for HTTP, Excel, reporting, and email

- [Read Excel](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/lib/readexcel.py): excel reader · Loads test case rows and fields from the workbook · `lib/readexcel.py`
- [Write Excel](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/lib/writeexcel.py): excel writer · Persists pass/fail and execution results back to Excel · `lib/writeexcel.py`
- [Send requests](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/lib/sendrequests.py): HTTP client · Wraps API calls made by the tests · `lib/sendrequests.py`
- [Build report](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/lib/newReport.py): report generator · Creates the HTML test report after execution · `lib/newReport.py`
- [Send mail](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/lib/sendmail.py): notification · Emails the latest report to configured recipients · `lib/sendmail.py`
- [HTML runner](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/package/HTMLTestRunner.py): reporting lib · Vendored HTML test runner used to produce reports · `package/HTMLTestRunner.py`

### DB fixtures

MySQL state preparation and seed data

- [MySQL setup](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/db_fixture/mysql_db.py): db helper · Database access and reset/setup support for fixtures · `db_fixture/mysql_db.py`
- [Seed data](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/db_fixture/test_data.py): db seed · Prepares controlled backend data for predictable assertions · `db_fixture/test_data.py`

### Test data

Excel cases and external configuration

- [Test cases](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/database/ShuzibiaopaiAPITestCase.xlsx): excel cases · Primary data-driven source of API test definitions · `database/ShuzibiaopaiAPITestCase.xlsx`
- [Config INI](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/database/config.ini): runtime config · External settings such as database and email configuration · `database/config.ini`
- [Settings](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/config/setting.py): paths config · Central path and runtime configuration constants · `config/setting.py`

### Generated outputs

Execution artifacts and reports

- [Excel results](https://github.com/adminceshi/suizibiaopaiapi-master/blob/master/report/excelReport/ShuzibiaopaiAPITestCase.xlsx): result workbook · Workbook copies written as execution output artifacts · `report/excelReport/ShuzibiaopaiAPITestCase.xlsx`

## Connections

- 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
