Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ reports/
*.pb.go
*.pb.py


276 changes: 77 additions & 199 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,237 +1,115 @@
name: CI
name: CI Tests

on:
push:
branches: [main, develop]
branches: [ main, master, develop ]
pull_request:
branches: [main, develop]
branches: [ main, master, develop ]
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'

- name: Install dependencies
run: |
pip install --upgrade pip setuptools wheel
pip install -e ".[dev]"

- name: Run ruff
run: ruff check .

- name: Run mypy
run: mypy src config || true

test:
runs-on: ubuntu-latest
strategy:
matrix:
test-suite: [smoke, rest, graphql, grpc, database, kafka]
fail-fast: false

services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_DB: api_tests
POSTGRES_USER: tester
POSTGRES_PASSWORD: testpass
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

zookeeper:
image: confluentinc/cp-zookeeper:7.5.0
env:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- 2181:2181
options: >-
--health-cmd "nc -z localhost 2181"
--health-interval 10s
--health-timeout 5s
--health-retries 5

kafka:
image: confluentinc/cp-kafka:7.5.0
env:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: localhost:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
ports:
- 9092:9092
options: >-
--health-cmd "kafka-broker-api-versions --bootstrap-server localhost:9092"
--health-interval 10s
--health-timeout 10s
--health-retries 10

python-version: ["3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install dependencies
run: |
pip install --upgrade pip setuptools wheel
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Install service check tools

- name: Run tests
run: |
sudo apt-get update
sudo apt-get install -y postgresql-client netcat-openbsd

- name: Wait for services
pytest -m "rest or graphql or grpc" --alluredir=reports/allure-results

- name: Install Allure CLI
if: always()
run: |
timeout 60 bash -c 'until pg_isready -h localhost -p 5432 -U tester; do sleep 1; done'
timeout 60 bash -c 'until nc -z localhost 2181; do sleep 1; done'
sleep 5
timeout 60 bash -c 'until nc -z localhost 9092; do sleep 1; done'

- name: Run tests
wget -q https://github.com/allure-framework/allure2/releases/download/2.24.1/allure-2.24.1.tgz
tar -xzf allure-2.24.1.tgz
sudo mv allure-2.24.1 /opt/allure
sudo ln -s /opt/allure/bin/allure /usr/local/bin/allure

- name: Generate Allure report
if: always()
run: |
pytest -m ${{ matrix.test-suite }} \
--alluredir=reports/allure-results \
--junit-xml=reports/junit-${{ matrix.test-suite }}.xml \
-v
continue-on-error: true

- name: Upload test results
allure generate reports/allure-results --clean -o reports/allure-report || true

- name: Upload Allure results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.test-suite }}
path: |
reports/allure-results
reports/junit-${{ matrix.test-suite }}.xml
retention-days: 7
name: allure-results-${{ matrix.python-version }}
path: reports/allure-results
retention-days: 30

test-all:
- name: Upload Allure report
if: always()
uses: actions/upload-artifact@v4
with:
name: allure-report-${{ matrix.python-version }}
path: reports/allure-report
retention-days: 30

publish-pages:
needs: test
runs-on: ubuntu-latest
needs: [lint]

services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_DB: api_tests
POSTGRES_USER: tester
POSTGRES_PASSWORD: testpass
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

zookeeper:
image: confluentinc/cp-zookeeper:7.5.0
env:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- 2181:2181
options: >-
--health-cmd "nc -z localhost 2181"
--health-interval 10s
--health-timeout 5s
--health-retries 5

kafka:
image: confluentinc/cp-kafka:7.5.0
env:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: localhost:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
ports:
- 9092:9092
options: >-
--health-cmd "kafka-broker-api-versions --bootstrap-server localhost:9092"
--health-interval 10s
--health-timeout 10s
--health-retries 10

if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
permissions:
contents: read
pages: write
id-token: write

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: "3.11"
cache: 'pip'

- name: Install dependencies
run: |
pip install --upgrade pip setuptools wheel
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Install service check tools
run: |
sudo apt-get update
sudo apt-get install -y postgresql-client netcat-openbsd

- name: Wait for services
run: |
timeout 60 bash -c 'until pg_isready -h localhost -p 5432 -U tester; do sleep 1; done'
timeout 60 bash -c 'until nc -z localhost 2181; do sleep 1; done'
sleep 5
timeout 60 bash -c 'until nc -z localhost 9092; do sleep 1; done'

- name: Run all tests
run: |
pytest \
--alluredir=reports/allure-results \
--junit-xml=reports/junit.xml \
-v

- name: Generate Allure report
if: always()
uses: simple-elf/allure-report-action@master
with:
allure_results: reports/allure-results
allure_history: reports/allure-history
keep_reports: 20
continue-on-error: true

- name: Upload Allure report
if: always()
uses: actions/upload-artifact@v4

- name: Download Allure results
uses: actions/download-artifact@v4
with:
name: allure-report
pattern: allure-results-*
merge-multiple: true
path: reports/allure-results
retention-days: 30

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4

- name: Install Allure CLI
run: |
wget -q https://github.com/allure-framework/allure2/releases/download/2.24.1/allure-2.24.1.tgz
tar -xzf allure-2.24.1.tgz
sudo mv allure-2.24.1 /opt/allure
sudo ln -s /opt/allure/bin/allure /usr/local/bin/allure

- name: Generate Allure report
run: |
allure generate reports/allure-results --clean -o reports/allure-report

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
name: test-results
path: reports/junit.xml
retention-days: 30
path: reports/allure-report

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ RUN pip install -e .

CMD ["pytest"]


24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# API Testing Framework

Python фреймворк для тестирования REST, GraphQL, gRPC API и Kafka.
API testing framework in Python: REST, GraphQL, gRPC, Kafka, PostgreSQL, pytest, Allure.

![Python](https://img.shields.io/badge/Python-3.11+-blue)
![pytest](https://img.shields.io/badge/pytest-8.0+-green)
![License](https://img.shields.io/badge/license-MIT-blue)
![CI](https://github.com/Obrams/api_test_python/actions/workflows/ci.yml/badge.svg)

**Topics:** `api-testing` `pytest` `grpc` `kafka` `graphql` `sqlalchemy` `allure`

## Содержание

Expand Down Expand Up @@ -290,6 +293,25 @@ pytest -m "not slow"
pytest -m negative
```

## CI и отчёты

### GitHub Actions

CI автоматически запускает тесты REST, GraphQL и gRPC при каждом push и pull request.

**Статус CI:** [![CI](https://github.com/Obrams/api_test_python/actions/workflows/ci.yml/badge.svg)](https://github.com/Obrams/api_test_python/actions/workflows/ci.yml)

### Allure отчёты

- **Артефакты:** Allure результаты и отчёты доступны в [Actions artifacts](https://github.com/Obrams/api_test_python/actions) после каждого запуска CI
- **GitHub Pages:** Статический Allure отчёт публикуется на [GitHub Pages](https://obrams.github.io/api_test_python/) (только для main/master ветки)

Для скачивания артефактов:
1. Перейти в [Actions](https://github.com/Obrams/api_test_python/actions)
2. Выбрать нужный workflow run
3. Скачать артефакты `allure-results-*` или `allure-report-*`
4. Для просмотра отчёта локально: `allure serve <путь-к-allure-results>`

## API для тестирования

### REST API
Expand Down
1 change: 1 addition & 0 deletions config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@




1 change: 1 addition & 0 deletions graphql/queries/countries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ query GetCountriesByCurrency($currency: String!) {




1 change: 1 addition & 0 deletions graphql/queries/rickmorty.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,4 @@ query SearchCharacters($name: String!) {




1 change: 1 addition & 0 deletions proto/hello.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ message HelloSummary {




1 change: 1 addition & 0 deletions proto/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ message SearchUsersRequest {




2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "api-test-python"
version = "1.0.0"
description = "API Testing Framework: REST, gRPC, GraphQL - 100+ тестов"
description = "API testing framework in Python: REST, GraphQL, gRPC, Kafka, PostgreSQL, pytest, Allure"
readme = "README.md"
requires-python = ">=3.11"
license = {text = "MIT"}
Expand Down
Loading
Loading