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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]