Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions adoption_sources/rescue_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,6 @@ def _clean_description(self, description: str) -> str:
r"\*\*Home for the Holidays.*?\*\*", "", text, flags=re.IGNORECASE
)

# Trim to reasonable length for social posts
text = text.strip()
if len(text) > 500:
text = text[:497] + "..."

return text

def _get_image_url(self, attrs: dict) -> str | None:
Expand Down
18 changes: 17 additions & 1 deletion manual_testing/mastodon_manual_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ def post_within_500_chars_limit_without_adoption_link():
)
return pet

def post_about_800_chars_with_adoption_link():
pet = AdoptablePet("Kool-Aid Man",
"Unknown",
"Unknown",
"Quahog",
"OH YEAH!"*100,
None,
"https://static.wikia.nocookie.net/familyguy/images/8/8b/Koolaid.jpg/revision/latest?cb=20090128174245",
None,
"Unknown",
None,
None
)
return pet

def post_unicode():
pet = AdoptablePet("Vinny",
"Unknown",
Expand All @@ -82,7 +97,8 @@ def post_unicode():
return pet

testing_cases = [
post_exceed_500_chars_limit_with_adoption_link,
#post_exceed_500_chars_limit_with_adoption_link,
post_about_800_chars_with_adoption_link,
#post_exceed_500_chars_limit_without_adoption_link,
#post_within_500_chars_limit_with_adoption_link,
#post_within_500_chars_limit_without_adoption_link,
Expand Down
39 changes: 38 additions & 1 deletion tests/test_mastodon.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abstractions import AdoptablePet, Post
from hypothesis import given, strategies as st
from hypothesis import given, strategies as st, assume
import pytest
from social_posters.mastodon import (
PosterMastodon,
Expand All @@ -23,6 +23,14 @@
max_size=3,
)

caption_text = st.text(
alphabet=st.characters(
blacklist_categories=("Cs", "Cc"),
),
min_size=0,
max_size=5000,
)

text_strategy = st.text(
alphabet=st.characters(blacklist_categories=("Cs",)),
min_size=0,
Expand Down Expand Up @@ -156,6 +164,35 @@ def test_format_post_output_stays_under_mastodon_limit_after_splitting(self, pet
assert len(main_caption) <= MASTODON_CHARACTER_LIMIT
assert all(len(reply) <= MASTODON_CHARACTER_LIMIT for reply in replies)
assert len(replies) <= MAX_REPLIES

@given(
text=caption_text,
limit=st.integers(min_value=1, max_value=10),
)
def test_safe_truncate_correctly(self, text, limit):
fst, snd = self.poster._safe_truncate(text, limit)

assert len(fst) <= limit

if len(text) <= limit:
assert fst == text
assert snd == ""
else:
assert fst == fst.rstrip()
assert snd == snd.strip()

@given(
text=st.text(),
limit=st.integers(min_value=1, max_value=10),
)
def test_safe_truncate_nothing(self, text, limit):
assume(len(text) <= limit)
fst, snd = self.poster._safe_truncate(text, limit)


assert fst == text
assert snd == ""



class TestMastodonCaption:
Expand Down
Loading