|
20 | 20 | from kubernetes.client import api_client
|
21 | 21 |
|
22 | 22 | from . import DynamicClient
|
| 23 | +from .resource import ResourceInstance, ResourceField |
23 | 24 | from .exceptions import ResourceNotFoundError
|
24 | 25 |
|
25 | 26 |
|
@@ -392,3 +393,32 @@ def test_node_apis_partial_object_metadata(self):
|
392 | 393 | resp = api.get(**params)
|
393 | 394 | self.assertEqual('PartialObjectMetadataList', resp.kind)
|
394 | 395 | self.assertEqual('meta.k8s.io/v1', resp.apiVersion)
|
| 396 | + |
| 397 | + |
| 398 | +class TestDynamicClientSerialization(unittest.TestCase): |
| 399 | + |
| 400 | + @classmethod |
| 401 | + def setUpClass(cls): |
| 402 | + config = base.get_e2e_configuration() |
| 403 | + cls.client = DynamicClient(api_client.ApiClient(configuration=config)) |
| 404 | + cls.pod_manifest = { |
| 405 | + 'apiVersion': 'v1', |
| 406 | + 'kind': 'Pod', |
| 407 | + 'metadata': {'name': 'foo-pod'}, |
| 408 | + 'spec': {'containers': [{'name': "main", 'image': "busybox"}]}, |
| 409 | + } |
| 410 | + |
| 411 | + def test_dict_type(self): |
| 412 | + self.assertEqual(self.client.serialize_body(self.pod_manifest), self.pod_manifest) |
| 413 | + |
| 414 | + def test_resource_instance_type(self): |
| 415 | + inst = ResourceInstance(self.client, self.pod_manifest) |
| 416 | + self.assertEqual(self.client.serialize_body(inst), self.pod_manifest) |
| 417 | + |
| 418 | + def test_resource_field(self): |
| 419 | + """`ResourceField` is a special type which overwrites `__getattr__` method to return `None` |
| 420 | + when a non-existent attribute was accessed. which means it can pass any `hasattr(...)` tests. |
| 421 | + """ |
| 422 | + res = ResourceField(foo='bar') |
| 423 | + # method will return original object when it doesn't know how to proceed |
| 424 | + self.assertEqual(self.client.serialize_body(res), res) |
0 commit comments