Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loosen cassandra-driver requirement to allow latest version #15022

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ repos:
^airflow/providers/apache/hive/.*README.md$|
^tests/providers/apache/cassandra/hooks/test_cassandra.py$|
^docs/apache-airflow-providers-apache-cassandra/connections/cassandra.rst$|
^docs/apache-airflow-providers-apache-hive/commits.rst$|git|
^docs/apache-airflow-providers-apache-hive/commits.rst$|
git|
^pylintrc |
^CHANGELOG.txt$
- id: consistent-pylint
language: pygrep
Expand Down
2 changes: 2 additions & 0 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ suggestion-mode=yes
# active Python interpreter and may run arbitrary code.
unsafe-load-any-extension=no

# Pylint 2.8 changes this to `extension-pkg-allow-list`
extension-pkg-whitelist=cassandra

[MESSAGES CONTROL]

Expand Down
2 changes: 2 additions & 0 deletions pylintrc-tests
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ suggestion-mode=yes
# active Python interpreter and may run arbitrary code.
unsafe-load-any-extension=no

# Pylint 2.8 changes this to `extension-pkg-allow-list`
extension-pkg-whitelist=cassandra

[MESSAGES CONTROL]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def get_sphinx_theme_version() -> str:
'azure-storage-file>=2.1.0',
]
cassandra = [
'cassandra-driver>=3.13.0,<3.21.0',
'cassandra-driver>=3.13.0,<4',
]
celery = [
'celery~=4.4.2',
Expand Down
25 changes: 11 additions & 14 deletions tests/providers/apache/cassandra/hooks/test_cassandra.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,17 @@ def setUp(self):
hook.shutdown_cluster()

def test_get_conn(self):
with mock.patch.object(Cluster, "connect") as mock_connect, mock.patch(
"socket.getaddrinfo", return_value=[]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous mocking didn't work anymore, but this was to some extend, testing the internals of Cassandra.

I have replaced it with just ensuring we call `Cluster() correctly here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This likely no longer works because cython "caches"/looks up the built in getaddrinfo at compile time, so the mocking has no effect.

) as mock_getaddrinfo:
mock_connect.return_value = 'session'
hook = CassandraHook(cassandra_conn_id='cassandra_test')
hook.get_conn()
assert mock_getaddrinfo.called
mock_connect.assert_called_once_with('test_keyspace')

cluster = hook.get_cluster()
assert cluster.contact_points == ['host-1', 'host-2']
assert cluster.port == 9042
assert cluster.protocol_version == 4
assert isinstance(cluster.load_balancing_policy, TokenAwarePolicy)
with mock.patch.object(Cluster, "__init__") as mock_cluster_ctor:
mock_cluster_ctor.return_value = None
CassandraHook(cassandra_conn_id='cassandra_test')
mock_cluster_ctor.assert_called_once_with(
contact_points=['host-1', 'host-2'],
port=9042,
protocol_version=4,
load_balancing_policy=mock.ANY,
)

assert isinstance(mock_cluster_ctor.call_args[1]['load_balancing_policy'], TokenAwarePolicy)

def test_get_lb_policy_with_no_args(self):
# test LB policies with no args
Expand Down