Skip to content

Commit

Permalink
Unit tests jenkins hook (#9767)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 815a4697dc15c85caee0bba336edf40050ec479f
  • Loading branch information
subkanthi authored and Cloud Composer Team committed Sep 12, 2024
1 parent a2374bb commit b61dafc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
60 changes: 60 additions & 0 deletions tests/providers/jenkins/hooks/test_jenkins.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 0 additions & 1 deletion tests/test_project_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
'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',
Expand Down

0 comments on commit b61dafc

Please sign in to comment.