Skip to content

Commit

Permalink
Raise NotImplementedError when flavor is not supported (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
peay committed Jan 16, 2023
1 parent 2a1b31c commit b4a987d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repository:
#topics: github, probot

# Either `true` to make the repository private, or `false` to make it public.
private: true
private: false

# Either `true` to enable issues for this repository, `false` to disable them.
has_issues: true
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def _download_aws_rds_ca_bundle(self):
"SQLAlchemy dialects to connect to Amazon RDS instances "
"with IAM authentication"
),
url="https://github.com/cisco-open/sqlalchemy-rdsiam",
long_description=_get_readme_contents(),
long_description_content_type="text/markdown",
packages=["sqlalchemy_rdsiam"],
Expand Down
8 changes: 6 additions & 2 deletions sqlalchemy_rdsiam/dialects.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ def import_dbapi(cls: Type) -> ModuleType:
return dbapi_psycopg2

except ImportError:
from sqlalchemy.dialects.postgresql.base import PGDialect

_has_sqlalchemy_psycopg2 = False

class PGDialect_psycopg2rdsiam: # type: ignore
class PGDialect_psycopg2rdsiam(PGDialect): # type: ignore
@classmethod
def dbapi(cls: Type) -> ModuleType:
return cls.import_dbapi()
Expand Down Expand Up @@ -77,9 +79,11 @@ def import_dbapi(cls: Type) -> ModuleType:
return AsyncAdapt_asyncpg_dbapi(asyncpg=dbapi_asyncpg)

except ImportError:
from sqlalchemy.dialects.postgresql.base import PGDialect

_has_sqlalchemy_asyncpg = False

class PGDialect_asyncpgrdsiam: # type: ignore
class PGDialect_asyncpgrdsiam(PGDialect): # type: ignore
@classmethod
def dbapi(cls: Type) -> ModuleType:
return cls.import_dbapi()
Expand Down
20 changes: 20 additions & 0 deletions tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ def test_connect_region(
)


@pytest.mark.parametrize(
"try_connect_fn,engine_prefix",
[
pytest.param(
"try_connect_sync",
"postgresql+psycopg2rdsiam",
marks=pytest.mark.skipif(
_has_sqlalchemy_psycopg2, reason="psycopg2 is available"
),
)
],
)
def test_dialect_not_available(request, try_connect_fn, engine_prefix):
"""Check that using an unsupported dialect raises the right error."""
try_connect = request.getfixturevalue(try_connect_fn)

with pytest.raises(NotImplementedError):
try_connect(f"{engine_prefix}://some-url")


@pytest.mark.skipif(
not _has_sqlalchemy_psycopg2,
reason="psycopg2 is not supported",
Expand Down

0 comments on commit b4a987d

Please sign in to comment.