def _mockFileExists(tempFile: File, b2FileId: str = "someId") -> None:
    bucket.get_file_info_by_name.side_effect = None
    bucket.get_file_info_by_name.return_value = FileVersionInfoFactory.from_response_headers(
        {
            "x-bz-file-id": b2FileId,
            "content-length": tempFile.size
        })
 def existOrThrow():
     if doesFileExist():
         return FileVersionInfoFactory.from_response_headers({
             "id":
             id,
             "content-length":
             size
         })
     raise FileNotPresent()
Пример #3
0
def test_get_available_nameWithOverwrites(settings):
    mockedBucket = mock.Mock(spec=Bucket)
    mockedBucket.get_file_info_by_name.return_value = FileVersionInfoFactory.from_response_headers(
        {
            "id_": 1,
            "file_name": "some_name.txt"
        })

    with mock.patch.object(settings, "BACKBLAZE_CONFIG",
                           _settingsDict({})), mock.patch.object(
                               B2Api, "authorize_account"), mock.patch.object(
                                   B2Api, "get_bucket_by_name") as api:
        api.return_value = mockedBucket
        storage = BackblazeB2Storage(opts={"allowFileOverwrites": True})

        availableName = storage.get_available_name("some_name.txt",
                                                   max_length=None)

        assert availableName == "some_name.txt"