-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix/fix api exception handling (#140)
* Fix module path to ApiException * Add a test case for handling ApiException
- Loading branch information
1 parent
0c5cdae
commit b484e46
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from k8s_handle import settings | ||
from k8s_handle import handler_deploy | ||
from kubernetes import client | ||
|
||
|
||
class TestDeployHandler(unittest.TestCase): | ||
|
||
def setUp(self): | ||
settings.CONFIG_FILE = 'tests/fixtures/config_with_env_vars.yaml' | ||
settings.TEMPLATES_DIR = 'templates/tests' | ||
os.environ['K8S_CONFIG_DIR'] = '/tmp/kube/' | ||
os.environ['SECTION1'] = 'not found' | ||
os.environ['SECTION'] = 'section-1' | ||
|
||
@patch('k8s_handle.templating.Renderer._generate_file') | ||
@patch('kubernetes.client.api.version_api.VersionApi.get_code_with_http_info') | ||
@patch('k8s_handle.k8s.provisioner.Provisioner.run') | ||
def test_api_exception_handling( | ||
self, | ||
mocked_provisioner_run, | ||
mocked_client_version_api_get_code, | ||
mocked_generate_file | ||
): | ||
mocked_client_version_api_get_code.side_effect = client.exceptions.ApiException( | ||
'Max retries exceeded with url: /version/' | ||
) | ||
|
||
configs = { | ||
'section': os.environ['SECTION'], | ||
'config': settings.CONFIG_FILE, | ||
"use_kubeconfig": True | ||
} | ||
# client.exceptions.ApiException should be handled | ||
handler_deploy(configs) |