def test_create_goofys_daemonset(self, create_p): ds = V1DaemonSet(metadata=V1ObjectMeta(name='test')) k8s.create_goofys_daemonset(daemonset=ds) create_p.side_effect = ApiValueError('Error') with self.assertRaises(api.ApiError) as e: k8s.create_goofys_daemonset(daemonset=ds) self.assertEqual('Error when creating the deployment test: Error', str(e.exception))
def test_delete_goofys_daemonset(self, create_p): ds = V1DaemonSet(metadata=V1ObjectMeta(name='test')) create_p.return_value = V1Status(status='Deleted') res = k8s.delete_goofys_daemonset(name='test', namespace='test') create_p.assert_called_once() create_p.side_effect = ApiValueError('Error') with self.assertRaises(api.ApiError) as e: k8s.delete_goofys_daemonset(name='test', namespace='test') self.assertEqual('Error when deleting the deployment test: Error', str(e.exception))
def test_delete_one(self, batch_p): batch_p.return_value = V1Status(message='Ganz blöd', status=100) res = cubegens.delete_one('id') batch_p.assert_called_once() self.assertEqual(100, res) batch_p.side_effect = ApiValueError('Error') with self.assertRaises(api.ApiError) as e: cubegens.delete_one('id') self.assertEqual("Error", str(e.exception)) self.assertEqual(400, e.exception.status_code)
def test_list_goofys_daemonsets(self, create_p): ds = V1DaemonSet(metadata=V1ObjectMeta(name='test')) create_p.return_value = V1DaemonSetList(items=[ds]) res = k8s.list_goofys_daemonsets(namespace='test') self.assertIsInstance(res, V1DaemonSetList) self.assertEqual(1, len(res.items)) create_p.side_effect = ApiValueError('Error') with self.assertRaises(api.ApiError) as e: k8s.list_goofys_daemonsets(namespace='test') self.assertEqual( 'Error when listing daemonsets in namespace test: Error', str(e.exception))
def test_create_configmap(self, create_p): data = {'dr': 'who'} cm = k8s.create_configmap_object(name='test', data=data) k8s.create_configmap(namespace='test', body=cm) create_p.assert_called_once() create_p.side_effect = ApiValueError('Error') with self.assertRaises(api.ApiError) as e: k8s.create_configmap(namespace='test', body=cm) self.assertEqual( 'Error when creating the configmap test in test: Error', str(e.exception))
def test_info(self, batch_p): batch_p.return_value = V1Job(metadata=V1ObjectMeta(name='id-cate'), status=V1Status(message='Ganz blöd', status=100)) res = cubegens.status('id') batch_p.assert_called_once() self.assertEqual(100, res['status']) batch_p.side_effect = ApiValueError( "Missing the required parameter `namespace` " "when calling `read_namespaced_job_status`") res = cubegens.status('id') self.assertDictEqual({}, res)
def test_create_info_only(self, namespace_p, create_p, status_p): res = cubegens.create('drwho', '*****@*****.**', _CFG, info_only=True) self.assertIn("drwho-", res['cubegen_id']) self.assertEqual(24, len(res['cubegen_id'])) create_p.side_effect = ApiException(401, 'Unauthorized') with self.assertRaises(api.ApiError) as e: cubegens.create('drwho', '*****@*****.**', _CFG, info_only=True) self.assertEqual(400, e.exception.status_code) self.assertIn("Reason: Unauthorized", str(e.exception)) self.assertIn("401", str(e.exception)) create_p.side_effect = ApiValueError('Error') with self.assertRaises(api.ApiError) as e: cubegens.create('drwho', '*****@*****.**', _CFG, info_only=True) self.assertEqual(400, e.exception.status_code) self.assertEqual("Error", str(e.exception)) del os.environ['XCUBE_HUB_CALLBACK_URL'] with self.assertRaises(api.ApiError) as e: cubegens.create('drwho', '*****@*****.**', _CFG, info_only=True) self.assertEqual('XCUBE_HUB_CALLBACK_URL must be given', str(e.exception)) cfg = _CFG.copy() del cfg['input_config'] with self.assertRaises(api.ApiError) as e: cubegens.create('drwho', '*****@*****.**', cfg, info_only=True) self.assertEqual( "Either 'input_config' or 'input_configs' must be given", str(e.exception))
def test_create_pvc_if_not_exists(self, list_p): pvc = V1PersistentVolumeClaim(metadata=V1ObjectMeta(name='tt')) list_p.return_value = V1PersistentVolumeClaimList(items=[pvc]) res = k8s.create_pvc_if_not_exists(pvc, 'test_namespace') self.assertFalse(res) list_p.return_value = V1PersistentVolumeClaimList(items=[]) with patch('xcube_hub.core.k8s.create_pvc') as p: res = k8s.create_pvc_if_not_exists(pvc, 'test_namespace') p.assert_called_once() self.assertTrue(res) list_p.side_effect = ApiValueError('Error') with self.assertRaises(api.ApiError) as e: k8s.create_pvc_if_not_exists(pvc, 'test_namespace') self.assertEqual('Error when creating the pvc tt: Error', str(e.exception))