Skip to content

Commit c5a72ac

Browse files
committed
chore: just simplify
1 parent 023595a commit c5a72ac

File tree

8 files changed

+82
-104
lines changed

8 files changed

+82
-104
lines changed

.github/workflows/python-tests.yml

+7-35
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,23 @@ name: Python Tests
33
on: [push]
44

55
jobs:
6-
format:
7-
runs-on: ubuntu-latest
8-
steps:
9-
- uses: actions/checkout@v4
10-
11-
- name: Install the latest version of rye
12-
uses: eifinger/setup-rye@v4
13-
14-
- name: Validate formatting
15-
run: rye format --check
16-
176
test:
187
runs-on: ubuntu-latest
19-
needs: format
20-
strategy:
21-
max-parallel: 4
22-
matrix:
23-
tox_env:
24-
- py38-django42
25-
- py312-django42
26-
- py312-django50
27-
- py312-django51
28-
include:
29-
- python-version: 3.8
30-
tox_env: py38-django42
31-
- python-version: 3.12
32-
tox_env: py312-django42
33-
- python-version: 3.12
34-
tox_env: py312-django50
35-
- python-version: 3.12
36-
tox_env: py312-django51
37-
388
steps:
399
- uses: actions/checkout@v4
40-
- name: Set up Python ${{ matrix.python-version }}
41-
10+
- name: Set up Python
4211
uses: actions/setup-python@v5
4312
with:
44-
python-version: "${{ matrix.python-version }}"
13+
python-version: "3.12"
4514

4615
- name: Install the latest version of rye
4716
uses: eifinger/setup-rye@v4
4817

4918
- name: Install dependencies
5019
run: rye sync
5120

52-
- name: Test with tox
53-
run: rye run tox -e ${{ matrix.tox_env }}
21+
- name: Validate formatting
22+
run: rye format --check
23+
24+
- name: Test
25+
run: rye test

pyproject.toml

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ dev-dependencies = [
3939
"coverage>=7.6.1",
4040
"tox>=4.18.0",
4141
"tox-gh-actions>=3.2.0",
42+
"pretend>=1.0.9",
43+
"psycopg2>=2.9.9",
44+
"mysqlclient>=2.2.4",
45+
"pytest-mock>=3.14.0",
46+
"pytest-django>=4.8.0",
47+
"moto>=5.0.13",
4248
]
4349

4450
[build-system]

requirements-dev.lock

+41
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,26 @@ asgiref==3.8.1
1414
# via django
1515
boto3==1.35.0
1616
# via django-iam-dbauth
17+
# via moto
1718
botocore==1.35.0
1819
# via boto3
20+
# via moto
1921
# via s3transfer
2022
cachetools==5.5.0
2123
# via tox
24+
certifi==2024.7.4
25+
# via requests
26+
cffi==1.17.0
27+
# via cryptography
2228
chardet==5.2.0
2329
# via tox
30+
charset-normalizer==3.3.2
31+
# via requests
2432
colorama==0.4.6
2533
# via tox
2634
coverage==7.6.1
35+
cryptography==43.0.0
36+
# via moto
2737
distlib==0.3.8
2838
# via virtualenv
2939
django==5.1
@@ -33,11 +43,20 @@ dnspython==2.6.1
3343
filelock==3.15.4
3444
# via tox
3545
# via virtualenv
46+
idna==3.7
47+
# via requests
3648
iniconfig==2.0.0
3749
# via pytest
50+
jinja2==3.1.4
51+
# via moto
3852
jmespath==1.0.1
3953
# via boto3
4054
# via botocore
55+
markupsafe==2.1.5
56+
# via jinja2
57+
# via werkzeug
58+
moto==5.0.13
59+
mysqlclient==2.2.4
4160
packaging==24.1
4261
# via pyproject-api
4362
# via pytest
@@ -48,11 +67,27 @@ platformdirs==4.2.2
4867
pluggy==1.5.0
4968
# via pytest
5069
# via tox
70+
pretend==1.0.9
71+
psycopg2==2.9.9
72+
pycparser==2.22
73+
# via cffi
5174
pyproject-api==1.7.1
5275
# via tox
5376
pytest==8.3.2
77+
# via pytest-django
78+
# via pytest-mock
79+
pytest-django==4.8.0
80+
pytest-mock==3.14.0
5481
python-dateutil==2.9.0.post0
5582
# via botocore
83+
# via moto
84+
pyyaml==6.0.2
85+
# via responses
86+
requests==2.32.3
87+
# via moto
88+
# via responses
89+
responses==0.25.3
90+
# via moto
5691
s3transfer==0.10.2
5792
# via boto3
5893
six==1.16.0
@@ -64,5 +99,11 @@ tox==4.18.0
6499
tox-gh-actions==3.2.0
65100
urllib3==2.2.2
66101
# via botocore
102+
# via requests
103+
# via responses
67104
virtualenv==20.26.3
68105
# via tox
106+
werkzeug==3.0.3
107+
# via moto
108+
xmltodict==0.13.0
109+
# via moto

src/django_iam_dbauth/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def resolve_cname(hostname):
1414
Looking for the endpoint which is of the form cluster-name.accountandregionhash.regionid.rds.amazonaws.com
1515
To do so, recursively resolve the host name until it's a subdomain of rds.amazonaws.com.
1616
"""
17+
breakpoint()
1718
base_domain = dns.name.from_text("rds.amazonaws.com")
1819
answer = dns.name.from_text(hostname)
1920
while not answer.is_subdomain(base_domain):

tests/conftest.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from django.conf import settings
2+
from moto import mock_aws
3+
import boto3
4+
import pytest
25

36

47
def pytest_configure():
@@ -36,3 +39,12 @@ def pytest_configure():
3639
USE_TZ=True,
3740
ROOT_URLCONF="test_urls",
3841
)
42+
43+
44+
@pytest.fixture
45+
def rds_client():
46+
# Use moto to mock the RDS client
47+
with mock_aws():
48+
session = boto3.session.Session()
49+
client = session.client(service_name="rds", region_name="us-west-2")
50+
yield client

tests/test_aws_mysql.py

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
import boto3
2+
import urllib
23
import pretend
34

45
from django_iam_dbauth.aws.mysql.base import DatabaseWrapper
56

67

7-
def test_get_connection_params(mocker):
8-
token_kwargs = {}
9-
10-
def generate_db_auth_token(**kwargs):
11-
token_kwargs.update(kwargs)
12-
return "generated-token"
13-
14-
client = pretend.stub(generate_db_auth_token=generate_db_auth_token)
15-
mocker.patch.object(boto3, "client", return_value=client)
16-
8+
def test_get_connection_params(rds_client):
179
settings = {
1810
"NAME": "example",
1911
"USER": "mysql",
2012
"PASSWORD": "secret",
2113
"PORT": 3306,
2214
"HOST": "example-cname.labd.nl",
2315
"ENGINE": "django_iam_dbauth.aws.mysql",
24-
"OPTIONS": {"use_iam_auth": 1, "region_name": "test"},
16+
"OPTIONS": {
17+
"use_iam_auth": 1,
18+
"region_name": "test",
19+
"resolve_cname_enabled": False,
20+
},
2521
}
2622

2723
db = DatabaseWrapper(settings)
2824
params = db.get_connection_params()
2925

30-
assert params["password"] == "generated-token"
31-
assert token_kwargs == {
32-
"DBHostname": "cluster-name.accountandregionhash.eu-west-1.rds.amazonaws.com",
33-
"DBUsername": "mysql",
34-
"Port": 3306,
35-
}
26+
assert params["password"].startswith("example-cname.labd.nl")

tests/test_aws_postgresql.py

+7-27
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,22 @@
1-
import boto3
2-
import pretend
3-
41
from django_iam_dbauth.aws.postgresql.base import DatabaseWrapper
52

63

7-
def test_get_connection_params(mocker):
8-
token_kwargs = {}
9-
10-
def generate_db_auth_token(**kwargs):
11-
token_kwargs.update(kwargs)
12-
return "generated-token"
13-
14-
client = pretend.stub(generate_db_auth_token=generate_db_auth_token)
15-
mocker.patch.object(boto3, "client", return_value=client)
16-
4+
def test_get_connection_params(rds_client):
175
settings = {
186
"NAME": "example",
197
"USER": "postgresql",
208
"PASSWORD": "secret",
219
"PORT": 5432,
2210
"HOST": "example-cname.labd.nl",
2311
"ENGINE": "django_iam_dbauth.aws.postgresql",
24-
"OPTIONS": {"use_iam_auth": 1, "region_name": "test"},
12+
"OPTIONS": {
13+
"use_iam_auth": 1,
14+
"region_name": "test",
15+
"resolve_cname_enabled": False,
16+
},
2517
}
2618

2719
db = DatabaseWrapper(settings)
2820
params = db.get_connection_params()
2921

30-
expected = {
31-
"database": "example",
32-
"user": "postgresql",
33-
"password": "generated-token",
34-
"port": 5432,
35-
"host": "example-cname.labd.nl",
36-
}
37-
assert params == expected
38-
assert token_kwargs == {
39-
"DBHostname": "cluster-name.accountandregionhash.eu-west-1.rds.amazonaws.com",
40-
"DBUsername": "postgresql",
41-
"Port": 5432,
42-
}
22+
assert params["password"].startswith("example-cname.labd.nl")

tox.ini

-25
This file was deleted.

0 commit comments

Comments
 (0)