|
1 |
| -import boto3 |
2 |
| -import pretend |
3 |
| - |
4 | 1 | from django_iam_dbauth.aws.postgresql.base import DatabaseWrapper
|
5 | 2 |
|
6 | 3 |
|
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): |
17 | 5 | settings = {
|
18 | 6 | "NAME": "example",
|
19 | 7 | "USER": "postgresql",
|
20 | 8 | "PASSWORD": "secret",
|
21 | 9 | "PORT": 5432,
|
22 | 10 | "HOST": "example-cname.labd.nl",
|
23 | 11 | "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 | + }, |
25 | 17 | }
|
26 | 18 |
|
27 | 19 | db = DatabaseWrapper(settings)
|
28 | 20 | params = db.get_connection_params()
|
29 | 21 |
|
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") |
0 commit comments