From d1ebea97c258250ad142e34f7d14f6fcecb19a0e Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sat, 19 Aug 2023 17:07:15 -0400 Subject: [PATCH] Refactored to include URL Tags and Assets --- apprise/Apprise.py | 10 ++++++++-- test/test_apprise_pickle.py | 33 +++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/apprise/Apprise.py b/apprise/Apprise.py index 82d91d7570..aa681d93f7 100644 --- a/apprise/Apprise.py +++ b/apprise/Apprise.py @@ -825,7 +825,12 @@ def __getstate__(self): """ attributes = { 'asset': self.asset, - 'urls': self.urls(), + # Prepare our URL list as we need to extract the associated tags + # and asset details associated with it + 'urls': [{ + 'url': server.url(privacy=False), + 'tag': server.tags if server.tags else None, + 'asset': server.asset} for server in self.servers], 'locale': self.locale, 'debug': self.debug, 'location': self.location, @@ -841,7 +846,8 @@ def __setstate__(self, state): self.asset = state['asset'] self.locale = state['locale'] self.location = state['location'] - self.add(state['urls']) + for entry in state['urls']: + self.add(entry['url'], asset=entry['asset'], tag=entry['tag']) def __bool__(self): """ diff --git a/test/test_apprise_pickle.py b/test/test_apprise_pickle.py index 0ad1d5021f..d09d17b0c0 100644 --- a/test/test_apprise_pickle.py +++ b/test/test_apprise_pickle.py @@ -47,8 +47,8 @@ def test_apprise_pickle_asset(tmpdir): """pickle: AppriseAsset """ asset = AppriseAsset() - encoded = pickle.dumps(asset) - new_asset = pickle.loads(encoded) + serialized = pickle.dumps(asset) + new_asset = pickle.loads(serialized) # iterate over some keys to verify they're still the same: keys = ( @@ -67,8 +67,8 @@ def test_apprise_pickle_locale(tmpdir): """pickle: AppriseLocale """ _locale = AppriseLocale.AppriseLocale() - encoded = pickle.dumps(_locale) - new_locale = pickle.loads(encoded) + serialized = pickle.dumps(_locale) + new_locale = pickle.loads(serialized) assert _locale.lang == new_locale.lang @@ -79,13 +79,30 @@ def test_apprise_pickle_locale(tmpdir): def test_apprise_pickle_core(tmpdir): """pickle: Apprise """ - apobj = Apprise() + asset = AppriseAsset(app_id="default") + apobj = Apprise(asset=asset) + # Create a custom asset so we can verify it gets correctly serialized + xml_asset = AppriseAsset(app_id="xml") + + # Store our Entries apobj.add("json://localhost") - apobj.add("xml://localhost") + apobj.add("xml://localhost", asset=xml_asset) apobj.add("form://localhost") apobj.add("mailto://user:pass@localhost", tag="email") - encoded = pickle.dumps(apobj) + serialized = pickle.dumps(apobj) + + # Unserialize our object + new_apobj = pickle.loads(serialized) - new_apobj = pickle.loads(encoded) + # Verify that it loaded our URLs back assert len(new_apobj) == 4 + + # Our assets were kept (note the XML altered entry) + assert apobj[0].app_id == "default" + assert apobj[1].app_id == "xml" + assert apobj[2].app_id == "default" + assert apobj[3].app_id == "default" + + # Our tag was kept + assert "email" in apobj[3].tags