diff --git a/joboffers/management/commands/test_mastodon.py b/joboffers/management/commands/test_mastodon.py new file mode 100644 index 0000000..f7da012 --- /dev/null +++ b/joboffers/management/commands/test_mastodon.py @@ -0,0 +1,10 @@ +from joboffers.management.commands import TestPublishCommand +from joboffers.publishers.mastodon import MastodonPublisher + + +class Command(TestPublishCommand): + help = 'Test sending a post to Mastodon.' + + def handle(self, *args, **options): + """Post a message to Mastodon.""" + self._handle_publish(options, MastodonPublisher) diff --git a/joboffers/tests/test_joboffer_publisher.py b/joboffers/tests/test_joboffer_publisher.py index d249223..cde0b68 100644 --- a/joboffers/tests/test_joboffer_publisher.py +++ b/joboffers/tests/test_joboffer_publisher.py @@ -10,6 +10,7 @@ from ..publishers.facebook import FacebookPublisher from ..publishers.telegram import TelegramPublisher from ..publishers.twitter import TwitterPublisher +from ..publishers.mastodon import MastodonPublisher from ..models import OfferState from .factories import JobOfferFactory @@ -78,21 +79,24 @@ def test_publisher_publish_error(): @pytest.mark.django_db @patch('joboffers.publishers.publish_offer') def test_publisher_to_all_social_networks_works_ok(publish_offer_function, settings): - """ - Test that publish_to_all_social_networks() uses all the condifured publishers - """ + """Test that publish_to_all_social_networks() uses all the configured publishers.""" joboffer = JobOfferFactory.create(state=OfferState.ACTIVE) settings.SOCIAL_NETWORKS_PUBLISHERS = [ - 'joboffers.publishers.discourse.DiscoursePublisher', - 'joboffers.publishers.facebook.FacebookPublisher', - 'joboffers.publishers.telegram.TelegramPublisher', - 'joboffers.publishers.twitter.TwitterPublisher' + 'joboffers.publishers.discourse.DiscoursePublisher', + 'joboffers.publishers.facebook.FacebookPublisher', + 'joboffers.publishers.telegram.TelegramPublisher', + 'joboffers.publishers.twitter.TwitterPublisher', + 'joboffers.publishers.mastodon.MastodonPublisher', ] publish_to_all_social_networks(joboffer) expected_publishers = [ - DiscoursePublisher, FacebookPublisher, TelegramPublisher, TwitterPublisher + DiscoursePublisher, + FacebookPublisher, + TelegramPublisher, + TwitterPublisher, + MastodonPublisher, ] assert publish_offer_function.called diff --git a/pyarweb/settings/base.py b/pyarweb/settings/base.py index 88998cd..20d1383 100644 --- a/pyarweb/settings/base.py +++ b/pyarweb/settings/base.py @@ -278,6 +278,10 @@ TWITTER_CONSUMER_KEY = os.environ.get('TWITTER_CONSUMER_KEY') TWITTER_CONSUMER_SECRET = os.environ.get('TWITTER_CONSUMER_SECRET') +# Mastodon constants +MASTODON_AUTH_TOKEN = os.environ.get('MASTODON_AUTH_TOKEN') +MASTODON_API_BASE_URL = os.environ.get('MASTODON_API_BASE_URL') + # Discourse constants DISCOURSE_HOST = os.environ.get('DISCOURSE_HOST') DISCOURSE_API_KEY = os.environ.get('DISCOURSE_API_KEY') @@ -285,8 +289,9 @@ DISCOURSE_CATEGORY = os.environ.get('DISCOURSE_CATEGORY') SOCIAL_NETWORKS_PUBLISHERS = [ - 'joboffers.publishers.discourse.DiscoursePublisher', - 'joboffers.publishers.facebook.FacebookPublisher', - 'joboffers.publishers.telegram.TelegramPublisher', - 'joboffers.publishers.twitter.TwitterPublisher' + 'joboffers.publishers.discourse.DiscoursePublisher', + 'joboffers.publishers.facebook.FacebookPublisher', + 'joboffers.publishers.telegram.TelegramPublisher', + 'joboffers.publishers.twitter.TwitterPublisher', + 'joboffers.publishers.mastodon.MastodonPublisher', ] diff --git a/requirements.txt b/requirements.txt index 6c5c9fc..b01f141 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,6 +19,7 @@ django-tagging==0.5.0 django-taggit==1.5.1 django-taggit-autosuggest==0.3.8 lxml==4.9.1 +Mastodon.py==1.8.1 plotly==5.7.0 psycopg2-binary==2.9.1 tweepy==4.5.0