This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new 815a469  Unit tests jenkins hook (#9767)
815a469 is described below

commit 815a4697dc15c85caee0bba336edf40050ec479f
Author: Kanthi <[email protected]>
AuthorDate: Sun Jul 12 12:41:19 2020 -0400

    Unit tests jenkins hook (#9767)
---
 tests/providers/jenkins/hooks/test_jenkins.py | 60 +++++++++++++++++++++++++++
 tests/test_project_structure.py               |  1 -
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/tests/providers/jenkins/hooks/test_jenkins.py 
b/tests/providers/jenkins/hooks/test_jenkins.py
new file mode 100644
index 0000000..13da3c5
--- /dev/null
+++ b/tests/providers/jenkins/hooks/test_jenkins.py
@@ -0,0 +1,60 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+from unittest import mock
+
+from airflow.providers.jenkins.hooks.jenkins import JenkinsHook
+
+
+class TestJenkinsHook(unittest.TestCase):
+
+    @mock.patch('airflow.hooks.base_hook.BaseHook.get_connection')
+    def test_client_created_default_http(self, get_connection_mock):
+        """ tests `init` method to validate http client creation when all 
parameters are passed """
+        default_connection_id = 'jenkins_default'
+
+        connection_host = 'http://test.com'
+        connection_port = 8080
+        get_connection_mock.return_value = mock. \
+            Mock(connection_id=default_connection_id,
+                 login='test', password='test', extra='',
+                 host=connection_host, port=connection_port)
+
+        complete_url = f'http://{connection_host}:{connection_port}/'
+        hook = JenkinsHook(default_connection_id)
+        self.assertIsNotNone(hook.jenkins_server)
+        self.assertEqual(hook.jenkins_server.server, complete_url)
+
+    @mock.patch('airflow.hooks.base_hook.BaseHook.get_connection')
+    def test_client_created_default_https(self, get_connection_mock):
+        """ tests `init` method to validate https client creation when all
+        parameters are passed """
+        default_connection_id = 'jenkins_default'
+
+        connection_host = 'http://test.com'
+        connection_port = 8080
+        get_connection_mock.return_value = mock. \
+            Mock(connection_id=default_connection_id,
+                 login='test', password='test', extra='true',
+                 host=connection_host, port=connection_port)
+
+        complete_url = f'https://{connection_host}:{connection_port}/'
+        hook = JenkinsHook(default_connection_id)
+        self.assertIsNotNone(hook.jenkins_server)
+        self.assertEqual(hook.jenkins_server.server, complete_url)
diff --git a/tests/test_project_structure.py b/tests/test_project_structure.py
index 1b715cf..2cc0da4 100644
--- a/tests/test_project_structure.py
+++ b/tests/test_project_structure.py
@@ -37,7 +37,6 @@ MISSING_TEST_FILES = {
     'tests/providers/google/cloud/utils/test_field_sanitizer.py',
     'tests/providers/google/cloud/utils/test_field_validator.py',
     'tests/providers/google/cloud/utils/test_mlengine_prediction_summary.py',
-    'tests/providers/jenkins/hooks/test_jenkins.py',
     'tests/providers/microsoft/azure/sensors/test_azure_cosmos.py',
     'tests/providers/microsoft/azure/log/test_wasb_task_handler.py',
     'tests/providers/microsoft/mssql/hooks/test_mssql.py',

Reply via email to