You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/09/03 10:08:18 UTC
[GitHub] [airflow] minu7 opened a new pull request #18007: fix Neo4jHook to get the query response
minu7 opened a new pull request #18007:
URL: https://github.com/apache/airflow/pull/18007
It allows to get the answer of the query from the Neo4jHook.
closes: #18005
related: #18005
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] mik-laj commented on a change in pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#discussion_r702141517
##########
File path: tests/providers/neo4j/hooks/test_neo4j.py
##########
@@ -15,51 +15,94 @@
# specific language governing permissions and limitations
# under the License.
#
-import json
import unittest
from unittest import mock
+from parameterized import parameterized
+
from airflow.models import Connection
from airflow.providers.neo4j.hooks.neo4j import Neo4jHook
class TestNeo4jHookConn(unittest.TestCase):
- def setUp(self):
- super().setUp()
- self.neo4j_hook = Neo4jHook()
- self.connection = Connection(
- conn_type='neo4j', login='login', password='password', host='host', schema='schema'
+ @parameterized.expand(
+ [
+ [dict(), "bolt://host:7687"],
+ [{"bolt_scheme": True}, "bolt://host:7687"],
+ [{"certs_self_signed": True, "bolt_scheme": True}, "bolt+ssc://host:7687"],
+ [{"certs_trusted_ca": True, "bolt_scheme": True}, "bolt+s://host:7687"],
+ ]
+ )
+ def test_get_uri_neo4j_scheme(self, conn_extra, expected_uri):
+ connection = Connection(
+ conn_type='neo4j',
+ login='login',
+ password='password',
+ host='host',
+ schema='schema',
+ extra=conn_extra,
)
- def test_get_uri_neo4j_scheme(self):
Review comment:
Thanks to parameterization, we can write the same tests, but with less code duplication, which makes it easier to manage.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] uranusjr commented on pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
uranusjr commented on pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#issuecomment-912428892
Could you add/modify a test (or a couple of them since there are two branches) for this change?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] boring-cyborg[bot] commented on pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#issuecomment-912422666
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:
- Pay attention to the quality of your code (flake8, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/STATIC_CODE_CHECKS.rst#prerequisites-for-pre-commit-hooks) will help you with that.
- In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
- Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/BREEZE.rst) for testing locally, itβs a heavy docker but it ships with a working Airflow and a lot of integrations.
- Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
- Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
- Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#coding-style-and-best-practices).
Apache Airflow is a community-driven project and together we are making it better π.
In case of doubts contact the developers at:
Mailing List: dev@airflow.apache.org
Slack: https://s.apache.org/airflow-slack
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] boring-cyborg[bot] commented on pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#issuecomment-914443813
Awesome work, congrats on your first merged pull request!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] mik-laj commented on a change in pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#discussion_r702141953
##########
File path: tests/providers/neo4j/hooks/test_neo4j.py
##########
@@ -15,51 +15,94 @@
# specific language governing permissions and limitations
# under the License.
#
-import json
import unittest
from unittest import mock
+from parameterized import parameterized
+
from airflow.models import Connection
from airflow.providers.neo4j.hooks.neo4j import Neo4jHook
class TestNeo4jHookConn(unittest.TestCase):
- def setUp(self):
- super().setUp()
- self.neo4j_hook = Neo4jHook()
- self.connection = Connection(
- conn_type='neo4j', login='login', password='password', host='host', schema='schema'
+ @parameterized.expand(
+ [
+ [dict(), "bolt://host:7687"],
+ [{"bolt_scheme": True}, "bolt://host:7687"],
+ [{"certs_self_signed": True, "bolt_scheme": True}, "bolt+ssc://host:7687"],
+ [{"certs_trusted_ca": True, "bolt_scheme": True}, "bolt+s://host:7687"],
+ ]
+ )
+ def test_get_uri_neo4j_scheme(self, conn_extra, expected_uri):
+ connection = Connection(
+ conn_type='neo4j',
+ login='login',
+ password='password',
+ host='host',
+ schema='schema',
+ extra=conn_extra,
)
- def test_get_uri_neo4j_scheme(self):
-
- self.neo4j_hook.get_connection = mock.Mock()
- self.neo4j_hook.get_connection.return_value = self.connection
- uri = self.neo4j_hook.get_uri(self.connection)
-
- assert uri == "bolt://host:7687"
-
- def test_get_uri_bolt_scheme(self):
+ # Use the environment variable mocking to test saving the configuration as a URI and
+ # to avoid mocking Airflow models class
+ with mock.patch.dict('os.environ', AIRFLOW_CONN_NEO4J_DEFAULT=connection.get_uri()):
Review comment:
Mocking connection by env variable is recommended. http://airflow.apache.org/docs/apache-airflow/stable/best-practices.html#mocking-variables-and-connections
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] minu7 commented on pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
minu7 commented on pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#issuecomment-914096396
Sorry for the late reply, the tests look good, thanks π
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] github-actions[bot] commented on pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#issuecomment-914101587
The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] mik-laj commented on a change in pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#discussion_r703311083
##########
File path: tests/providers/neo4j/hooks/test_neo4j.py
##########
@@ -15,51 +15,94 @@
# specific language governing permissions and limitations
# under the License.
#
-import json
import unittest
from unittest import mock
+from parameterized import parameterized
+
from airflow.models import Connection
from airflow.providers.neo4j.hooks.neo4j import Neo4jHook
class TestNeo4jHookConn(unittest.TestCase):
- def setUp(self):
- super().setUp()
- self.neo4j_hook = Neo4jHook()
- self.connection = Connection(
- conn_type='neo4j', login='login', password='password', host='host', schema='schema'
+ @parameterized.expand(
+ [
+ [dict(), "bolt://host:7687"],
Review comment:
I prefer to avoid initializing an empty dictionary with this syntax because it is ambiguous. I always have to wonder if this will make an empty dictionary(``{}==dictt()``) or a set(``{}==set()``).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] mik-laj commented on pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
mik-laj commented on pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#issuecomment-912785861
@minu7 I pushed ttests. Can you look at it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] uranusjr commented on a change in pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#discussion_r703293541
##########
File path: tests/providers/neo4j/hooks/test_neo4j.py
##########
@@ -15,51 +15,94 @@
# specific language governing permissions and limitations
# under the License.
#
-import json
import unittest
from unittest import mock
+from parameterized import parameterized
+
from airflow.models import Connection
from airflow.providers.neo4j.hooks.neo4j import Neo4jHook
class TestNeo4jHookConn(unittest.TestCase):
- def setUp(self):
- super().setUp()
- self.neo4j_hook = Neo4jHook()
- self.connection = Connection(
- conn_type='neo4j', login='login', password='password', host='host', schema='schema'
+ @parameterized.expand(
+ [
+ [dict(), "bolt://host:7687"],
Review comment:
```suggestion
[{}, "bolt://host:7687"],
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] mik-laj commented on a change in pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#discussion_r702140880
##########
File path: tests/providers/neo4j/operators/test_neo4j.py
##########
@@ -46,16 +28,13 @@
class TestNeo4jOperator(unittest.TestCase):
- def setUp(self):
- args = {'owner': 'airflow', 'start_date': DEFAULT_DATE}
- dag = DAG(TEST_DAG_ID, default_args=args)
- self.dag = dag
-
- @mock.patch('airflow.providers.neo4j.operators.neo4j.Neo4jOperator.get_hook')
+ @mock.patch('airflow.providers.neo4j.operators.neo4j.Neo4jHook')
def test_neo4j_operator_test(self, mock_hook):
sql = """
MATCH (tom {name: "Tom Hanks"}) RETURN tom
"""
- op = Neo4jOperator(task_id='basic_neo4j', sql=sql, dag=self.dag)
- op.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True)
Review comment:
This test took an unnecessarily long time - 6 seconds. We need a full run, but running the execute method is enough.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] mik-laj commented on pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
mik-laj commented on pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#issuecomment-914098094
@uranusjr @potiuk Can you look at it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk commented on a change in pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#discussion_r703315158
##########
File path: tests/providers/neo4j/hooks/test_neo4j.py
##########
@@ -15,51 +15,94 @@
# specific language governing permissions and limitations
# under the License.
#
-import json
import unittest
from unittest import mock
+from parameterized import parameterized
+
from airflow.models import Connection
from airflow.providers.neo4j.hooks.neo4j import Neo4jHook
class TestNeo4jHookConn(unittest.TestCase):
- def setUp(self):
- super().setUp()
- self.neo4j_hook = Neo4jHook()
- self.connection = Connection(
- conn_type='neo4j', login='login', password='password', host='host', schema='schema'
+ @parameterized.expand(
+ [
+ [dict(), "bolt://host:7687"],
Review comment:
explicit is better than implicit :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] mik-laj merged pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
mik-laj merged pull request #18007:
URL: https://github.com/apache/airflow/pull/18007
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] mik-laj commented on a change in pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#discussion_r703311083
##########
File path: tests/providers/neo4j/hooks/test_neo4j.py
##########
@@ -15,51 +15,94 @@
# specific language governing permissions and limitations
# under the License.
#
-import json
import unittest
from unittest import mock
+from parameterized import parameterized
+
from airflow.models import Connection
from airflow.providers.neo4j.hooks.neo4j import Neo4jHook
class TestNeo4jHookConn(unittest.TestCase):
- def setUp(self):
- super().setUp()
- self.neo4j_hook = Neo4jHook()
- self.connection = Connection(
- conn_type='neo4j', login='login', password='password', host='host', schema='schema'
+ @parameterized.expand(
+ [
+ [dict(), "bolt://host:7687"],
Review comment:
I prefer to avoid initializing an empty dictionary with this syntax because it is ambiguous. I always have to wonder if this will make an empty dictionary(``{}==dict()``) or a set(``{}==set()``).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] mik-laj commented on a change in pull request #18007: fix Neo4jHook to get the query response
Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #18007:
URL: https://github.com/apache/airflow/pull/18007#discussion_r702140880
##########
File path: tests/providers/neo4j/operators/test_neo4j.py
##########
@@ -46,16 +28,13 @@
class TestNeo4jOperator(unittest.TestCase):
- def setUp(self):
- args = {'owner': 'airflow', 'start_date': DEFAULT_DATE}
- dag = DAG(TEST_DAG_ID, default_args=args)
- self.dag = dag
-
- @mock.patch('airflow.providers.neo4j.operators.neo4j.Neo4jOperator.get_hook')
+ @mock.patch('airflow.providers.neo4j.operators.neo4j.Neo4jHook')
def test_neo4j_operator_test(self, mock_hook):
sql = """
MATCH (tom {name: "Tom Hanks"}) RETURN tom
"""
- op = Neo4jOperator(task_id='basic_neo4j', sql=sql, dag=self.dag)
- op.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True)
Review comment:
This test took an unnecessarily long time - 6 seconds. We need a full run, but running the execute method is enough. This test also lacked assertion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org