Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet committed Mar 12, 2024
1 parent 4696782 commit 78ef1eb
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 20 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/main.yml → .github/workflows/astradb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ on:
- main

jobs:
test:
strategy:
matrix:
mode: [ "ASTRA_DB", "TESTCONTAINERS_CASSANDRA" ]
test-astradb:
env:
ASTRA_DB_APPLICATION_TOKEN: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN }}
ASTRA_DB_DATABASE_ID: ${{ secrets.ASTRA_DB_DATABASE_ID }}
ASTRA_DB_INIT_STRING: ${{ secrets.ASTRA_DB_INIT_STRING }}
ASTRA_DB_KEYSPACE: ${{ secrets.ASTRA_DB_KEYSPACE }}
ASTRA_DB_SECURE_BUNDLE_PATH: ${{ secrets.ASTRA_DB_SECURE_BUNDLE_PATH }}
TEST_DB_MODE: ${{ matrix.mode }}
TEST_DB_MODE: ASTRA_DB
runs-on: ubuntu-latest

steps:
Expand All @@ -40,10 +37,6 @@ jobs:
run: |
python -c 'import os; from cassio.config.bundle_download import download_astra_bundle_url; download_astra_bundle_url(database_id=os.environ["ASTRA_DB_DATABASE_ID"], token=os.environ["ASTRA_DB_APPLICATION_TOKEN"], out_file_path=os.environ["ASTRA_DB_SECURE_BUNDLE_PATH"])'
- name: Unit tests
run: |
pytest tests/unit
- name: Integration tests
run: |
pytest tests/integration
34 changes: 34 additions & 0 deletions .github/workflows/cassandra.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test with Apache Cassandra

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test-cassandra:
env:
CASSANDRA_CONTACT_POINTS: 127.0.0.1
TEST_DB_MODE: TESTCONTAINERS_CASSANDRA
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Integration tests
run: |
pytest tests/integration
31 changes: 31 additions & 0 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test with Astra DB

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
unit-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Integration tests
run: |
pytest tests/unit
1 change: 0 additions & 1 deletion src/cassio/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def init(
contact_points,
username,
password,
cluster_kwargs,
)
):
raise ValueError("When auto=True, no arguments can be passed.")
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ def cassandra_port(db_keyspace):
cassandra.start()
wait_for_logs(cassandra, "Startup complete")
cassandra.get_wrapped_container().exec_run(f'''cqlsh -e "CREATE KEYSPACE {db_keyspace} WITH replication = {{'class': 'SimpleStrategy', 'replication_factor': '1'}};"''')
os.environ["CASSANDRA_CONTACT_POINTS"] = "127.0.0.1"
yield cassandra.get_exposed_port(9042)
cassandra.stop()
else:
yield None
yield 9042


@pytest.fixture(scope="session")
Expand Down
22 changes: 13 additions & 9 deletions tests/integration/test_init_cassandra.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestInitCassandra:
Requires a running (local) Cassandra cluster.
"""

def test_init_session(self):
def test_init_session(self, cassandra_port):
#
_reset_cassio_globals()
assert resolve_session() is None
Expand All @@ -51,9 +51,9 @@ def test_init_session(self):
else:
auth = None
if _cps:
cluster = Cluster(_cps, auth_provider=auth)
cluster = Cluster(_cps, port=cassandra_port, auth_provider=auth)
else:
cluster = Cluster(auth_provider=auth)
cluster = Cluster(port=cassandra_port, auth_provider=auth)
session = cluster.connect()
#
cassio.init(session=session)
Expand All @@ -69,7 +69,7 @@ def test_init_session(self):
assert resolve_session("s") == "s"
assert resolve_keyspace("k") == "k"

def test_init_empty_cps(self):
def test_init_empty_cps(self, cassandra_port):
stolen = _freeze_envvars(["CASSANDRA_CONTACT_POINTS"])
_reset_cassio_globals()
assert resolve_session() is None
Expand All @@ -80,14 +80,15 @@ def test_init_empty_cps(self):
contact_points=CASSANDRA_CONTACT_POINTS or "",
username=CASSANDRA_USERNAME,
password=CASSANDRA_PASSWORD,
cluster_kwargs={"port": cassandra_port},
)
assert resolve_session() is not None
assert resolve_keyspace() is None
assert resolve_session("s") == "s"
assert resolve_keyspace("k") == "k"
_unfreeze_envvars(stolen)

def test_init_cps(self):
def test_init_cps(self, cassandra_port):
_reset_cassio_globals()
assert resolve_session() is None
assert resolve_keyspace() is None
Expand All @@ -97,13 +98,14 @@ def test_init_cps(self):
contact_points=CASSANDRA_CONTACT_POINTS or "127.0.0.1",
username=CASSANDRA_USERNAME,
password=CASSANDRA_PASSWORD,
cluster_kwargs={"port": cassandra_port},
)
assert resolve_session() is not None
assert resolve_keyspace() is None
assert resolve_session("s") == "s"
assert resolve_keyspace("k") == "k"

def test_init_cleaning_cps(self):
def test_init_cleaning_cps(self, cassandra_port):
_reset_cassio_globals()
assert resolve_session() is None
assert resolve_keyspace() is None
Expand All @@ -113,13 +115,14 @@ def test_init_cleaning_cps(self):
contact_points=(CASSANDRA_CONTACT_POINTS or "127.0.0.1") + ",,,, , ",
username=CASSANDRA_USERNAME,
password=CASSANDRA_PASSWORD,
cluster_kwargs={"port": cassandra_port},
)
assert resolve_session() is not None
assert resolve_keyspace() is None
assert resolve_session("s") == "s"
assert resolve_keyspace("k") == "k"

def test_init_with_keyspace(self):
def test_init_with_keyspace(self, cassandra_port):
_reset_cassio_globals()
assert resolve_session() is None
assert resolve_keyspace() is None
Expand All @@ -130,13 +133,14 @@ def test_init_with_keyspace(self):
username=CASSANDRA_USERNAME,
password=CASSANDRA_PASSWORD,
keyspace=CASSANDRA_KEYSPACE,
cluster_kwargs={"port": cassandra_port},
)
assert resolve_session() is not None
assert resolve_keyspace() == CASSANDRA_KEYSPACE
assert resolve_session("s") == "s"
assert resolve_keyspace("k") == "k"

def test_init_auto(self):
def test_init_auto(self, cassandra_port):
_reset_cassio_globals()
stolen = _freeze_envvars(
[
Expand All @@ -147,7 +151,7 @@ def test_init_auto(self):
"ASTRA_DB_DATABASE_ID",
]
)
cassio.init(auto=True)
cassio.init(auto=True, cluster_kwargs={"port": cassandra_port})
assert resolve_session() is not None
assert resolve_keyspace() == os.environ.get("CASSANDRA_KEYSPACE")
assert resolve_session("s") == "s"
Expand Down

0 comments on commit 78ef1eb

Please sign in to comment.