def test_upload_from_directory(self, mock_file_upload_response):
     path = os.path.join(os.path.dirname(__file__), "files_for_test_upload")
     res = FILES_API.upload(path=path)
     response_body = mock_file_upload_response.calls[0].response.json()
     del response_body["uploadUrl"]
     assert FileMetadataList([FileMetadata._load(response_body), FileMetadata._load(response_body)]) == res
     assert 4 == len(mock_file_upload_response.calls)
     for call in mock_file_upload_response.calls:
         payload = call.request.body
         if isinstance(payload, BufferedReader):
             continue
         elif jsgz_load(payload)["name"] in ["file_for_test_upload_1.txt", "file_for_test_upload_2.txt"]:
             continue
         else:
             raise AssertionError("incorrect payload: {}".format(payload))
 def test_upload_from_memory(self, mock_file_upload_response):
     res = FILES_API.upload_bytes(content=b"content", name="bla")
     response_body = mock_file_upload_response.calls[0].response.json()
     del response_body["uploadUrl"]
     assert FileMetadata._load(response_body) == res
     assert "https://upload.here/" == mock_file_upload_response.calls[1].request.url
     assert {"name": "bla"} == jsgz_load(mock_file_upload_response.calls[0].request.body)
     assert b"content" == mock_file_upload_response.calls[1].request.body
 def test_upload(self, mock_file_upload_response):
     path = os.path.join(os.path.dirname(__file__), "files_for_test_upload", "file_for_test_upload_1.txt")
     res = FILES_API.upload(path, name="bla")
     response_body = mock_file_upload_response.calls[0].response.json()
     del response_body["uploadUrl"]
     assert FileMetadata._load(response_body) == res
     assert "https://upload.here/" == mock_file_upload_response.calls[1].request.url
     assert {"name": "bla"} == jsgz_load(mock_file_upload_response.calls[0].request.body)
     assert isinstance(mock_file_upload_response.calls[1].request.body, BufferedReader)
 def test_upload_using_file_handle(self, mock_file_upload_response):
     path = os.path.join(os.path.dirname(__file__), "files_for_test_upload", "file_for_test_upload_1.txt")
     with open(path) as fh:
         res = FILES_API.upload_bytes(fh, name="bla")
     response_body = mock_file_upload_response.calls[0].response.json()
     del response_body["uploadUrl"]
     assert FileMetadata._load(response_body) == res
     assert "https://upload.here/" == mock_file_upload_response.calls[1].request.url
     assert {"name": "bla"} == jsgz_load(mock_file_upload_response.calls[0].request.body)
     assert isinstance(mock_file_upload_response.calls[1].request.body, TextIOWrapper)
Example #5
0
 def test_upload_from_directory(self, mock_file_upload_response):
     path = os.path.join(os.path.dirname(__file__), "files_for_test_upload")
     res = FILES_API.upload(path=path, asset_ids=[1, 2])
     response_body = mock_file_upload_response.calls[0].response.json()
     del response_body["uploadUrl"]
     assert FileMetadataList([
         FileMetadata._load(response_body),
         FileMetadata._load(response_body)
     ]) == res
     assert 4 == len(mock_file_upload_response.calls)
     for call in mock_file_upload_response.calls:
         payload = call.request.body
         if isinstance(payload, BufferedReader):
             continue
         else:
             json = jsgz_load(payload)
             assert [1, 2] == json["assetIds"]
             assert json["name"] in [
                 "file_for_test_upload_1.txt", "file_for_test_upload_2.txt"
             ]
 def test_create(self, mock_file_create_response):
     file_metadata = FileMetadata(name="bla")
     returned_file_metadata, upload_url = FILES_API.create(file_metadata)
     response_body = mock_file_create_response.calls[0].response.json()
     assert FileMetadata._load(response_body) == returned_file_metadata
     assert response_body["uploadUrl"] == upload_url