Skip to content

Commit

Permalink
Merge pull request #19 from jokester/upgrade-pytest
Browse files Browse the repository at this point in the history
simplify config & tune logging & revive tests
  • Loading branch information
jokester authored Jun 14, 2024
2 parents e769fdc + 23db6dc commit 034294f
Show file tree
Hide file tree
Showing 39 changed files with 712 additions and 363 deletions.
20 changes: 16 additions & 4 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@ SECRET_KEY=CHANGE_ME
# 【请修改】管理员邮箱,第一次启动会创建此账号,默认密码为 123123,请及时修改密码!
# 之后每次程序启动时,会将此账号设置为管理员
ADMIN_EMAIL=[email protected]
# initial password for auto-created admin user
ADMIN_INITIAL_PASSWORD=

# Database
# MONGODB_URI="" # takes precedence over other MONGODB_* entries
# MONGODB_DB_NAME=moeflow
# MONGODB_USER=moeflow
# MONGODB_PASS=CHANGE_ME

# Job Queue
# CELERY_BROKER_URL="" # takes precedence over other RABBITMQ_* entries
# RABBITMQ_USER=moeflow
# RABBITMQ_PASS=CHANGE_ME
# RABBITMQ_VHOST_NAME=moeflow

# APP 专用的 MongoDB 数据库名称
MONGODB_DB_NAME=moeflow

# -----------
# Storage 配置
# -----------
# 目前支持 LOCAL_STORAGE 和 OSS 和 OPENDAL
# 目前支持 LOCAL_STORAGE 和 OSS
STORAGE_TYPE=LOCAL_STORAGE
# STORAGE_DOMAIN: 返回给客户端的图片URL前缀
# 1. 如果STORAGE_TYPE为OSS
Expand All @@ -41,7 +53,7 @@ OSS_PROCESS_COVER_NAME=cover
OSS_PROCESS_SAFE_CHECK_NAME=safe-check

# -----------
# CDN 配置
# CDN 配置
# -----------
# 如果绑定了 CDN 来加速 OSS,且开启了 CDN 的[阿里云 OSS 私有 Bucket 回源]和[URL 鉴权],
# 此时需要设置 OSS_VIA_CDN = True,并设置 CDN URL 鉴权主/备 KEY
Expand Down
77 changes: 77 additions & 0 deletions .env.test.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Env variables for tests
TESTING=YES
LOG_LEVEL=DEBUG
SITE_NAME=萌翻TEST
SECRET_KEY=SECRET
[email protected]

MONGODB_URI="mongodb://moeflow:[email protected]:27017/moeflow_test?authSource=admin"
# MONGODB_DB_NAME=moeflow
# MONGODB_USER=moeflow
# MONGODB_PASS=CHANGE_ME
CELERY_BROKER_URL="amqp://moeflow:[email protected]:5672/moeflow" # takes precedence over other RABBITMQ_* entries
# RABBITMQ_USER=moeflow
# RABBITMQ_PASS=CHANGE_ME
# RABBITMQ_VHOST_NAME=moeflow_test

# Storage
STORAGE_TYPE=LOCAL_STORAGE
# STORAGE_DOMAIN: 返回给客户端的图片URL前缀
# 1. 如果STORAGE_TYPE为OSS
# - 未设置自定义域名则填写阿里云提供的 OSS 域名,格式如:https://<your-bucket-name>.<oss-region>.aliyuncs.com/
# - 如果绑定了 CDN 来加速 OSS,则填写绑定在 CDN 的域名
# 2. 如果STORAGE_TYPE为LOCAL_STORAGE
# - 本地储存填写绑定到服务器的域名+"/storage/",格式如:http(s)://<your-domain>.com/storage/,
# 3. 如果STORAGE_TYPE为OPENDAL: 不生效 (图片URL将由OPENDAL_STORAGE_PROVIDER决定)
STORAGE_DOMAIN=http://127.0.0.1:5000/storage/
# (可不修改) 允许上传文件的最大大小(MB),默认 1GB
MAX_CONTENT_LENGTH_MB=1024

## OSS_*: STORAGE_TYPE为OSS时的配置
OSS_ACCESS_KEY_ID=
OSS_ACCESS_KEY_SECRET=
# OSS Endpoint(地域节点)
# 含协议名,形如 https://oss-cn-shanghai.aliyuncs.com/
OSS_ENDPOINT=
OSS_BUCKET_NAME=
# (可不修改) OSS 图片处理规则名称
OSS_PROCESS_COVER_NAME=cover
OSS_PROCESS_SAFE_CHECK_NAME=safe-check

# -----------
# CDN 配置
# -----------
# 如果绑定了 CDN 来加速 OSS,且开启了 CDN 的[阿里云 OSS 私有 Bucket 回源]和[URL 鉴权],
# 此时需要设置 OSS_VIA_CDN = True,并设置 CDN URL 鉴权主/备 KEY
OSS_VIA_CDN=True
CDN_URL_KEY_A=
CDN_URL_KEY_B=

# -----------
# Email 配置
# -----------
# 是否发送用户邮件(验证码等)
ENABLE_USER_EMAIL=False
# 是否发送日志邮件
ENABLE_LOG_EMAIL=False
# SMTP 服务器地址
EMAIL_SMTP_HOST=
# SMTP 服务器端口
EMAIL_SMTP_PORT=
# 是否使用 SSL 连接 SMTP 服务器
EMAIL_USE_SSL=True
# 发件邮箱地址
EMAIL_ADDRESS=
# SMTP 服务器登陆用户名,通常是邮箱全称
EMAIL_USERNAME=
# SMTP 服务器登陆密码
EMAIL_PASSWORD=
# 用户回信邮箱地址
EMAIL_REPLY_ADDRESS=
# 网站错误报告邮箱地址
EMAIL_ERROR_ADDRESS=

# Options for non default features. only enable if you know what you are doing.
# CELERY_BROKER_URL="amqp://moeflow:PLEASE_CHANGE_THIS@moeflow-rabbitmq:5672/moeflow"
# CELERY_BACKEND_URL='mongodb://moeflow:PLEASE_CHANGE_THIS@moeflow-mongodb:27017/moeflow?authSource=admin'
# MIT_STORAGE_ROOT=/app/storage
30 changes: 29 additions & 1 deletion .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
workflow_dispatch:

jobs:
check-pr:
static-check:
runs-on: ubuntu-latest

steps:
Expand All @@ -17,3 +17,31 @@ jobs:
- run: pip install -r requirements.txt
- run: ruff check .
- run: ruff format --diff .

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: docker-compose -f tests/deps.yaml up -d
- uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
- run: pip install -r requirements.txt
- run: cp -rv .env.test.sample .env.test
- uses: pavelzw/pytest-action@v2
with:
emoji: false
verbose: true
job-summary: true
- uses: codecov/[email protected]
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
# XXX: can't if (SECRET_DEFINED) for this step
- name: save test report
uses: actions/upload-artifact@v4
if: always()
with:
name: report.html
path: report.html
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
/report.html
htmlcov/
.tox/
.coverage
Expand Down Expand Up @@ -80,7 +81,8 @@ celerybeat-schedule
*.sage.py

# dotenv
.env
.env*
!.*.sample

# virtualenv
.venv
Expand Down Expand Up @@ -117,4 +119,4 @@ gen
/files/tmp/

# 储存文件
/storage/*
/storage/*
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
PYTEST_COV_ARGS =

FORCE: ;

create-venv:
python3.10 -mvenv venv

deps:
venv/bin/pip install -r requirements.txt

remove-venv: FORCE
rm -rf venv

recreate-venv: remove-venv create-venv

lint:
venv/bin/ruff check

lint-fix:
venv/bin/ruff --fix

format:
venv/bin/ruff format

requirements.txt: deps-top.txt recreate-venv
venv/bin/pip install -r deps-top.txt
echo '# GENERATED: run make requirements.txt to recreate lock file' > requirements.txt
venv/bin/pipdeptree --freeze >> requirements.txt

test: test_all

test_all:
venv/bin/pytest

test_all_parallel:
# TODO: fix this
venv/bin/pytest -n 8

test_single:
venv/bin/pytest tests/api/test_file_api.py

test_logging:
#--capture=no
venv/bin/pytest --capture=sys --log-cli-level=DEBUG tests/base/test_logging.py
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 萌翻[MoeFlow]后端项目

[![codecov](https://codecov.io/gh/moeflow-com/moeflow-backend/graph/badge.svg?token=LQJBLB495F)](https://codecov.io/gh/moeflow-com/moeflow-backend)

由于此版本调整了部分 API 接口, **请配合萌翻前端 Version.1.0.1 版本使用!** 直接使用旧版可能在修改(创建)团队和项目时报错。

此版本需配置 **阿里云 OSS** 作为文件存储。如果需要使用其他文件存储方式,可以选择使用以下的分支版本:
Expand Down
Loading

0 comments on commit 034294f

Please sign in to comment.