diff --git a/pubnub/pnconfiguration.py b/pubnub/pnconfiguration.py index ac1316ee..72d3ecfa 100644 --- a/pubnub/pnconfiguration.py +++ b/pubnub/pnconfiguration.py @@ -1,5 +1,6 @@ import warnings from typing import Any +from copy import deepcopy from Cryptodome.Cipher import AES from pubnub.enums import PNHeartbeatNotificationOptions, PNReconnectionPolicy from pubnub.exceptions import PubNubException @@ -179,6 +180,11 @@ def user_id(self, user_id): def lock(self): self.__dict__['_locked'] = False if self.disable_config_locking else True + def copy(self): + config_copy = deepcopy(self) + config_copy.__dict__['_locked'] = False + return config_copy + def __setattr__(self, name: str, value: Any) -> None: if self._locked: warnings.warn(UserWarning('Configuration is locked. Any changes made won\'t have any effect')) diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index 587a5a8c..0605295e 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -107,3 +107,15 @@ async def test_asyncio_config_mutability_lock_disabled(self): config.user_id = 'test' assert pubnub.config.user_id == 'test' + + def test_config_copy(self): + config = PNConfiguration() + config.disable_config_locking = False + config.publish_key = 'demo' + config.subscribe_key = 'demo' + config.user_id = 'demo' + config.lock() + config_copy = config.copy() + assert id(config) != id(config_copy) + assert config._locked is True + assert config_copy._locked is False