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_bucket.rename_blob.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.rename_file("old_file_name", "new_file_name")
            assert expected.value.errors == "service unavailable"
Ejemplo n.º 2
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_bucket.rename_blob.return_value = True

        test_handler = GCSHandler("test_bucket_name")
        result = test_handler.rename_file("old_file_name", "new_file_name")
        assert result is True
        mock_bucket.blob.assert_called_once()
        mock_bucket.rename_blob.assert_called_once()
Ejemplo n.º 3
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_bucket.rename_blob.side_effect = [
            ServiceUnavailable("service unavailable"),
            True,
        ]

        test_handler = GCSHandler("test_bucket_name", back_off=0.1)
        result = test_handler.rename_file("old_file_name", "new_file_name")
        assert result is True
        assert mock_bucket.blob.call_count == 2
        assert mock_bucket.rename_blob.call_count == 2