Пример #1
0
 def test_stop_should_throw_ex_when_missing_resource_id(self, mock_hook):
     with self.assertRaises(AirflowException) as cm:
         op = ComputeEngineStopInstanceOperator(
             project_id=GCP_PROJECT_ID, zone=GCE_ZONE, resource_id="", task_id='id'
         )
         op.execute(None)
     err = cm.exception
     self.assertIn("The required parameter 'resource_id' is missing", str(err))
     mock_hook.assert_not_called()
Пример #2
0
 def test_stop_should_not_throw_ex_when_project_id_none(self, mock_hook):
     op = ComputeEngineStopInstanceOperator(zone=GCE_ZONE, resource_id=RESOURCE_ID, task_id='id')
     op.execute(None)
     mock_hook.assert_called_once_with(
         api_version='v1', gcp_conn_id='google_cloud_default', impersonation_chain=None,
     )
     mock_hook.return_value.stop_instance.assert_called_once_with(
         zone=GCE_ZONE, resource_id=RESOURCE_ID, project_id=None
     )
Пример #3
0
 def test_stop_should_throw_ex_when_missing_zone(self, mock_hook):
     with pytest.raises(AirflowException) as ctx:
         op = ComputeEngineStopInstanceOperator(project_id=GCP_PROJECT_ID,
                                                zone="",
                                                resource_id=RESOURCE_ID,
                                                task_id='id')
         op.execute(None)
     err = ctx.value
     assert "The required parameter 'zone' is missing" in str(err)
     mock_hook.assert_not_called()
Пример #4
0
 def test_instance_stop(self, mock_hook):
     op = ComputeEngineStopInstanceOperator(project_id=GCP_PROJECT_ID,
                                            zone=GCE_ZONE,
                                            resource_id=RESOURCE_ID,
                                            task_id='id')
     op.execute(None)
     mock_hook.assert_called_once_with(api_version='v1',
                                       gcp_conn_id='google_cloud_default')
     mock_hook.return_value.stop_instance.assert_called_once_with(
         zone=GCE_ZONE, resource_id=RESOURCE_ID, project_id=GCP_PROJECT_ID)