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
2 changes: 1 addition & 1 deletion .github/workflows/bkpaas-auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
4 changes: 4 additions & 0 deletions sdks/bkpaas-auth/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 版本历史

## 3.2.0

- 增加对 Django 5.x 版本的支持,并移除对 Python 3.9 版本的支持

## 3.1.3
- feat: 用户模型增加时区支持,新增 time_zone 属性,由认证服务返回时区

Expand Down
19 changes: 16 additions & 3 deletions sdks/bkpaas-auth/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import tempfile

import nox
from nox.command import CommandFailed

ALL_PYTHON = ["3.9", "3.10", "3.11"]
ALL_PYTHON = ["3.10", "3.11", "3.12"]


# ref: https://stackoverflow.com/questions/59768651/how-to-use-nox-with-poetry
Expand Down Expand Up @@ -49,8 +50,20 @@ def tests(session):
install_with_constraints(
session,
"pytest",
"django",
"pytest-django",
"pytest-mock",
)
session.run("pytest", *session.posargs)
# Install the SQLite driver manually because some environment's sqlite3 version is too old
# to meet the Django requirement.
try:
session.install("pysqlite3-binary")
except CommandFailed:
print("pysqlite3-binary installation failed, continuing...")

django_versions = [
">=4.2,<5",
">=5.0,<6",
]
for django in django_versions:
session.install(f"django{django}")
session.run("pytest", *session.posargs)
Comment on lines +67 to +69
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation installs Django versions sequentially in a loop, but this approach may not properly isolate tests between Django versions. Each session.install for a new Django version will overwrite the previous one, which is correct. However, consider adding logging or separating the test runs more explicitly to make it clear which Django version is being tested. Additionally, the tests should ideally fail fast if one Django version fails rather than continuing to test the next version.

Copilot uses AI. Check for mistakes.
8 changes: 4 additions & 4 deletions sdks/bkpaas-auth/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdks/bkpaas-auth/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ classifiers = ["License :: OSI Approved :: MIT License"]
# PEP 621 project metadata
# See https://www.python.org/dev/peps/pep-0621/
name = "bkpaas-auth"
version = "3.1.3"
version = "3.2.0"
description = "User authentication django app for blueking internal projects"
readme = "README.md"
authors = [{ name = "blueking", email = "blueking@tencent.com" }]
license = "MIT"
# classifiers is dynamic because we want to create Python classifiers automatically
dynamic = ["classifiers"]
requires-python = '>=3.9,<4.0'
dependencies = ['django (>=4.2,<5.0)', 'requests', 'six']
requires-python = '>=3.10,<4.0'
dependencies = ['django (>=4.2,<6.0)', 'requests', 'six']

[project.urls]
Homepage = "https://github.com/TencentBlueKing/bkpaas-python-sdk/"
Expand Down
58 changes: 39 additions & 19 deletions sdks/bkpaas-auth/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
# -*- coding: utf-8 -*-
import logging
import sqlite3
import sys

import pytest


def _ensure_sqlite_min_version() -> None:
"""Ensure that the sqlite3 module meets the minimum version requirement."""
minimum_version = (3, 31, 0)
Comment thread
piglei marked this conversation as resolved.
if sqlite3.sqlite_version_info >= minimum_version:
return

try:
import pysqlite3
except ImportError:
return

# Replace sqlite3 module so Django picks up the newer SQLite implementation.
sys.modules["sqlite3"] = pysqlite3
sys.modules["sqlite3.dbapi2"] = pysqlite3.dbapi2


_ensure_sqlite_min_version()


def setup_root_logger(level):
"""Set up the root logger, make it to write messages to stdout"""
root = logging.getLogger()
root.setLevel(level)

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(level)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
root.addHandler(handler)

Expand All @@ -23,36 +43,36 @@ def pytest_configure():
settings.configure(
DEBUG_PROPAGATE_EXCEPTIONS=True,
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": ":memory:",
}
},
SECRET_KEY='not very secret in tests',
SECRET_KEY="not very secret in tests",
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
},
],
USE_TZ=True,
TIME_ZONE='Asia/Shanghai',
TIME_ZONE="Asia/Shanghai",
MIDDLEWARE=[],
MIDDLEWARE_CLASSES=[],
INSTALLED_APPS=(
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'tests',
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"tests",
),
# bkauth settings
BKAUTH_BACKEND_TYPE='bk_token',
BKAUTH_TOKEN_APP_CODE='mock_app_code',
BKAUTH_TOKEN_SECRET_KEY='mock_app_key',
BKAUTH_TOKEN_GRANT_ENDPOINT='',
USER_ID='0221dbef87cd',
USER_NAME='user1',
USER_NICKNAME='user1中文名',
BKAUTH_BACKEND_TYPE="bk_token",
BKAUTH_TOKEN_APP_CODE="mock_app_code",
BKAUTH_TOKEN_SECRET_KEY="mock_app_key",
BKAUTH_TOKEN_GRANT_ENDPOINT="",
USER_ID="0221dbef87cd",
USER_NAME="user1",
USER_NICKNAME="user1中文名",
AUTHENTICATION_BACKENDS=["bkpaas_auth.backends.UniversalAuthBackend"],
)

Expand Down