Skip to content

Adjusted apps.ExAppInfo dataclass. #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2023
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ All notable changes to this project will be documented in this file.

## [0.4.0 - 2023-10-2x]

As the project moves closer to `beta`, final unification changes are being made.
This release contains some breaking changes in `users` API.

### Changed

- `users.get_details` renamed to `get_user` and returns a class instead of a dictionary.
- `users.get_details` renamed to `get_user` and returns a class instead of a dictionary. #145
- Optional argument `displayname` in `users.create` renamed to `display_name`.
- The `apps.ExAppInfo` class has been rewritten in the same format as all the others.

### Fixed

Expand Down
53 changes: 34 additions & 19 deletions nc_py_api/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Nextcloud API for working with applications."""

import dataclasses
import datetime
import typing

from ._misc import require_capabilities
Expand All @@ -11,26 +12,40 @@
class ExAppInfo:
"""Information about the External Application."""

app_id: str
"""`ID` of the application"""
name: str
"""Display name"""
version: str
"""Version of the application"""
enabled: bool
"""Flag indicating if the application enabled"""
last_check_time: int
"""UTC time of last successful application check"""
system: bool
"""Flag indicating if the application is a system application"""

def __init__(self, raw_data: dict):
self.app_id = raw_data["id"]
self.name = raw_data["name"]
self.version = raw_data["version"]
self.enabled = bool(raw_data["enabled"])
self.last_check_time = raw_data["last_check_time"]
self.system = raw_data["system"]
self._raw_data = raw_data

@property
def app_id(self) -> str:
"""`ID` of the application."""
return self._raw_data["id"]

@property
def name(self) -> str:
"""Display name."""
return self._raw_data["name"]

@property
def version(self) -> str:
"""Version of the application."""
return self._raw_data["version"]

@property
def enabled(self) -> bool:
"""Flag indicating if the application enabled."""
return bool(self._raw_data["enabled"])

@property
def last_check_time(self) -> datetime.datetime:
"""Time of the last successful application check."""
return datetime.datetime.utcfromtimestamp(int(self._raw_data["last_check_time"])).replace(
tzinfo=datetime.timezone.utc
)

@property
def system(self) -> bool:
"""Flag indicating if the application is a system application."""
return bool(self._raw_data["system"])


class _AppsAPI:
Expand Down
4 changes: 3 additions & 1 deletion tests/actual_tests/apps_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

import pytest

APP_NAME = "files_trashbin"
Expand Down Expand Up @@ -68,7 +70,7 @@ def test_ex_app_get_list(nc, nc_app):
assert isinstance(app.name, str)
assert isinstance(app.version, str)
assert isinstance(app.enabled, bool)
assert isinstance(app.last_check_time, int)
assert isinstance(app.last_check_time, datetime.datetime)
assert isinstance(app.system, bool)
if app.app_id == "nc_py_api":
assert app.system is True