mirror of https://github.com/doccano/doccano.git
pythondatasetnatural-language-processingdata-labelingmachine-learningannotation-tooldatasetsactive-learningtext-annotation
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1003 B
35 lines
1003 B
from contextlib import contextmanager
|
|
from importlib import reload
|
|
from os import environ
|
|
|
|
from django.test import TestCase
|
|
|
|
from app import settings
|
|
|
|
|
|
class TestDatabaseUrl(TestCase):
|
|
def test_sslmode_defaults_to_required(self):
|
|
with setenv('DATABASE_URL', 'pgsql://u:p@h/d'):
|
|
self._assert_sslmode_is('require')
|
|
|
|
def test_sslmode_not_set_for_sqlite(self):
|
|
with setenv('DATABASE_URL', 'sqlite:///some/path'):
|
|
self._assert_sslmode_is(None)
|
|
|
|
def test_sslmode_can_be_set_via_database_url(self):
|
|
with setenv('DATABASE_URL', 'pgsql://u:p@h/d?sslmode=disabled'), \
|
|
setenv('IS_HEROKU', 'False'):
|
|
self._assert_sslmode_is('disabled')
|
|
|
|
def _assert_sslmode_is(self, expected):
|
|
reload(settings)
|
|
actual = settings.DATABASES['default'].get('OPTIONS', {}).get('sslmode')
|
|
self.assertEqual(actual, expected)
|
|
|
|
|
|
@contextmanager
|
|
def setenv(key, value):
|
|
environ[key] = value
|
|
yield
|
|
del environ[key]
|
|
|