Skip to content

Commit

Permalink
Refactored to include URL Tags and Assets
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Aug 19, 2023
1 parent dc2daab commit d1ebea9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
10 changes: 8 additions & 2 deletions apprise/Apprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
"""
Expand Down
33 changes: 25 additions & 8 deletions test/test_apprise_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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

Expand All @@ -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

0 comments on commit d1ebea9

Please sign in to comment.