Repository: tomplus/kubernetes_asyncio
Pull request #41 (2018-09-22 21:40:53)

fix: read config data with bytes (python3)
Ref: https://github.com/kubernetes-client/python-base/pull/86

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

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

```diff
@@            Coverage Diff             @@
##           master      #41      +/-   ##
==========================================
+ Coverage   94.07%   94.13%   +0.05%     
==========================================
  Files          18       18              
  Lines        1182     1193      +11     
==========================================
+ Hits         1112     1123      +11     
  Misses         70       70
```


| [Impacted Files](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/41?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [kubernetes\_asyncio/config/kube\_config.py](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/41/diff?src=pr&el=tree#diff-a3ViZXJuZXRlc19hc3luY2lvL2NvbmZpZy9rdWJlX2NvbmZpZy5weQ==) | `93.23% <100%> (+0.07%)` | :arrow_up: |
| [kubernetes\_asyncio/config/kube\_config\_test.py](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/41/diff?src=pr&el=tree#diff-a3ViZXJuZXRlc19hc3luY2lvL2NvbmZpZy9rdWJlX2NvbmZpZ190ZXN0LnB5) | `93.64% <100%> (+0.14%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/41?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/41?src=pr&el=footer). Last update [b0b29f3...a81ab2f](https://codecov.io/gh/tomplus/kubernetes_asyncio/pull/41?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/kubernetes_asyncio/config/kube_config.py b/kubernetes_asyncio/config/kube_config.py
index b63025d5..27cdc336 100644
--- a/kubernetes_asyncio/config/kube_config.py
+++ b/kubernetes_asyncio/config/kube_config.py
@@ -95,8 +95,12 @@ class FileOrData(object):
         use_data_if_no_file = not self._file and self._data
         if use_data_if_no_file:
             if self._base64_file_content:
+                if isinstance(self._data, str):
+                    content = self._data.encode()
+                else:
+                    content = self._data
                 self._file = _create_temp_file_with_content(
-                    base64.decodestring(self._data.encode()))
+                    base64.decodestring(content))
             else:
                 self._file = _create_temp_file_with_content(self._data)
         if self._file and not os.path.isfile(self._file):


Test patch:
diff --git a/kubernetes_asyncio/config/kube_config_test.py b/kubernetes_asyncio/config/kube_config_test.py
index 1acf6620..b9a7d0af 100644
--- a/kubernetes_asyncio/config/kube_config_test.py
+++ b/kubernetes_asyncio/config/kube_config_test.py
@@ -197,6 +197,18 @@ class TestFileOrData(BaseTestCase):
                              _create_temp_file_with_content(TEST_DATA)))
         _cleanup_temp_files()
 
+    def test_file_given_data_bytes(self):
+        obj = {TEST_DATA_KEY: TEST_DATA_BASE64.encode()}
+        t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
+                       data_key_name=TEST_DATA_KEY)
+        self.assertEqual(TEST_DATA, self.get_file_content(t.as_file()))
+
+    def test_file_given_data_bytes_no_base64(self):
+        obj = {TEST_DATA_KEY: TEST_DATA.encode()}
+        t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
+                       data_key_name=TEST_DATA_KEY, base64_file_content=False)
+        self.assertEqual(TEST_DATA, self.get_file_content(t.as_file()))
+
 
 class TestConfigNode(BaseTestCase):