def test_init_valid(self):
     conf = load_yaml('simple')
     object_configuration = ObjectConfiguration(conf)
     self.assertEqual(object_configuration.data, conf)
     self.assertEqual(object_configuration.api_version, 'v1')
     self.assertEqual(object_configuration.kind, 'ConfigMap')
     self.assertEqual(object_configuration.name, 'testing')
예제 #2
0
 def test_create_object_with_non_namespaced_object(self):
     self.__mock_create_non_namespaced_object()
     object_config = ObjectConfiguration({
         'apiVersion': 'v1',
         'kind': 'Namespace',
         'metadata': {
             'name': 'Testing'
         }
     })
     self.api_ctl.create_object(object_config)
     self.client_director.determine_api_method_for_create_object.assert_called_once_with(
         'v1', 'Namespace')
     self.create_method.assert_called_once_with(body=object_config.data)
예제 #3
0
 def test_update_object_with_cluster_custom_object_plural_not_found(self):
     self.__mock_update_cluster_custom_object(kind='MyOtherCustom')
     object_config = ObjectConfiguration({
         'apiVersion': 'example.com/v1',
         'kind': 'MyCustom',
         'metadata': {
             'name': 'Testing'
         }
     })
     with self.assertRaises(UnrecognisedObjectKindError) as context:
         self.api_ctl.update_object(object_config)
     self.client_director.determine_api_method_for_update_object.assert_called_once_with(
         'example.com/v1', 'MyCustom')
     self.update_method.assert_not_called()
     self.assertEqual(
         str(context.exception),
         'Could not find a CRD for custom Resource with group \'example.com\', version \'v1\', kind \'MyCustom\' - CRD required to determine the Resource plural'
     )
예제 #4
0
 def test_create_object_with_namespaced_object(self):
     self.__mock_create_namespaced_object()
     object_config = ObjectConfiguration({
         'apiVersion': 'v1',
         'kind': 'ConfigMap',
         'metadata': {
             'name': 'Testing'
         },
         'data': {
             'dataItemA': 'A',
             'dataItemB': 'B'
         }
     })
     self.api_ctl.create_object(object_config)
     self.client_director.determine_api_method_for_create_object.assert_called_once_with(
         'v1', 'ConfigMap')
     self.create_method.assert_called_once_with(body=object_config.data,
                                                namespace='default')
예제 #5
0
 def test_create_object_with_cluster_custom_object(self):
     self.__mock_create_cluster_custom_object()
     object_config = ObjectConfiguration({
         'apiVersion': 'example.com/v1',
         'kind': 'MyCustom',
         'metadata': {
             'name': 'Testing'
         }
     })
     self.api_ctl.create_object(object_config)
     self.client_director.determine_api_method_for_create_object.assert_called_once_with(
         'example.com/v1', 'MyCustom')
     self.crd_director.get_crd_by_kind.assert_called_once_with(
         'example.com', 'MyCustom')
     self.create_method.assert_called_once_with(group='example.com',
                                                version='v1',
                                                plural='mycustoms',
                                                body=object_config.data)
예제 #6
0
 def test_create_object_with_namespaced_custom_object_supply_default_namespace_in_init(
         self):
     self.__reconfigure_with_namespace('AltInitDefault')
     self.__mock_create_namespaced_custom_object()
     object_config = ObjectConfiguration({
         'apiVersion': 'example.com/v1',
         'kind': 'MyCustom',
         'metadata': {
             'name': 'Testing'
         }
     })
     self.api_ctl.create_object(object_config)
     self.client_director.determine_api_method_for_create_object.assert_called_once_with(
         'example.com/v1', 'MyCustom')
     self.create_method.assert_called_once_with(group='example.com',
                                                version='v1',
                                                plural='mycustoms',
                                                body=object_config.data,
                                                namespace='AltInitDefault')
예제 #7
0
 def test_update_object_with_namespaced_object_supply_default_namespace_in_init(
         self):
     self.__reconfigure_with_namespace('AltInitDefault')
     self.__mock_update_namespaced_object()
     object_config = ObjectConfiguration({
         'apiVersion': 'v1',
         'kind': 'ConfigMap',
         'metadata': {
             'name': 'Testing'
         },
         'data': {
             'dataItemA': 'A',
             'dataItemB': 'B'
         }
     })
     self.api_ctl.update_object(object_config)
     self.client_director.determine_api_method_for_update_object.assert_called_once_with(
         'v1', 'ConfigMap')
     self.update_method.assert_called_once_with(name='Testing',
                                                body=object_config.data,
                                                namespace='AltInitDefault')
예제 #8
0
 def test_update_object_with_namespaced_custom_object_including_namespace_metadata(
         self):
     self.__mock_update_namespaced_custom_object()
     object_config = ObjectConfiguration({
         'apiVersion': 'example.com/v1',
         'kind': 'MyCustom',
         'metadata': {
             'name': 'Testing',
             'namespace': 'NamespaceFromMetadata'
         }
     })
     self.api_ctl.update_object(object_config,
                                default_namespace='AltDefault')
     self.client_director.determine_api_method_for_update_object.assert_called_once_with(
         'example.com/v1', 'MyCustom')
     self.update_method.assert_called_once_with(
         name='Testing',
         group='example.com',
         version='v1',
         plural='mycustoms',
         body=object_config.data,
         namespace='NamespaceFromMetadata')
 def __check_raises_error(self, conf, expected_reason):
     with self.assertRaises(InvalidObjectConfigurationError) as context:
         ObjectConfiguration(conf)
     self.assertEqual(context.exception.reason, expected_reason)