Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevo committed Aug 19, 2021
1 parent 5db96bd commit ee02ce2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 55 deletions.
2 changes: 1 addition & 1 deletion pyflarum/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def get_post_by_id(self, id: int) -> Post:
return Post(user=self, _fetched_data=json)


def get_discussions(self, filter: Optional[Filter]=None):
def get_discussions(self, filter: Optional[Filter]=None) -> Discussions:
"""
Obtains all discussions from `/api/discussions`, optionally filtering results by using `filter`.
"""
Expand Down
2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path


ROOT_PATH = Path(__file__).parent.parent.absolute()
TESTS_PATH = Path(__file__).parent.absolute()
8 changes: 4 additions & 4 deletions tests/edit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

if __name__ == "__main__":
# Edit first post of discussion with ID 16 to the current time.
discussion = user.get_discussion_by_id(16)
first_post = discussion.get_posts()[0]
first_discussion = user.get_discussions().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=discussion, content=edited_content)
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 {discussion.id} is not a comment (but {first_post.contentType}), editing that is not possible.")
print(f"First post of discussion ID {first_discussion.id} is not a comment (but {first_post.contentType}), editing that is not possible.")
5 changes: 3 additions & 2 deletions tests/get_likes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@

from pyflarum import FlarumUser
from pyflarum.extensions.flarum import Flarum_Likes
from pyflarum.flarum.core.posts import PostFromBulk


USER = FlarumUser(forum_url=os.environ['forum_url'], username_or_email='test', password=os.environ['account_password'], extensions=[Flarum_Likes.LikesExtension])


if __name__ == "__main__":
discussion = USER.get_discussion_by_id(4)
discussion = USER.get_discussions().get_discussions()[0].get_full_data()

for post in discussion.get_posts():
post: Flarum_Likes.LikesPostFromBulkMixin
post: 'Flarum_Likes.LikesPostFromBulkMixin | PostFromBulk'

liked_by = post.get_liked_by()

Expand Down
20 changes: 7 additions & 13 deletions tests/like_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
load_dotenv()

import os
import time
#import time

from pyflarum import FlarumUser
from pyflarum.extensions.flarum import Flarum_Likes
from pyflarum.extensions import absolutely_all
from pyflarum.flarum.core.posts import PostFromBulk


USER = FlarumUser(
Expand All @@ -20,17 +21,10 @@
if __name__ == "__main__":
for posts in USER.absolutely_all_posts():
for post in posts:
post: Flarum_Likes.LikesPostFromBulkMixin
post: 'Flarum_Likes.LikesPostFromBulkMixin | PostFromBulk'

for user in post.get_liked_by():
if user.id == USER.data.id:
print(f"Post {post.id} ({post.url}) is already liked by me, skipping...")
liked = post.like()
print(f"Liked post {liked.id} ({liked.url})")
# time.sleep(1)

break

else:
liked = post.like()
print(f"Liked post {liked.id} ({liked.url})")
# time.sleep(1)

continue
continue
35 changes: 0 additions & 35 deletions tests/test.py

This file was deleted.

0 comments on commit ee02ce2

Please sign in to comment.