From 84469d16f0abbf94422c223ad8c7a8c70720917f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 2 Oct 2023 17:32:53 +0100 Subject: [PATCH] Extra test for last published --- posts.py | 28 ++++++++++++++++++---------- tests.py | 5 +++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/posts.py b/posts.py index 8b73bbb4b..93ea87e3c 100644 --- a/posts.py +++ b/posts.py @@ -937,6 +937,23 @@ def delete_all_posts(base_dir: str, 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, nickname: str, domain: str, post_json_object: {}, 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 # This happens for edited posts if '/outbox/' in filename: - if 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) + _save_last_published(base_dir, nickname, domain, published) inbox_filename = filename.replace('/outbox/', '/inbox/') if os.path.isfile(inbox_filename): diff --git a/tests.py b/tests.py index 643996344..f9c38f801 100644 --- a/tests.py +++ b/tests.py @@ -1364,6 +1364,9 @@ def test_post_message_between_servers(base_dir: str) -> None: is_article = False city = 'London, England' # 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' assert len([name for name in os.listdir(outbox_path) 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 time.sleep(1) + assert os.path.isfile(last_pub_filename) + # check that a news account exists news_actor_dir = alice_dir + '/accounts/news@' + alice_domain print("news_actor_dir: " + news_actor_dir)