Repository: tomplus/kubernetes_asyncio
Pull request #48 (2018-10-12 23:04:49)

fix: pdate ExecProvider to use safe_get()
Sync with synchronous lib: https://github.com/kubernetes-client/python-base/pull/91

codecov-io: # [Codecov](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/48?src=pr&el=h1) Report
> Merging [#48](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/48?src=pr&el=desc) into [master](https://codecov.io/gh/tomplus/kubernetes_asyncio/commit/38ae5f8e6c730ac211ee388992697113c8c58ca3?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/48/graphs/tree.svg?width=650&token=0Dvm4fqopq&height=150&src=pr)](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/48?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #48      +/-   ##
==========================================
+ Coverage   94.37%   94.38%   +<.01%     
==========================================
  Files          20       20              
  Lines        1352     1353       +1     
==========================================
+ Hits         1276     1277       +1     
  Misses         76       76
```


| [Impacted Files](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/48?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [kubernetes\_asyncio/config/exec\_provider.py](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/48/diff?src=pr&el=tree#diff-a3ViZXJuZXRlc19hc3luY2lvL2NvbmZpZy9leGVjX3Byb3ZpZGVyLnB5) | `96% <100%> (ø)` | :arrow_up: |
| [kubernetes\_asyncio/config/exec\_provider\_test.py](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/48/diff?src=pr&el=tree#diff-a3ViZXJuZXRlc19hc3luY2lvL2NvbmZpZy9leGVjX3Byb3ZpZGVyX3Rlc3QucHk=) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/48?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/48?src=pr&el=footer). Last update [38ae5f8...cad6ae6](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/48?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/kubernetes_asyncio/config/exec_provider.py b/kubernetes_asyncio/config/exec_provider.py
index 6a9864bd..fb96836e 100644
--- a/kubernetes_asyncio/config/exec_provider.py
+++ b/kubernetes_asyncio/config/exec_provider.py
@@ -39,10 +39,10 @@ class ExecProvider(object):
                     'exec: malformed request. missing key \'%s\'' % key)
         self.api_version = exec_config['apiVersion']
         self.args = [exec_config['command']]
-        if 'args' in exec_config:
+        if exec_config.safe_get('args'):
             self.args.extend(exec_config['args'])
         self.env = os.environ.copy()
-        if 'env' in exec_config:
+        if exec_config.safe_get('env'):
             additional_vars = {}
             for item in exec_config['env']:
                 name = item['name']


Test patch:
diff --git a/kubernetes_asyncio/config/exec_provider_test.py b/kubernetes_asyncio/config/exec_provider_test.py
index 6c156161..e80e98db 100644
--- a/kubernetes_asyncio/config/exec_provider_test.py
+++ b/kubernetes_asyncio/config/exec_provider_test.py
@@ -20,15 +20,17 @@ from asynctest import ANY, TestCase, main, mock, patch
 
 from .config_exception import ConfigException
 from .exec_provider import ExecProvider
+from .kube_config import ConfigNode
 
 
 class ExecProviderTest(TestCase):
 
     def setUp(self):
-        self.input_ok = {
+        self.input_ok = ConfigNode('test', {
             'command': 'aws-iam-authenticator token -i dummy',
-            'apiVersion': 'client.authentication.k8s.io/v1beta1'
-        }
+            'apiVersion': 'client.authentication.k8s.io/v1beta1',
+            'env': None
+        })
         self.output_ok = """
         {
             "apiVersion": "client.authentication.k8s.io/v1beta1",
@@ -127,8 +129,12 @@ class ExecProviderTest(TestCase):
         self.process_mock.wait.assert_awaited_once()
 
     async def test_ok_with_args(self):
-        self.input_ok['args'] = ['--mock', '90']
-        ep = ExecProvider(self.input_ok)
+        input_ok = ConfigNode('test', {
+            'command': 'aws-iam-authenticator token -i dummy',
+            'apiVersion': 'client.authentication.k8s.io/v1beta1',
+            'args': ['--mock', '90']
+        })
+        ep = ExecProvider(input_ok)
         result = await ep.run()
         self.assertTrue(isinstance(result, dict))
         self.assertTrue('token' in result)
@@ -140,10 +146,13 @@ class ExecProviderTest(TestCase):
 
     async def test_ok_with_env(self):
 
-        self.input_ok['env'] = [{'name': 'EXEC_PROVIDER_ENV_NAME',
-                                 'value': 'EXEC_PROVIDER_ENV_VALUE'}]
+        input_ok = ConfigNode('test', {
+            'command': 'aws-iam-authenticator token -i dummy',
+            'apiVersion': 'client.authentication.k8s.io/v1beta1',
+            'env': [{'name': 'EXEC_PROVIDER_ENV_NAME',
+                     'value': 'EXEC_PROVIDER_ENV_VALUE'}]})
 
-        ep = ExecProvider(self.input_ok)
+        ep = ExecProvider(input_ok)
         result = await ep.run()
         self.assertTrue(isinstance(result, dict))
         self.assertTrue('token' in result)