Skip to content

Commit 68b08a5

Browse files
committed
[back] fix: fix unbound variable in tournesolbot
1 parent f290204 commit 68b08a5

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

backend/twitterbot/tests/test_tournesolbot.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,19 @@ def test_get_best_criteria(self):
165165
@mock.patch("twitterbot.tournesolbot.get_twitter_account_from_video_id")
166166
def test_prepare_tweet(self, mock_get_twitter_account_from_video_id):
167167

168-
tweet_text = (
168+
message_text = (
169169
"Aujourd'hui, je recommande 'Tournesol is great! 🌻 #tournesol' de @TournesolApp, "
170170
"comparée 77 fois sur #Tournesol🌻 par 28 contributeurs, critères favoris:"
171171
"\n- Important & actionnable\n- Stimulant & suscite la réflexion"
172-
"\ntournesol.app/entities/yt:AAAAAAAAAAA"
173172
)
173+
message_end = "\ntournesol.app/entities/yt:AAAAAAAAAAA"
174174

175175
mock_get_twitter_account_from_video_id.return_value = "@TournesolApp"
176176

177-
assert prepare_text(self.videos[8], dest="twitter") == tweet_text
177+
assert prepare_text(self.videos[8], dest="twitter") == message_text + message_end
178+
assert prepare_text(self.videos[8], dest="bluesky") == message_text.replace(
179+
"@TournesolApp", "'Tournesol'"
180+
)
178181

179182
# Test automatic shortening of the video title to fit in the tweet
180183
self.videos[8].metadata[
@@ -187,12 +190,15 @@ def test_prepare_tweet(self, mock_get_twitter_account_from_video_id):
187190
"contributeurs, critères favoris:"
188191
"\n- Important & actionnable"
189192
"\n- Stimulant & suscite la réflexion"
190-
"\ntournesol.app/entities/yt:AAAAAAAAAAA"
191193
)
194+
message_end = "\ntournesol.app/entities/yt:AAAAAAAAAAA"
192195

193-
assert prepare_text(self.videos[8], dest="twitter") == tweet_text_too_long
196+
assert prepare_text(self.videos[8], dest="twitter") == tweet_text_too_long + message_end
197+
assert prepare_text(self.videos[8], dest="bluesky").startswith(
198+
"Aujourd'hui, je recommande 'Tournesol is great!"
199+
)
194200

195-
# Test replacement of special characters in the video title
201+
# Test replacement of special characters in the video title for Twitter
196202
self.videos[8].metadata["name"] = "Tournesol.app is great but mention @twitter are not..."
197203

198204
tweet_special_characters = (

backend/twitterbot/tournesolbot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ def prepare_text(video: Entity, dest: Literal["twitter", "bluesky"]):
6969
CriteriaLocale.objects.filter(language=language).values_list("criteria__name", "label")
7070
)
7171

72+
video_title = video.metadata["name"]
7273
if dest == "twitter":
7374
# Replace "@" by a smaller "@" to avoid false mentions in the tweet
74-
video_title = video.metadata["name"].replace("@", "﹫")
75+
video_title = video_title.replace("@", "﹫")
7576

7677
# Replace "." in between words to avoid in the tweet false detection of links
7778
video_title = re.sub(r"\b(?:\.)\b", "․", video_title)

0 commit comments

Comments
 (0)