Пример #1
0
    def test_put_all_success(self):
        '''Make sure everything works in no-error scenario.

        '''

        self.setup(psuccess=1.)

        responses.add_callback(responses.PUT,
                               self.dst_url,
                               callback=self.callback,
                               content_type='application/json')

        for _ in range(N):
            data = {'sample': 'data'}
            put_request(self.dst_url, data)
Пример #2
0
def put_image_type(dataset_id: str, token: str, img_type: str):
    """Adds the attribute imgType to the db dataset entry.

    Args:
        dataset_id:
            Identifier of the dataset.
        token:
            The token for authenticating the request.
        img_type:
            Whether the sample was fully uploaded (full), only a thumbnail
            (thumbnail) or only metadata (meta).

    Returns:
        A boolean value indicating a successful put request.

    Raises:
        RuntimeError if put was not successful.

    """
    dst_url = _prefix(dataset_id=dataset_id)
    payload = {'token': token}

    data = {'dataset': {'imgType': img_type}}

    response = put_request(dst_url, json=data, params=payload)
    return response
Пример #3
0
    def test_put_no_success(self):
        '''Make sure everything works in no-error scenario.

        '''

        self.setup(psuccess=0.)

        responses.add_callback(
            responses.PUT, self.dst_url,
            callback=self.callback,
            content_type='application/json'
        )

        with self.assertRaises(RuntimeError):
            data = {'sample': 'data'}
            put_request(self.dst_url, data)
Пример #4
0
def upload_file_with_signed_url(file, url: str) -> bool:
    """Upload a file to the cloud storage using a signed URL.

    Args:
        filename:
            Path to a file for upload.
        url:
            Signed url for push.

    Returns:
        A boolean value indicating successful upload.

    Raises:
        RuntimeError if put request failed.
    """
    response = put_request(url, data=file)
    file.close()
    return response
Пример #5
0
 def upload_file_with_signed_url(self, file, signed_write_url: str):
     response = put_request(signed_write_url, data=file)
     file.close()
     return response