Files
scylladb/test/cqlpy/test_use.py
Nadav Har'El 8c215141a1 test: rename "cql-pytest" to "cqlpy"
Python and Python developers don't like directory names to include a
minus sign, like "cql-pytest". In this patch we rename test/cql-pytest
to test/cqlpy, and also change a few references in other code (e.g., code
that used test/cql-pytest/run.py) and also references to this test suite
in documentation and comments.

Arguably, the word "test" was always redundant in test/cql-pytest, and
I want to leave the "py" in test/cqlpy to emphasize that it's Python-based
tests, contrasting with test/cql which are CQL-request-only approval
tests.

Fixes #20846

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
2024-11-06 16:48:36 +02:00

35 lines
1.5 KiB
Python

# Copyright 2022-present ScyllaDB
#
# SPDX-License-Identifier: AGPL-3.0-or-later
#############################################################################
# Tests for the "USE" statement, which modifies the default keyspace used
# by subsequent statements.
#
# Note that because the "USE" statement modifies the state of the current
# connection, and there is no way to undo its effects (there is no "UNUSE"
# or way to do an empty "USE"), the following tests should all use a new_cql
# wrapper over the cql fixture, instead of the cql fixture directly. This
# wrapper creates a new connection, with its own default USE.
#############################################################################
import pytest
from cassandra.protocol import InvalidRequest
from util import unique_name, new_cql
# Check that CREATE TABLE and DROP TABLE work without an explicit keyspace
# name if a default keyspace name is specified with "USE".
def test_create_table_use_keyspace(cql, test_keyspace):
with new_cql(cql) as ncql:
ncql.execute(f'USE {test_keyspace}')
table = unique_name()
ncql.execute(f'CREATE TABLE {table} (k int PRIMARY KEY)')
ncql.execute(f'DROP TABLE {table}')
# Check that without a USE, one cannot CREATE TABLE if the keyspace is not
# explicitly specified.
def test_create_table_no_keyspace(cql, test_keyspace):
with new_cql(cql) as ncql:
with pytest.raises(InvalidRequest, match='No keyspace'):
ncql.execute(f'CREATE TABLE {unique_name()} (k int PRIMARY KEY)')