Skip to content

Commit

Permalink
Add failing test for oauth listtoken issue #61
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Apr 3, 2023
1 parent d76a9b7 commit fd30e06
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/pcloud/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ def get_access_token(self):
http_server = HTTPServer(("localhost", PORT), HTTPServerHandler)

# Solution taken from https://stackoverflow.com/a/12651298
# There might be better ways than accessing internal methods
# There might be better ways than accessing the internal
# _thread library for starting the http-server non-blocking
# but I did not found any ;-)
def start_server():
http_server.serve_forever()
http_server.handle_request()

_thread.start_new_thread(start_server, ())
self.open_browser()
self.close_browser()
http_server.server_close()
return http_server.access_token, http_server.pc_hostname
5 changes: 5 additions & 0 deletions src/pcloud/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ def test_copyfile(pycloud, testfolder):
resp["sha256"]
== "df745d42f69266c49141ea7270c45240cf883b9cdb6a14fffcdff33c04c5304c"
)

def test_listtokens(pycloud):
result = pycloud.listtokens()
assert result['result'] == 0
assert len(result['tokens']) > 1
6 changes: 3 additions & 3 deletions src/pcloud/tests/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ def open_browser(self):
page = self.browser.new_page()
log.info(self.auth_url)
page.goto(self.auth_url)

page.get_by_placeholder("Email").fill(os.environ.get("PCLOUD_USERNAME"))

page.get_by_text("Continue").click()

page.get_by_placeholder("Password").fill(os.environ.get("PCLOUD_PASSWORD"))
page.get_by_text("Log in").click()
expect(page.get_by_text("You may now close this window.")).to_be_visible()
Expand Down Expand Up @@ -64,3 +61,6 @@ def test_upload_download_roundrobin(pycloud_oauth2, testfolder):
assert result == bytes(f.read(), "utf-8")
result = pycloud_oauth2.file_close(fd=fd)
assert result["result"] == 0

def test_listtokens(pycloud_oauth2):
assert pycloud_oauth2.listtokens() == {'a'}

0 comments on commit fd30e06

Please sign in to comment.