Ejemplo n.º 1
0
    def test_retry_failed(self, mock_gcs):
        mock_client = mock_gcs.return_value
        mock_client.get_bucket = MagicMock()
        mock_bucket = mock_client.get_bucket.return_value
        mock_blob = mock_bucket.blob.return_value
        mock_blob.delete.side_effect = [
            ServiceUnavailable("service unavailable"),
            ServiceUnavailable("service unavailable"),
            ServiceUnavailable("service unavailable"),
            ServiceUnavailable("service unavailable"),
        ]

        test_handler = GCSHandler("test_bucket_name", back_off=0.1)
        with pytest.raises(ServiceUnavailable) as expected:
            test_handler.delete_file("test_file_name")
            assert expected.value.errors == "service unavailable"
Ejemplo n.º 2
0
    def test_retry_succeed(self, mock_gcs):
        mock_client = mock_gcs.return_value
        mock_client.get_bucket = MagicMock()
        mock_bucket = mock_client.get_bucket.return_value
        mock_blob = mock_bucket.blob.return_value
        mock_blob.delete.side_effect = [ServiceUnavailable("service unavailable"), True]

        test_handler = GCSHandler("test_bucket_name", back_off=0.1)
        result = test_handler.delete_file("test_file_name")
        assert result is True
        assert mock_bucket.blob.call_count == 2
        assert mock_blob.delete.call_count == 2
Ejemplo n.º 3
0
    def test_normal_flow(self, mock_gcs):
        mock_client = mock_gcs.return_value
        mock_client.get_bucket = MagicMock()
        mock_bucket = mock_client.get_bucket.return_value
        mock_blob = mock_bucket.blob.return_value
        mock_blob.delete.return_value = True

        test_handler = GCSHandler("test_bucket_name")
        result = test_handler.delete_file("test_file_name")
        assert result is True
        mock_bucket.blob.assert_called_once()
        mock_blob.delete.assert_called_once()