diff --git a/.travis.yml b/.travis.yml index 4c6aad2..738f77b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ dist: xenial python: - 3.6 - 3.7 - - 3.8 install: - pip install -r test_requirements.txt script: diff --git a/CHANGES.rst b/CHANGES.rst index b8f0e23..4fc80dc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,12 @@ Changelog 1.0a7 (unreleased) ------------------ +- Add new API method `createfolderifnotexists` #19 + [Arkoniak, tomgross] + +- Fix duplication of data transfer on file upload #17 + [blasterspike, tomgross] + - Consistently use MIT licences [tomgross] @@ -22,13 +28,13 @@ Changelog [blasterspike] - Test and claim Python 3.7 compatibility - [tomgross] + [tomgross] 1.0a4 (2017-10-29) ------------------ - Fix error with duplicate files parameter #3 - [tomgross] + [tomgross] - Fix upload of data [tomgross] diff --git a/setup.cfg b/setup.cfg index aa7f8eb..c1b60e1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,7 +4,6 @@ ignore = .coveragerc .editorconfig .gitattributes - bootstrap-buildout.py [isort] # for details see diff --git a/src/pcloud/api.py b/src/pcloud/api.py index 4ad6b31..d802d51 100644 --- a/src/pcloud/api.py +++ b/src/pcloud/api.py @@ -132,7 +132,7 @@ def uploadfile(self, **kwargs): files = {filename: open(f, "rb")} # kwargs['filename'] = filename else: # 'data' in kwargs: - files = {"f": (kwargs.pop("filename"), kwargs.pop("data"))} + files = {"f": (kwargs.pop("filename", "data-upload.bin"), kwargs.pop("data"))} return self._upload("uploadfile", files, **kwargs) @RequiredParameterCheck(("progresshash",)) @@ -218,7 +218,7 @@ def file_truncate(self, **kwargs): @RequiredParameterCheck(("fd", "data")) def file_write(self, **kwargs): - files = {"filename": BytesIO(kwargs["data"])} + files = {"file": ('upload-file.io', BytesIO(kwargs.pop("data")))} return self._upload("file_write", files, **kwargs) @RequiredParameterCheck(("fd",)) diff --git a/src/pcloud/tests/conftest.py b/src/pcloud/tests/conftest.py index b6df3b0..f668966 100644 --- a/src/pcloud/tests/conftest.py +++ b/src/pcloud/tests/conftest.py @@ -12,9 +12,12 @@ def start_mock_server(): """ httpd = MockServer(("", PORT), MockHandler) httpd_thread = Thread(target=httpd.serve_forever) - httpd_thread.setDaemon(False) + httpd_thread.setDaemon(True) httpd_thread.start() + print("start") yield start_mock_server + print("teardown") + httpd_thread.join(1) httpd_thread._is_stopped = True httpd_thread._tstate_lock = None - httpd_thread._stop() + diff --git a/src/pcloud/tests/server.py b/src/pcloud/tests/server.py index 51ac43d..0747732 100644 --- a/src/pcloud/tests/server.py +++ b/src/pcloud/tests/server.py @@ -29,14 +29,15 @@ def do_POST(self): "CONTENT_TYPE": self.headers["Content-Type"], }, ) - print(form) - if "data" in form: - size = len(form.getvalue("data")) + if "upload.txt" in form: + file_ = form.getvalue("upload.txt") else: - size = len(form.getvalue("upload.txt")) + file_ = form.getvalue("file") + size = len(file_) self.send_response(200) self.send_header("Content-type", "applicaton/json") self.end_headers() + print(f"File: {file_}, Size: {size}", end='') # Send the json message self.wfile.write( bytes('{ "result": 0, "metadata": {"size": %s} }' % size, "utf-8") diff --git a/src/pcloud/tests/test_api.py b/src/pcloud/tests/test_api.py index aadf766..39869b2 100644 --- a/src/pcloud/tests/test_api.py +++ b/src/pcloud/tests/test_api.py @@ -1,5 +1,6 @@ # from pcloud import api +from pcloud.pcloudfs import PCloudFS import os.path import pytest @@ -10,8 +11,14 @@ class DummyPyCloud(api.PyCloud): endpoint = "http://localhost:{0}/".format(5000) +class DummyPCloudFS(PCloudFS): + + factory = DummyPyCloud + + @pytest.mark.usefixtures("start_mock_server") class TestPcloudApi(object): + def test_getdigest(self): api = DummyPyCloud("foo", "bar") assert api.getdigest() == b"YGtAxbUpI85Zvs7lC7Z62rBwv907TBXhV2L867Hkh" @@ -27,3 +34,16 @@ def test_upload_files(self): "result": 0, "metadata": {"size": 14}, } + + +@pytest.mark.usefixtures("start_mock_server") +class TestPcloudFs(object): + + def test_write(self, capsys): + with DummyPCloudFS(username="foo", password="bar") as fs: + data = b"hello pcloud fs unittest" + fs_f = fs.openbin("hello.bin") + fs_f.write(data) + captured = capsys.readouterr() + assert captured.out == "File: b'hello pcloud fs unittest', Size: 24" + diff --git a/src/pcloud/tests/test_fs.py b/src/pcloud/tests/test_fs.py deleted file mode 100644 index 5478d5a..0000000 --- a/src/pcloud/tests/test_fs.py +++ /dev/null @@ -1,26 +0,0 @@ -from pcloud.pcloudfs import PCloudFS -from pcloud.tests.test_api import DummyPyCloud - -import pytest - - -class DummyPCloudFS(PCloudFS): - - factory = DummyPyCloud - - -@pytest.mark.usefixtures("start_mock_server") -class TestPcloudFs(object): - def test_write(self): - with DummyPCloudFS(username="foo", password="bar") as fs: - - #  testfile = os.path.join(os.path.dirname(__file__), 'data', 'upload.txt') - # assert api.uploadfile(files=[testfile]) == {"result": 0, - # - # "metadata": {"size": 14}} - data = b"hello unittest" - fs_f = fs.openbin("hello.bin") - foo = fs_f.write(data) - print(foo) - # import pdb; pdb.set_trace() - assert True