|
2 | 2 | import time |
3 | 3 |
|
4 | 4 | import psycopg |
5 | | - |
6 | 5 | import pytest |
| 6 | +from django.conf import settings |
7 | 7 | from django.db import connection |
8 | 8 | from django.db.utils import OperationalError |
9 | 9 | from django.test import override_settings |
10 | | -from django.conf import settings |
11 | 10 |
|
12 | 11 | from ansible_base.lib.utils.db import ( |
13 | 12 | advisory_lock, |
14 | 13 | get_pg_notify_params, |
15 | 14 | migrations_are_complete, |
16 | | - psycopg_kwargs_from_settings_dict, |
17 | 15 | psycopg_conn_string_from_settings_dict, |
| 16 | + psycopg_kwargs_from_settings_dict, |
18 | 17 | ) |
19 | 18 |
|
20 | 19 |
|
@@ -90,31 +89,45 @@ def test_psycopg_kwargs_from_settings_dict(self): |
90 | 89 | psycopg_params = self._trim_python_objects(psycopg_kwargs_from_settings_dict(test_dict)) |
91 | 90 | assert psycopg_params == self.PSYCOPG_KWARGS |
92 | 91 |
|
| 92 | + def test_psycopg_kwargs_use(self): |
| 93 | + "This assures that the data we get for the kwargs are usable, and demos how to use" |
| 94 | + if connection.vendor == 'sqlite': |
| 95 | + pytest.skip('Test needs to connect to postgres which is not running') |
| 96 | + |
| 97 | + test_dict = settings.DATABASES['default'].copy() |
| 98 | + test_dict['OPTIONS'] = {'autocommit': True} |
| 99 | + with override_settings(USE_TZ=False): |
| 100 | + psycopg_params = self._trim_python_objects(psycopg_kwargs_from_settings_dict(test_dict)) |
| 101 | + |
| 102 | + psycopg.connect(**psycopg_params) |
| 103 | + |
93 | 104 | def test_listener_string_production(self): |
94 | 105 | "This is a test to correspond to PG_NOTIFY_DSN_SERVER type settings in eda-server" |
95 | | - args = psycopg_conn_string_from_settings_dict( |
96 | | - { |
97 | | - "ENGINE": "django.db.backends.postgresql", |
98 | | - "HOST": "127.0.0.1", |
99 | | - "PORT": 5432, |
100 | | - "USER": "postgres", |
101 | | - "PASSWORD": "DB_PASSWORD", |
102 | | - "NAME": "eda", |
103 | | - "TIME_ZONE": settings.DATABASES['default']['TIME_ZONE'], |
104 | | - "OPTIONS": { |
105 | | - "sslmode": "allow", |
106 | | - "sslcert": "", |
107 | | - "sslkey": "", |
108 | | - "sslrootcert": "", |
109 | | - }, |
110 | | - } |
111 | | - ) |
| 106 | + with override_settings(USE_TZ=False): |
| 107 | + args = psycopg_conn_string_from_settings_dict( |
| 108 | + { |
| 109 | + "ENGINE": "django.db.backends.postgresql", |
| 110 | + "HOST": "127.0.0.1", |
| 111 | + "PORT": 5432, |
| 112 | + "USER": "postgres", |
| 113 | + "PASSWORD": "DB_PASSWORD", |
| 114 | + "NAME": "eda", |
| 115 | + "OPTIONS": { |
| 116 | + "sslmode": "allow", |
| 117 | + "sslcert": "", |
| 118 | + "sslkey": "", |
| 119 | + "sslrootcert": "", |
| 120 | + }, |
| 121 | + } |
| 122 | + ) |
112 | 123 | assert args == ( |
113 | 124 | "dbname=eda sslmode=allow sslcert='' sslkey='' sslrootcert='' client_encoding=UTF8 user=postgres password=DB_PASSWORD host=127.0.0.1 port=5432" |
114 | 125 | ) |
115 | 126 |
|
116 | 127 | def test_listener_string_production_use(self): |
117 | 128 | "This assures that the data we get for the connection string is usable, and demos how to use" |
| 129 | + if connection.vendor == 'sqlite': |
| 130 | + pytest.skip('Test needs to connect to postgres which is not running') |
118 | 131 | args = psycopg_conn_string_from_settings_dict(settings.DATABASES['default']) |
119 | 132 | psycopg.connect(conninfo=args) |
120 | 133 |
|
|
0 commit comments