Skip to content

Commit

Permalink
tests(templates): Adds logic to check content of Bluesky templates
Browse files Browse the repository at this point in the history
  • Loading branch information
ERosendo committed Sep 17, 2024
1 parent 55ced78 commit f846e99
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions bc/core/tests/test_templates.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import re
from unittest.mock import patch

from django.test import SimpleTestCase

from bc.channel.tests.factories import fake_token
from bc.channel.utils.connectors.bluesky_api.client import BlueskyAPI
from bc.core.utils.status.templates import (
BLUESKY_FOLLOW_A_NEW_CASE,
MASTODON_FOLLOW_A_NEW_CASE,
TWITTER_FOLLOW_A_NEW_CASE,
MastodonTemplate,
)
from bc.core.utils.tests.base import faker


class NewSubscriptionValidTemplateTest(SimpleTestCase):
Expand Down Expand Up @@ -804,3 +810,30 @@ def test_truncate_descriptions(self):
msg="Failed with dict: %s.\n%s is longer than %s"
% (test, result, template.max_characters),
)


class BlueskyTemplateTest(SimpleTestCase):

@patch(
"bc.channel.utils.connectors.bluesky_api.client.BlueskyAPI._get_session"
)
def test_create_posts_with_no_brackets(self, mock_session):
fake_article_url = faker.url()
fake_docket_url = faker.url()
fake_initial_complaint_link = faker.url()

message, _ = BLUESKY_FOLLOW_A_NEW_CASE.format(
docket=faker.text(),
docket_link=fake_docket_url,
docket_id=faker.random_int(100_000, 400_000),
article_url=fake_article_url,
date_filed=None,
initial_complaint_type="Complaint",
initial_complaint_link=fake_initial_complaint_link,
)
bluesky_connector = BlueskyAPI(fake_token(), fake_token())
post_content = bluesky_connector._clean_text(message)
# This regular expression ensures that no brackets are included in
# the content of the post to enclose embedded links
pattern = r"View Full Case | Complaint | Context"
self.assertIsNotNone(re.search(pattern, post_content))

0 comments on commit f846e99

Please sign in to comment.