def test_first_post(): USER = FlarumUser(forum_url=os.environ['forum_url'], username_or_email='test', password=os.environ['account_password']) discussion = USER.get_discussions()[ 0] # discussion on top of the front page with default filters print(discussion.title) notifications = USER.get_notifications() notifications.mark_all_as_read()
def test_get_likes(): USER = FlarumUser(forum_url=os.environ['forum_url'], username_or_email='test', password=os.environ['account_password'], extensions=[Flarum_Likes.LikesExtension]) discussion = USER.get_discussions()[0].get_full_data() # type: Discussion for post in discussion.get_posts(): post: 'Flarum_Likes.LikesPostFromBulkMixin' liked_by = post.get_liked_by() if len(liked_by) > 0: print(f"Post {post.id} ({post.url}) was liked by:") for user in post.get_liked_by(): print(user.username)
def test_edit(): USER = FlarumUser(forum_url=os.environ['forum_url'], username_or_email='test', password=os.environ['account_password']) # Edit first post of discussion with ID 16 to the current time. first_discussion = USER.get_discussions()[0].get_full_data() first_post = first_discussion.get_posts()[0] if first_post.contentType == 'comment': edited_content = f"""{first_post.content}\n###### BTW, The current time for me, the bot, is: {datetime.now().time().strftime(r"%H hours, %M minutes and %S seconds.")}.""" edit = PreparedPost(user=USER, discussion=first_discussion, content=edited_content) edited = first_post.edit(edit) print(f"Successfuly edited post {edited.id} - {edited.url}") else: print( f"First post of discussion ID {first_discussion.id} is not a comment (but {first_post.contentType}), editing that is not possible." )