80 lines
1.9 KiB
Python
80 lines
1.9 KiB
Python
import os
|
|
import pickle
|
|
|
|
from dateutil.tz import tzutc
|
|
|
|
from sqlalchemy import select
|
|
|
|
from models import (
|
|
Hashtags,
|
|
Posts,
|
|
)
|
|
from urma import (
|
|
process_bookmarked_posts,
|
|
process_favourited_posts,
|
|
)
|
|
|
|
BOOSTED_POST = "tests/boosted.pickle"
|
|
BOOSTING_POST = "tests/boosting.pickle"
|
|
FAVOURITED_POST = "tests/favourited.pickle"
|
|
ME_ID = 109568725613662482
|
|
|
|
|
|
def test_process_favourited_no_fave(session):
|
|
"""Test post not marked as favourite"""
|
|
|
|
with open(FAVOURITED_POST, "rb") as inp:
|
|
posts = pickle.load(inp)
|
|
|
|
# Sanity check
|
|
assert len(posts) == 1
|
|
|
|
# Set not favourited
|
|
posts[0]['favourited'] = False
|
|
|
|
process_favourited_posts(session, posts, ME_ID)
|
|
|
|
all_posts = session.execute(select(Posts)).scalars().all()
|
|
assert len(all_posts) == 0
|
|
|
|
|
|
def test_process_favourited_with_fave(session):
|
|
"""Test post marked as favourite"""
|
|
|
|
with open(FAVOURITED_POST, "rb") as inp:
|
|
posts = pickle.load(inp)
|
|
|
|
# Sanity check
|
|
assert len(posts) == 1
|
|
|
|
process_favourited_posts(session, posts, ME_ID)
|
|
|
|
all_posts = session.execute(select(Posts)).scalars().all()
|
|
assert len(all_posts) == 1
|
|
|
|
original_post = posts[0]
|
|
retrieved_post = all_posts[0]
|
|
|
|
assert original_post.id == int(retrieved_post.post_id)
|
|
assert original_post.account.id == int(retrieved_post.account.account_id)
|
|
assert original_post.created_at == retrieved_post.created_at
|
|
assert retrieved_post.favourited is True
|
|
|
|
|
|
def test_process_post_hashtags(session):
|
|
"""Test hashtags correctly parsed"""
|
|
|
|
with open(FAVOURITED_POST, "rb") as inp:
|
|
posts = pickle.load(inp)
|
|
|
|
# Sanity check
|
|
assert len(posts) == 1
|
|
|
|
process_favourited_posts(session, posts, ME_ID)
|
|
|
|
all_tags = Hashtags.get_all(session)
|
|
|
|
expected = ['fdroid', 'apps', 'android', 'foss', 'free', 'AndroidAppRain']
|
|
for hashtag in all_tags:
|
|
assert hashtag.name in expected
|