本文整理汇总了Python中airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook.update_instance方法的典型用法代码示例。如果您正苦于以下问题:Python CloudSpannerHook.update_instance方法的具体用法?Python CloudSpannerHook.update_instance怎么用?Python CloudSpannerHook.update_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook
的用法示例。
在下文中一共展示了CloudSpannerHook.update_instance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestGcpSpannerHookNoDefaultProjectID
# 需要导入模块: from airflow.contrib.hooks.gcp_spanner_hook import CloudSpannerHook [as 别名]
# 或者: from airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook import update_instance [as 别名]
class TestGcpSpannerHookNoDefaultProjectID(unittest.TestCase):
def setUp(self):
with mock.patch('airflow.contrib.hooks.gcp_api_base_hook.GoogleCloudBaseHook.__init__',
new=mock_base_gcp_hook_no_default_project_id):
self.spanner_hook_no_default_project_id = CloudSpannerHook(gcp_conn_id='test')
@mock.patch('airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook._get_client')
def test_get_existing_instance_missing_project_id(self, get_client):
instance_method = get_client.return_value.instance
instance_exists_method = instance_method.return_value.exists
instance_exists_method.return_value = True
with self.assertRaises(AirflowException) as cm:
self.spanner_hook_no_default_project_id.get_instance(instance_id=SPANNER_INSTANCE)
get_client.assert_not_called()
instance_method.assert_not_called()
instance_exists_method.assert_not_called()
err = cm.exception
self.assertIn("The project id must be passed", str(err))
@mock.patch('airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook._get_client')
def test_get_existing_instance_overridden_project_id(self, get_client):
instance_method = get_client.return_value.instance
instance_exists_method = instance_method.return_value.exists
instance_exists_method.return_value = True
res = self.spanner_hook_no_default_project_id.get_instance(instance_id=SPANNER_INSTANCE,
project_id=GCP_PROJECT_ID_HOOK_UNIT_TEST)
get_client.assert_called_once_with(project_id='example-project')
instance_method.assert_called_once_with(instance_id='instance')
self.assertIsNotNone(res)
@mock.patch('airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook._get_client')
def test_get_non_existing_instance(self, get_client):
instance_method = get_client.return_value.instance
instance_exists_method = instance_method.return_value.exists
instance_exists_method.return_value = False
res = self.spanner_hook_no_default_project_id.get_instance(instance_id=SPANNER_INSTANCE,
project_id=GCP_PROJECT_ID_HOOK_UNIT_TEST)
get_client.assert_called_once_with(project_id='example-project')
instance_method.assert_called_once_with(instance_id='instance')
self.assertIsNone(res)
@mock.patch('airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook._get_client')
def test_create_instance_missing_project_id(self, get_client):
instance_method = get_client.return_value.instance
create_method = instance_method.return_value.create
create_method.return_value = False
with self.assertRaises(AirflowException) as cm:
self.spanner_hook_no_default_project_id.create_instance(
instance_id=SPANNER_INSTANCE,
configuration_name=SPANNER_CONFIGURATION,
node_count=1,
display_name=SPANNER_DATABASE)
get_client.assert_called_once_with(project_id='example-project')
get_client.assert_not_called()
instance_method.assert_not_called()
create_method.assert_not_called()
err = cm.exception
self.assertIn("The project id must be passed", str(err))
@mock.patch('airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook._get_client')
def test_create_instance_overridden_project_id(self, get_client):
instance_method = get_client.return_value.instance
create_method = instance_method.return_value.create
create_method.return_value = False
res = self.spanner_hook_no_default_project_id.create_instance(
project_id=GCP_PROJECT_ID_HOOK_UNIT_TEST,
instance_id=SPANNER_INSTANCE,
configuration_name=SPANNER_CONFIGURATION,
node_count=1,
display_name=SPANNER_DATABASE)
get_client.assert_called_once_with(project_id='example-project')
instance_method.assert_called_once_with(
instance_id='instance',
configuration_name='configuration',
display_name='database-name',
node_count=1)
self.assertIsNone(res)
@mock.patch('airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook._get_client')
def test_update_instance_missing_project_id(self, get_client):
instance_method = get_client.return_value.instance
instance_exists_method = instance_method.return_value.exists
instance_exists_method.return_value = True
update_method = instance_method.return_value.update
update_method.return_value = False
with self.assertRaises(AirflowException) as cm:
self.spanner_hook_no_default_project_id.update_instance(
instance_id=SPANNER_INSTANCE,
configuration_name=SPANNER_CONFIGURATION,
node_count=2,
display_name=SPANNER_DATABASE)
get_client.assert_not_called()
instance_method.assert_not_called()
update_method.assert_not_called()
err = cm.exception
self.assertIn("The project id must be passed", str(err))
@mock.patch('airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook._get_client')
def test_update_instance_overridden_project_id(self, get_client):
#.........这里部分代码省略.........