Beispiel #1
0
 def execute(self, context):
     hook = CloudVideoIntelligenceHook(gcp_conn_id=self.gcp_conn_id)
     operation = hook.annotate_video(
         input_uri=self.input_uri,
         input_content=self.input_content,
         video_context=self.video_context,
         location=self.location,
         retry=self.retry,
         features=[enums.Feature.LABEL_DETECTION],
         timeout=self.timeout)
     self.log.info("Processing video for label annotations")
     result = MessageToDict(operation.result())
     self.log.info("Finished processing.")
     return result
 def execute(self, context):
     hook = CloudVideoIntelligenceHook(
         gcp_conn_id=self.gcp_conn_id,
         impersonation_chain=self.impersonation_chain,
     )
     operation = hook.annotate_video(
         input_uri=self.input_uri,
         input_content=self.input_content,
         video_context=self.video_context,
         location=self.location,
         retry=self.retry,
         features=[enums.Feature.EXPLICIT_CONTENT_DETECTION],
         timeout=self.timeout)
     self.log.info("Processing video for explicit content annotations")
     result = MessageToDict(operation.result())
     self.log.info("Finished processing.")
     return result
 def setUp(self):
     with mock.patch(
             "airflow.providers.google.cloud.hooks.video_intelligence.CloudVideoIntelligenceHook.__init__",
             new=mock_base_gcp_hook_default_project_id,
     ):
         self.hook = CloudVideoIntelligenceHook(gcp_conn_id="test")
class TestCloudVideoIntelligenceHook(unittest.TestCase):
    def setUp(self):
        with mock.patch(
                "airflow.providers.google.cloud.hooks.video_intelligence.CloudVideoIntelligenceHook.__init__",
                new=mock_base_gcp_hook_default_project_id,
        ):
            self.hook = CloudVideoIntelligenceHook(gcp_conn_id="test")

    @mock.patch(
        "airflow.providers.google.cloud.hooks.video_intelligence.CloudVideoIntelligenceHook.client_info",
        new_callable=mock.PropertyMock,
    )
    @mock.patch(
        "airflow.providers.google.cloud.hooks.video_intelligence.CloudVideoIntelligenceHook._get_credentials"
    )
    @mock.patch(
        "airflow.providers.google.cloud.hooks.video_intelligence.VideoIntelligenceServiceClient"
    )
    def test_video_intelligence_service_client_creation(
            self, mock_client, mock_get_creds, mock_client_info):
        result = self.hook.get_conn()
        mock_client.assert_called_once_with(
            credentials=mock_get_creds.return_value,
            client_info=mock_client_info.return_value)
        self.assertEqual(mock_client.return_value, result)
        self.assertEqual(self.hook._conn, result)

    @mock.patch(
        "airflow.providers.google.cloud.hooks.video_intelligence.CloudVideoIntelligenceHook.get_conn"
    )
    def test_annotate_video(self, get_conn):
        # Given
        annotate_video_method = get_conn.return_value.annotate_video
        get_conn.return_value.annotate_video.return_value = ANNOTATE_VIDEO_RESPONSE

        # When
        result = self.hook.annotate_video(input_uri=INPUT_URI,
                                          features=FEATURES)

        # Then
        self.assertIs(result, ANNOTATE_VIDEO_RESPONSE)
        annotate_video_method.assert_called_once_with(
            input_uri=INPUT_URI,
            input_content=None,
            features=FEATURES,
            video_context=None,
            output_uri=None,
            location_id=None,
            retry=None,
            timeout=None,
            metadata=None,
        )

    @mock.patch(
        "airflow.providers.google.cloud.hooks.video_intelligence.CloudVideoIntelligenceHook.get_conn"
    )
    def test_annotate_video_with_output_uri(self, get_conn):
        # Given
        annotate_video_method = get_conn.return_value.annotate_video
        get_conn.return_value.annotate_video.return_value = ANNOTATE_VIDEO_RESPONSE

        # When
        result = self.hook.annotate_video(input_uri=INPUT_URI,
                                          output_uri=OUTPUT_URI,
                                          features=FEATURES)

        # Then
        self.assertIs(result, ANNOTATE_VIDEO_RESPONSE)
        annotate_video_method.assert_called_once_with(
            input_uri=INPUT_URI,
            output_uri=OUTPUT_URI,
            input_content=None,
            features=FEATURES,
            video_context=None,
            location_id=None,
            retry=None,
            timeout=None,
            metadata=None,
        )