Skip to content

Commit 2969a53

Browse files
author
Kapustin Aleksandr
committed
Add delete from yaml and delete from dict simple tests
1 parent b177f02 commit 2969a53

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

kubernetes_asyncio/utils/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@
1818
FailToCreateError, create_from_dict, create_from_yaml,
1919
create_from_yaml_single_item,
2020
)
21+
from .delete_from_yaml import (
22+
FailToDeleteError, delete_from_dict, delete_from_yaml,
23+
delete_from_yaml_single_item,
24+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2019 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain 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,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from asynctest import CoroutineMock, TestCase
16+
17+
from kubernetes_asyncio.utils import delete_from_dict, delete_from_yaml
18+
19+
20+
class DeleteFromYamlTest(TestCase):
21+
22+
async def test_delete_from_yaml(self):
23+
api_client = CoroutineMock()
24+
api_client.call_api = CoroutineMock()
25+
26+
await delete_from_yaml(api_client, 'examples/nginx-deployment.yaml')
27+
28+
# simple check for api call
29+
self.assertEqual(api_client.call_api.call_args[0][0],
30+
'/apis/apps/v1/namespaces/{namespace}/deployments/{name}')
31+
32+
self.assertEqual(api_client.call_api.call_args[0][1],
33+
'DELETE')
34+
35+
self.assertEqual(api_client.call_api.call_args[0][2],
36+
{'name': 'nginx-deployment', 'namespace': 'default'})
37+
38+
async def test_delete_from_dict(self):
39+
api_client = CoroutineMock()
40+
api_client.call_api = CoroutineMock()
41+
42+
await delete_from_dict(api_client, {
43+
'apiVersion': 'apps/v1',
44+
'kind': 'Deployment',
45+
'metadata': {
46+
'name': 'nginx-deployment'},
47+
})
48+
49+
# simple check for api call
50+
self.assertEqual(api_client.call_api.call_args[0][0],
51+
'/apis/apps/v1/namespaces/{namespace}/deployments/{name}')
52+
self.assertEqual(api_client.call_api.call_args[0][1],
53+
'DELETE')
54+
55+
self.assertEqual(api_client.call_api.call_args[0][2],
56+
{'name': 'nginx-deployment', 'namespace': 'default'})
57+
58+
59+
if __name__ == '__main__':
60+
import asynctest
61+
asynctest.main()

0 commit comments

Comments
 (0)