Skip to content

Commit

Permalink
Add test for oauth2
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Dec 15, 2021
1 parent d327924 commit 2f879f5
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ pyvenv.cfg
.idea
/share
Pipfile*
*.whl
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
1.0b2 (unreleased)
------------------

- Build wheel package
- Build wheel package [tomgross]
- Fix file upload with oauth [giust]

1.0b1 (2021-11-26)
------------------
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ OAuth 2.0 with PyCloud on your machine. For the communication with pCloud PyClou
builtin `webserver`-module.

>>> from pcloud import PyCloud
>>> pc = api.PyCloud.oauth2_authorize(client_id="XYZ", client_secret="abc123")
>>> pc = PyCloud.oauth2_authorize(client_id="XYZ", client_secret="abc123")
>>> pc.listfolder(folderid=0)

Uploading files
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[zest.releaser]
with create-wheel = yes
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Environment :: Console",
"Environment :: Other Environment",
"Environment :: Web Environment",
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
Expand All @@ -32,6 +34,7 @@
"Programming Language :: Python :: 3.10",
"Operating System :: OS Independent",
"License :: OSI Approved :: MIT License",
"Topic :: Software Development :: Libraries :: Python Modules",
],
keywords="Python pCloud REST",
author="Tom Gross",
Expand Down
2 changes: 1 addition & 1 deletion src/pcloud/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_publink_zip_with_unzip(pycloud):

def test_publink_zip(pycloud):
zipresponse = pycloud.getpubzip(code=public_code)
# I,m not sure, if zipping is deterministic,
# I'm not sure, if zipping is deterministic,
# so let's only check, if we find a valid ZIP file
zipfmem = BytesIO(zipresponse)
zf = zipfile.ZipFile(zipfmem)
Expand Down
36 changes: 36 additions & 0 deletions src/pcloud/tests/test_oauth2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import pytest

from pathlib import Path
from pcloud.api import PyCloud
from pcloud.api import O_CREAT


folder_for_tests = "integration-test"


@pytest.fixture
def pycloud_oauth2():
access_token = os.environ.get("PCLOUD_OAUTH2_TOKEN")
return PyCloud("", access_token, endpoint="eapi", oauth2=True)


@pytest.fixture
def testfolder(pycloud_oauth2):
pycloud_oauth2.createfolder(folderid=0, name=folder_for_tests)
yield folder_for_tests
pycloud_oauth2.deletefolderrecursive(path=f"/{folder_for_tests}")


def test_upload_download_roundrobin(pycloud_oauth2, testfolder):
testfile = testfile = Path(__file__).parent / "data" / "upload.txt"
result = pycloud_oauth2.uploadfile(path=f"/{testfolder}", files=[testfile])
size = result["metadata"][0]["size"]
assert result["result"] == 0
assert size == 14
fd = pycloud_oauth2.file_open(path=f"/{folder_for_tests}/upload.txt", flags=O_CREAT)["fd"]
result = pycloud_oauth2.file_read(fd=fd, count=size)
with open(testfile) as f:
assert result == bytes(f.read(), "utf-8")
result = pycloud_oauth2.file_close(fd=fd)
assert result["result"] == 0

0 comments on commit 2f879f5

Please sign in to comment.