Skip to content

Commit 47e5a91

Browse files
authored
feat: bkpaas-auth supports django 5.x (#251)
1 parent 9fa3182 commit 47e5a91

6 files changed

Lines changed: 67 additions & 30 deletions

File tree

.github/workflows/bkpaas-auth.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
strategy:
3939
fail-fast: false
4040
matrix:
41-
python-version: ["3.9", "3.10", "3.11"]
41+
python-version: ["3.10", "3.11", "3.12"]
4242
os: [ubuntu-latest, macos-latest]
4343
runs-on: ${{ matrix.os }}
4444
steps:

sdks/bkpaas-auth/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 版本历史
22

3+
## 3.2.0
4+
5+
- 增加对 Django 5.x 版本的支持,并移除对 Python 3.9 版本的支持
6+
37
## 3.1.3
48
- feat: 用户模型增加时区支持,新增 time_zone 属性,由认证服务返回时区
59

sdks/bkpaas-auth/noxfile.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import tempfile
33

44
import nox
5+
from nox.command import CommandFailed
56

6-
ALL_PYTHON = ["3.9", "3.10", "3.11"]
7+
ALL_PYTHON = ["3.10", "3.11", "3.12"]
78

89

910
# ref: https://stackoverflow.com/questions/59768651/how-to-use-nox-with-poetry
@@ -49,8 +50,20 @@ def tests(session):
4950
install_with_constraints(
5051
session,
5152
"pytest",
52-
"django",
5353
"pytest-django",
5454
"pytest-mock",
5555
)
56-
session.run("pytest", *session.posargs)
56+
# Install the SQLite driver manually because some environment's sqlite3 version is too old
57+
# to meet the Django requirement.
58+
try:
59+
session.install("pysqlite3-binary")
60+
except CommandFailed:
61+
print("pysqlite3-binary installation failed, continuing...")
62+
63+
django_versions = [
64+
">=4.2,<5",
65+
">=5.0,<6",
66+
]
67+
for django in django_versions:
68+
session.install(f"django{django}")
69+
session.run("pytest", *session.posargs)

sdks/bkpaas-auth/poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdks/bkpaas-auth/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ classifiers = ["License :: OSI Approved :: MIT License"]
55
# PEP 621 project metadata
66
# See https://www.python.org/dev/peps/pep-0621/
77
name = "bkpaas-auth"
8-
version = "3.1.3"
8+
version = "3.2.0"
99
description = "User authentication django app for blueking internal projects"
1010
readme = "README.md"
1111
authors = [{ name = "blueking", email = "blueking@tencent.com" }]
1212
license = "MIT"
1313
# classifiers is dynamic because we want to create Python classifiers automatically
1414
dynamic = ["classifiers"]
15-
requires-python = '>=3.9,<4.0'
16-
dependencies = ['django (>=4.2,<5.0)', 'requests', 'six']
15+
requires-python = '>=3.10,<4.0'
16+
dependencies = ['django (>=4.2,<6.0)', 'requests', 'six']
1717

1818
[project.urls]
1919
Homepage = "https://github.com/TencentBlueKing/bkpaas-python-sdk/"

sdks/bkpaas-auth/tests/conftest.py

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
11
# -*- coding: utf-8 -*-
22
import logging
3+
import sqlite3
34
import sys
45

56
import pytest
67

78

9+
def _ensure_sqlite_min_version() -> None:
10+
"""Ensure that the sqlite3 module meets the minimum version requirement."""
11+
minimum_version = (3, 31, 0)
12+
if sqlite3.sqlite_version_info >= minimum_version:
13+
return
14+
15+
try:
16+
import pysqlite3
17+
except ImportError:
18+
return
19+
20+
# Replace sqlite3 module so Django picks up the newer SQLite implementation.
21+
sys.modules["sqlite3"] = pysqlite3
22+
sys.modules["sqlite3.dbapi2"] = pysqlite3.dbapi2
23+
24+
25+
_ensure_sqlite_min_version()
26+
27+
828
def setup_root_logger(level):
929
"""Set up the root logger, make it to write messages to stdout"""
1030
root = logging.getLogger()
1131
root.setLevel(level)
1232

1333
handler = logging.StreamHandler(sys.stdout)
1434
handler.setLevel(level)
15-
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
35+
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
1636
handler.setFormatter(formatter)
1737
root.addHandler(handler)
1838

@@ -23,36 +43,36 @@ def pytest_configure():
2343
settings.configure(
2444
DEBUG_PROPAGATE_EXCEPTIONS=True,
2545
DATABASES={
26-
'default': {
27-
'ENGINE': 'django.db.backends.sqlite3',
28-
'NAME': ':memory:',
46+
"default": {
47+
"ENGINE": "django.db.backends.sqlite3",
48+
"NAME": ":memory:",
2949
}
3050
},
31-
SECRET_KEY='not very secret in tests',
51+
SECRET_KEY="not very secret in tests",
3252
TEMPLATES=[
3353
{
34-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
35-
'APP_DIRS': True,
54+
"BACKEND": "django.template.backends.django.DjangoTemplates",
55+
"APP_DIRS": True,
3656
},
3757
],
3858
USE_TZ=True,
39-
TIME_ZONE='Asia/Shanghai',
59+
TIME_ZONE="Asia/Shanghai",
4060
MIDDLEWARE=[],
4161
MIDDLEWARE_CLASSES=[],
4262
INSTALLED_APPS=(
43-
'django.contrib.auth',
44-
'django.contrib.contenttypes',
45-
'django.contrib.sessions',
46-
'tests',
63+
"django.contrib.auth",
64+
"django.contrib.contenttypes",
65+
"django.contrib.sessions",
66+
"tests",
4767
),
4868
# bkauth settings
49-
BKAUTH_BACKEND_TYPE='bk_token',
50-
BKAUTH_TOKEN_APP_CODE='mock_app_code',
51-
BKAUTH_TOKEN_SECRET_KEY='mock_app_key',
52-
BKAUTH_TOKEN_GRANT_ENDPOINT='',
53-
USER_ID='0221dbef87cd',
54-
USER_NAME='user1',
55-
USER_NICKNAME='user1中文名',
69+
BKAUTH_BACKEND_TYPE="bk_token",
70+
BKAUTH_TOKEN_APP_CODE="mock_app_code",
71+
BKAUTH_TOKEN_SECRET_KEY="mock_app_key",
72+
BKAUTH_TOKEN_GRANT_ENDPOINT="",
73+
USER_ID="0221dbef87cd",
74+
USER_NAME="user1",
75+
USER_NICKNAME="user1中文名",
5676
AUTHENTICATION_BACKENDS=["bkpaas_auth.backends.UniversalAuthBackend"],
5777
)
5878

0 commit comments

Comments
 (0)