|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | + |
| 15 | +import uuid |
| 16 | +from unittest import IsolatedAsyncioTestCase |
| 17 | + |
| 18 | +from kubernetes_asyncio.client import api_client |
| 19 | +from kubernetes_asyncio.client.api import core_v1_api |
| 20 | +from kubernetes_asyncio.e2e_test import base |
| 21 | + |
| 22 | + |
| 23 | +class TestApplyPatch(IsolatedAsyncioTestCase): |
| 24 | + |
| 25 | + @classmethod |
| 26 | + def setUpClass(cls): |
| 27 | + cls.config = base.get_e2e_configuration() |
| 28 | + |
| 29 | + async def test_apply_patch(self): |
| 30 | + client = api_client.ApiClient(configuration=self.config) |
| 31 | + api = core_v1_api.CoreV1Api(client) |
| 32 | + |
| 33 | + name = "cm-test" + str(uuid.uuid4()) |
| 34 | + manifest = dict( |
| 35 | + apiVersion="v1", |
| 36 | + kind="ConfigMap", |
| 37 | + metadata=dict( |
| 38 | + namespace="default", |
| 39 | + name=name, |
| 40 | + ), |
| 41 | + data={"hello": "world!"}, |
| 42 | + ) |
| 43 | + |
| 44 | + resp = await api.patch_namespaced_config_map( |
| 45 | + _content_type="application/apply-patch+yaml", |
| 46 | + field_manager="test", |
| 47 | + body=manifest, |
| 48 | + name=name, |
| 49 | + namespace="default", |
| 50 | + ) |
| 51 | + self.assertEqual(name, resp.metadata.name) |
| 52 | + |
| 53 | + resp = await api.read_namespaced_config_map(name=name, namespace="default") |
| 54 | + self.assertEqual(name, resp.metadata.name) |
| 55 | + |
| 56 | + resp = await api.delete_namespaced_config_map( |
| 57 | + name=name, body={}, namespace="default" |
| 58 | + ) |
0 commit comments