Skip to content

Commit

Permalink
Fix ssl tests when PG supports SSL
Browse files Browse the repository at this point in the history
  • Loading branch information
grigi committed Dec 3, 2019
1 parent 468444a commit f3ea664
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,21 @@ async def test_schema(self):

async def test_ssl_true(self):
self.db_config["connections"]["models"]["credentials"]["ssl"] = True
with self.assertRaises(ConnectionError):
try:
await Tortoise.init(self.db_config)
except (ConnectionError, ssl.SSLCertVerificationError):
pass
else:
self.assertFalse(True, "Expected ConnectionError or SSLCertVerificationError")

async def test_ssl_custom(self):
# Expect connectionerror or pass
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

self.db_config["connections"]["models"]["credentials"]["ssl"] = ctx
with self.assertRaises(ConnectionError):
await Tortoise.init(self.db_config)
try:
await Tortoise.init(self.db_config, _create_db=True)
except ConnectionError:
pass

0 comments on commit f3ea664

Please sign in to comment.