Beispiel #1
0
def test_share_failed_upload_to_gcp_storage(mock_requests):
    file_id = "a1asd2"
    signed_url = "https://test.signed.url/lol"
    content = "this is a other test content"

    content = content.encode('utf-8')
    mock_requests.set_responses({
        "post": {
            f"{api.API_URL}": {
                "status_code": 200,
                "json": {
                    "id": file_id,
                    "signedUrl": [signed_url],
                }
            }
        },
        "put": {
            signed_url: {
                "status_code": 404,
                "json": {
                    "_content": "Example content error"
                }
            },
        },
    })
    open_mock = mock.mock_open(read_data=content)
    with mock.patch('builtins.open', open_mock, create=False):
        with open(file_id, 'rb') as f:
            with pytest.raises(errors.UploadException):
                api.share(f)
    open_mock.assert_called_once_with(file_id, 'rb')
Beispiel #2
0
def test_share(mock_requests):
    file_id = "a1asd2"
    signed_url = "https://test.signed.url/lol"
    content = "this is a other test content"

    content = content.encode('utf-8')
    mock_requests.set_responses({
        "post": {
            f"{api.API_URL}": {
                "status_code": 200,
                "json": {
                    "id": file_id,
                    "signedUrl": [signed_url],
                }
            }
        },
        "put": {
            signed_url: {
                "status_code": 200,
            },
        },
    })
    open_mock = mock.mock_open(read_data=content)
    with mock.patch('builtins.open', open_mock, create=False):
        with open(file_id, 'rb') as f:
            assert api.share(f) == f"https://pigeon.ventures/{file_id}"
    open_mock.assert_called_once_with(file_id, 'rb')
Beispiel #3
0
def test_get_failed_download_unexpected_gcp_cloud_function_exception(
        mock_requests):
    file_id = "a7ds6s"
    signed_url = "https//test.signed.url/lol"
    content = "this is some test content"

    content = content.encode('utf-8')
    mock_requests.set_responses({
        "get": {
            f"{api.API_URL}?id={file_id}": {
                "status_code": 500,
                "json": {
                    "_content": "This is an example of the error outpupt"
                },
            },
            signed_url: {
                "status_code": 404,
                "json": {
                    "_content": content
                },
            },
        },
    })
    open_mock = mock.mock_open()
    with mock.patch('builtins.open', open_mock, create=False):
        with pytest.raises(errors.DownloadException):
            api.get(file_id)
Beispiel #4
0
def test_get_failed_download_from_gcp_storage(mock_requests):
    file_id = "a7ds6s"
    signed_url = "https//test.signed.url/lol"
    content = "this is some test content"

    content = content.encode('utf-8')
    mock_requests.set_responses({
        "get": {
            f"{api.API_URL}?id={file_id}": {
                "status_code": 200,
                "json": {
                    "signedUrl": [signed_url]
                }
            },
            signed_url: {
                "status_code": 404,
                "json": {
                    "_content": content
                },
            },
        },
    })
    open_mock = mock.mock_open()
    with mock.patch('builtins.open', open_mock, create=False):
        with pytest.raises(errors.DownloadException):
            api.get(file_id)
Beispiel #5
0
def test_get(mock_requests):
    file_id = "a7ds6s"
    signed_url = "https//test.signed.url/lol"
    content = "this is some test content"

    content = content.encode('utf-8')
    mock_requests.set_responses({
        "get": {
            f"{api.API_URL}?id={file_id}": {
                "status_code": 200,
                "json": {
                    "signedUrl": [signed_url]
                }
            },
            signed_url: {
                "status_code": 200,
                "json": {
                    "_content": content
                },
            },
        },
    })
    open_mock = mock.mock_open()
    with mock.patch('builtins.open', open_mock, create=False):
        api.get(file_id)
    open_mock.assert_called_once_with(file_id, 'wb')
    open_mock().write.assert_called_once_with(content)