Extra test for last published

main
Bob Mottram 2023-10-02 17:32:53 +01:00
parent 4602c7f7bc
commit 84469d16f0
2 changed files with 23 additions and 10 deletions

View File

@ -937,6 +937,23 @@ def delete_all_posts(base_dir: str,
print('ERROR: delete_all_posts ' + str(ex)) print('ERROR: delete_all_posts ' + str(ex))
def _save_last_published(base_dir: str, nickname: str, domain: str,
published: str) -> None:
"""Saves the last published date for the outbox
"""
if not published:
return
published_filename = \
acct_dir(base_dir, nickname, domain) + '/.last_published'
try:
with open(published_filename, 'w+', encoding='utf-8') as fp_last:
fp_last.write(published)
except OSError:
print('EX: unable to save last published time ' +
published_filename)
def save_post_to_box(base_dir: str, http_prefix: str, post_id: str, def save_post_to_box(base_dir: str, http_prefix: str, post_id: str,
nickname: str, domain: str, post_json_object: {}, nickname: str, domain: str, post_json_object: {},
boxname: str) -> str: boxname: str) -> str:
@ -970,16 +987,7 @@ def save_post_to_box(base_dir: str, http_prefix: str, post_id: str,
# if this is an outbox post with a duplicate in the inbox then save to both # if this is an outbox post with a duplicate in the inbox then save to both
# This happens for edited posts # This happens for edited posts
if '/outbox/' in filename: if '/outbox/' in filename:
if published: _save_last_published(base_dir, nickname, domain, published)
published_filename = \
acct_dir(base_dir, nickname, domain) + '/.last_published'
try:
with open(published_filename, 'w+',
encoding='utf-8') as fp_last:
fp_last.write(published)
except OSError:
print('EX: unable to save last published time ' +
published_filename)
inbox_filename = filename.replace('/outbox/', '/inbox/') inbox_filename = filename.replace('/outbox/', '/inbox/')
if os.path.isfile(inbox_filename): if os.path.isfile(inbox_filename):

View File

@ -1364,6 +1364,9 @@ def test_post_message_between_servers(base_dir: str) -> None:
is_article = False is_article = False
city = 'London, England' city = 'London, England'
# nothing in Alice's outbox # nothing in Alice's outbox
last_pub_filename = \
alice_dir + '/accounts/alice@' + alice_domain + '/.last_published'
assert not os.path.isfile(last_pub_filename)
outbox_path = alice_dir + '/accounts/alice@' + alice_domain + '/outbox' outbox_path = alice_dir + '/accounts/alice@' + alice_domain + '/outbox'
assert len([name for name in os.listdir(outbox_path) assert len([name for name in os.listdir(outbox_path)
if os.path.isfile(os.path.join(outbox_path, name))]) == 0 if os.path.isfile(os.path.join(outbox_path, name))]) == 0
@ -1412,6 +1415,8 @@ def test_post_message_between_servers(base_dir: str) -> None:
break break
time.sleep(1) time.sleep(1)
assert os.path.isfile(last_pub_filename)
# check that a news account exists # check that a news account exists
news_actor_dir = alice_dir + '/accounts/news@' + alice_domain news_actor_dir = alice_dir + '/accounts/news@' + alice_domain
print("news_actor_dir: " + news_actor_dir) print("news_actor_dir: " + news_actor_dir)