Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions nc_py_api/nextcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ def theme(self) -> ThemingInfo | None:
"""Returns Theme information."""
return get_parsed_theme(self.capabilities["theming"]) if "theming" in self.capabilities else None

def perform_login(self) -> bool:
"""Performs login into Nextcloud if not already logged in; manual invocation of this method is unnecessary."""
try:
self.update_server_info()
except Exception: # noqa pylint: disable=broad-exception-caught
return False
return True

def ocs(
self,
method: str,
Expand Down Expand Up @@ -199,6 +207,14 @@ async def theme(self) -> ThemingInfo | None:
"""Returns Theme information."""
return get_parsed_theme((await self.capabilities)["theming"]) if "theming" in await self.capabilities else None

async def perform_login(self) -> bool:
"""Performs login into Nextcloud if not already logged in; manual invocation of this method is unnecessary."""
try:
await self.update_server_info()
except Exception: # noqa pylint: disable=broad-exception-caught
return False
return True

async def ocs(
self,
method: str,
Expand Down
15 changes: 15 additions & 0 deletions tests/actual_tests/misc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,18 @@ async def test_public_ocs_async(anc_any):
r = await anc_any.ocs("GET", "/ocs/v1.php/cloud/capabilities")
assert r == await anc_any.ocs("GET", "ocs/v1.php/cloud/capabilities")
assert r == await anc_any._session.ocs("GET", "ocs/v1.php/cloud/capabilities") # noqa


def test_perform_login(nc_any):
new_nc = Nextcloud() if isinstance(nc_any, Nextcloud) else NextcloudApp()
assert not new_nc._session._capabilities
new_nc.perform_login()
assert new_nc._session._capabilities


@pytest.mark.asyncio(scope="session")
async def test_perform_login_async(anc_any):
new_nc = AsyncNextcloud() if isinstance(anc_any, Nextcloud) else AsyncNextcloudApp()
assert not new_nc._session._capabilities
await new_nc.perform_login()
assert new_nc._session._capabilities