@@ -0,0 +1,3046 @@
+# -*- coding: utf-8 -*-%0A%0A# Licensed under the Apache License, Version 2.0 (the %22License%22); you may%0A# not use this file except in compliance with the License. You may obtain%0A# a copy of the License at%0A#%0A#      http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A# License for the specific language governing permissions and limitations%0A# under the License.%0A%0Aimport unittest%0Aimport uuid%0A%0Afrom kubernetes import watch%0Afrom kubernetes.client import api_client%0Afrom kubernetes.client.api import core_v1_api%0Afrom kubernetes.e2e_test import base%0A%0A%0Adef short_uuid():%0A    id = str(uuid.uuid4())%0A    return id%5B-12:%5D%0A%0A%0Adef config_map_with_value(name, value):%0A    return %7B%0A        %22apiVersion%22: %22v1%22,%0A        %22kind%22: %22ConfigMap%22,%0A        %22metadata%22: %7B%0A            %22name%22: name,%0A        %7D,%0A        %22data%22: %7B%0A            %22key%22: value,%0A            %22config%22: %22dummy%22,%0A        %7D%0A    %7D%0A%0A%0Aclass TestClient(unittest.TestCase):%0A%0A    @classmethod%0A    def setUpClass(cls):%0A        cls.config = base.get_e2e_configuration()%0A%0A    def test_watch_configmaps(self):%0A        client = api_client.ApiClient(configuration=self.config)%0A        api = core_v1_api.CoreV1Api(client)%0A%0A        # create a configmap%0A        name_a = 'configmap-a-' + short_uuid()%0A        configmap_a = config_map_with_value(name_a, %22a%22)%0A        api.create_namespaced_config_map(%0A            body=configmap_a, namespace='default')%0A%0A        # list all configmaps and extract the resource version%0A        resp = api.list_namespaced_config_map('default')%0A        rv = resp.metadata.resource_version%0A%0A        # create another configmap%0A        name_b = 'configmap-b-' + short_uuid()%0A        configmap_b = config_map_with_value(name_b, %22b%22)%0A        api.create_namespaced_config_map(%0A            body=configmap_b, namespace='default')%0A%0A        # patch configmap b%0A        configmap_b%5B'data'%5D%5B'config'%5D = %22%7B%7D%22%0A        api.patch_namespaced_config_map(%0A            name=name_b, namespace='default', body=configmap_b)%0A%0A        # delete all configmaps%0A        api.delete_collection_namespaced_config_map(%0A            namespace='default')%0A%0A        w = watch.Watch()%0A        # expect to observe all events happened after the initial LIST%0A        expect = %5B'ADDED', 'MODIFIED', 'DELETED', 'DELETED'%5D%0A        i = 0%0A        # start watching with the resource version we got from the LIST%0A        for event in w.stream(api.list_namespaced_config_map,%0A                              namespace='default',%0A                              resource_version=rv,%0A                              timeout_seconds=5):%0A            self.assertEqual(event%5B'type'%5D, expect%5Bi%5D)%0A            # Kubernetes doesn't guarantee the order of the two objects%0A            # being deleted%0A            if i %3C 2:%0A                self.assertEqual(event%5B'object'%5D.metadata.name, name_b)%0A            i = i + 1%0A%0A        self.assertEqual(i, 4)%0A

add basic watch configmap e2e test