mirror of
https://github.com/ProtoThis/python-synology.git
synced 2026-01-19 09:28:42 +00:00
@ -273,6 +273,34 @@ class SynologyDSM(object):
|
||||
data = self.get(SynoStorage.API_KEY, "load_info")
|
||||
self._storage.update(data)
|
||||
|
||||
def reset(self, api):
|
||||
"""Reset an API to avoid fetching in on update."""
|
||||
if isinstance(api, str):
|
||||
if api in ("information", SynoDSMInformation.API_KEY):
|
||||
return False
|
||||
if hasattr(self, "_" + api):
|
||||
setattr(self, "_" + api, None)
|
||||
return True
|
||||
if api == SynoCoreSecurity.API_KEY:
|
||||
self._security = None
|
||||
return True
|
||||
if api == SynoCoreUtilization.API_KEY:
|
||||
self._utilisation = None
|
||||
return True
|
||||
if api == SynoStorage.API_KEY:
|
||||
self._storage = None
|
||||
return True
|
||||
if isinstance(api, SynoCoreSecurity):
|
||||
self._security = None
|
||||
return True
|
||||
if isinstance(api, SynoCoreUtilization):
|
||||
self._utilisation = None
|
||||
return True
|
||||
if isinstance(api, SynoStorage):
|
||||
self._storage = None
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def information(self):
|
||||
"""Gets NAS informations."""
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
"""Synology DSM tests."""
|
||||
from unittest import TestCase
|
||||
|
||||
from synology_dsm.api.core.security import SynoCoreSecurity
|
||||
from synology_dsm.api.dsm.information import SynoDSMInformation
|
||||
from synology_dsm.exceptions import (
|
||||
SynologyDSMRequestException,
|
||||
SynologyDSMAPINotExistsException,
|
||||
@ -188,6 +190,54 @@ class TestSynologyDSM(TestCase):
|
||||
},
|
||||
)
|
||||
|
||||
def test_reset_str_attr(self):
|
||||
"""Test reset with string attr."""
|
||||
assert not self.api._security
|
||||
assert self.api.security
|
||||
assert self.api._security
|
||||
assert self.api.reset("security")
|
||||
assert not self.api._security
|
||||
|
||||
def test_reset_str_key(self):
|
||||
"""Test reset with string API key."""
|
||||
assert not self.api._security
|
||||
assert self.api.security
|
||||
assert self.api._security
|
||||
assert self.api.reset(SynoCoreSecurity.API_KEY)
|
||||
assert not self.api._security
|
||||
|
||||
def test_reset_object(self):
|
||||
"""Test reset with object."""
|
||||
assert not self.api._security
|
||||
assert self.api.security
|
||||
assert self.api._security
|
||||
assert self.api.reset(self.api.security)
|
||||
assert not self.api._security
|
||||
|
||||
def test_reset_str_attr_information(self):
|
||||
"""Test reset with string information attr (should not be reset)."""
|
||||
assert not self.api._information
|
||||
assert self.api.information
|
||||
assert self.api._information
|
||||
assert not self.api.reset("information")
|
||||
assert self.api._information
|
||||
|
||||
def test_reset_str_key_information(self):
|
||||
"""Test reset with string information API key (should not be reset)."""
|
||||
assert not self.api._information
|
||||
assert self.api.information
|
||||
assert self.api._information
|
||||
assert not self.api.reset(SynoDSMInformation.API_KEY)
|
||||
assert self.api._information
|
||||
|
||||
def test_reset_object_information(self):
|
||||
"""Test reset with information object (should not be reset)."""
|
||||
assert not self.api._information
|
||||
assert self.api.information
|
||||
assert self.api._information
|
||||
assert not self.api.reset(self.api.information)
|
||||
assert self.api._information
|
||||
|
||||
def test_information(self):
|
||||
"""Test information."""
|
||||
assert self.api.information
|
||||
|
||||
Reference in New Issue
Block a user