def test_instance_create_aborts_and_succeeds_if_instance_exists(self, mock_hook):
     mock_hook.return_value.get_instance.return_value = {"name": INSTANCE_ID}
     op = CloudSpannerInstanceDeployOperator(
         project_id=PROJECT_ID,
         instance_id=INSTANCE_ID,
         configuration_name=CONFIG_NAME,
         node_count=int(NODE_COUNT),
         display_name=DISPLAY_NAME,
         task_id="id"
     )
     result = op.execute(None)
     mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default")
     mock_hook.return_value.create_instance.assert_not_called()
     self.assertTrue(result)
 def test_instance_create_aborts_and_succeeds_if_instance_exists(self, mock_hook):
     mock_hook.return_value.get_instance.return_value = {"name": INSTANCE_ID}
     op = CloudSpannerInstanceDeployOperator(
         project_id=PROJECT_ID,
         instance_id=INSTANCE_ID,
         configuration_name=CONFIG_NAME,
         node_count=int(NODE_COUNT),
         display_name=DISPLAY_NAME,
         task_id="id"
     )
     result = op.execute(None)
     mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default")
     mock_hook.return_value.create_instance.assert_not_called()
     self.assertTrue(result)
示例#3
0
 def test_instance_create_missing_project_id(self, mock_hook):
     mock_hook.return_value.get_instance.return_value = None
     op = CloudSpannerInstanceDeployOperator(instance_id=INSTANCE_ID,
                                             configuration_name=CONFIG_NAME,
                                             node_count=int(NODE_COUNT),
                                             display_name=DISPLAY_NAME,
                                             task_id="id")
     result = op.execute(None)
     mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default")
     mock_hook.return_value.create_instance.assert_called_once_with(
         project_id=None,
         instance_id=INSTANCE_ID,
         configuration_name=CONFIG_NAME,
         node_count=int(NODE_COUNT),
         display_name=DISPLAY_NAME)
     mock_hook.return_value.update_instance.assert_not_called()
     self.assertIsNone(result)
 def test_instance_create_missing_project_id(self, mock_hook):
     mock_hook.return_value.get_instance.return_value = None
     op = CloudSpannerInstanceDeployOperator(
         instance_id=INSTANCE_ID,
         configuration_name=CONFIG_NAME,
         node_count=int(NODE_COUNT),
         display_name=DISPLAY_NAME,
         task_id="id"
     )
     result = op.execute(None)
     mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default")
     mock_hook.return_value.create_instance.assert_called_once_with(
         project_id=None,
         instance_id=INSTANCE_ID,
         configuration_name=CONFIG_NAME,
         node_count=int(NODE_COUNT),
         display_name=DISPLAY_NAME
     )
     mock_hook.return_value.update_instance.assert_not_called()
     self.assertIsNone(result)
 def test_instance_update(self, mock_hook):
     mock_hook.return_value.get_instance.return_value = {"name": INSTANCE_ID}
     op = CloudSpannerInstanceDeployOperator(
         project_id=PROJECT_ID,
         instance_id=INSTANCE_ID,
         configuration_name=CONFIG_NAME,
         node_count=int(NODE_COUNT),
         display_name=DISPLAY_NAME,
         task_id="id"
     )
     result = op.execute(None)  # pylint: disable=assignment-from-no-return
     mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default")
     mock_hook.return_value.update_instance.assert_called_once_with(
         project_id=PROJECT_ID,
         instance_id=INSTANCE_ID,
         configuration_name=CONFIG_NAME,
         node_count=int(NODE_COUNT),
         display_name=DISPLAY_NAME
     )
     mock_hook.return_value.create_instance.assert_not_called()
     self.assertIsNone(result)