Exemplo n.º 1
0
    def test_creates_reminder_when_mention_is_a_reply_to_another_tweet(
            self, mock_alpha_vantage_get_intraday):
        bot.reply_to_mentions()

        mock_alpha_vantage_get_intraday.assert_called_once_with("AMZN")
        assert Reminder.select().count() == 1
        assert Reminder.select().first().tweet_id == 2
Exemplo n.º 2
0
    def test_saves_new_mentions(self, mock_tweepy):
        assert Mention.select().count() == 0

        bot.reply_to_mentions()

        mock_tweepy.assert_has_calls([call().mentions_timeline(since_id=None)])
        assert Mention.select().count() == 1
Exemplo n.º 3
0
    def test_creates_reminder_for_stock_shorting(self):
        assert Reminder.select().count() == 0

        bot.reply_to_mentions()

        reminder = Reminder.select().first()
        assert reminder.short is True
Exemplo n.º 4
0
    def test_updates_status_when_mention_is_new(self, mock_tweepy):
        bot.reply_to_mentions()

        mock_tweepy.assert_has_calls([
            call().update_status(
                status="@user_name Las acciones de $BABA cotizan a $277.72.",
                in_reply_to_status_id=1,
            )
        ])
Exemplo n.º 5
0
    def test_replies_when_stock_is_not_found(self, mock_tweepy):
        bot.reply_to_mentions()

        expected_status_call = call().update_status(
            status=f"@user_name {const.STOCK_NOT_FOUND_RESPONSE}",
            in_reply_to_status_id=1,
        )

        assert expected_status_call in mock_tweepy.mock_calls
Exemplo n.º 6
0
    def test_publishes_custom_error_response_when_max_retries_exceeded(
            self, mock_tweepy):
        expected_status_call = call().update_status(
            status=f"@user_name {const.API_LIMIT_EXCEEDED_RESPONSE}",
            in_reply_to_status_id=1,
        )

        bot.reply_to_mentions()

        assert expected_status_call in mock_tweepy.mock_calls
Exemplo n.º 7
0
    def test_publishes_custom_error_response_when_stock_name_not_found(
            self, mock_tweepy):
        expected_status_call = call().update_status(
            status=f"@user_name {const.STOCK_NOT_FOUND_RESPONSE}",
            in_reply_to_status_id=1,
        )

        bot.reply_to_mentions()

        assert expected_status_call in mock_tweepy.mock_calls
Exemplo n.º 8
0
    def test_does_not_update_status_when_mention_has_been_replied(
            self, mock_tweepy):
        update_status_call = call().update_status(
            status="@user_name Las acciones de $BABA cotizan a $277.72.",
            in_reply_to_status_id=1,
        )

        bot.reply_to_mentions()

        assert update_status_call not in mock_tweepy.mock_calls
Exemplo n.º 9
0
    def test_replies_to_mention_when_api_limit_exceeded(self, mock_tweepy):
        with freeze_time("2020-12-13T15:32:00Z"):
            bot.reply_to_mentions()

        expected_status_call = call().update_status(
            status=f"@user_name {const.API_LIMIT_EXCEEDED_RESPONSE}",
            in_reply_to_status_id=1,
        )

        assert expected_status_call in mock_tweepy.mock_calls
Exemplo n.º 10
0
    def test_replies_to_mention_when_mention_is_not_valid(self, mock_tweepy):
        with freeze_time("2020-12-13T15:32:00Z"):
            bot.reply_to_mentions()

        expected_status_call = call().update_status(
            status=f"@user_name {const.INVALID_MENTION_RESPONSE}",
            in_reply_to_status_id=1,
        )

        assert expected_status_call in mock_tweepy.mock_calls
        assert Reminder.select().count() == 0
Exemplo n.º 11
0
    def test_creates_reminder_when_mention_is_a_reply_to_an_extended_tweet(
        self,
        mock_alpha_vantage_get_intraday,
    ):
        bot.reply_to_mentions()

        mock_alpha_vantage_get_intraday.assert_has_calls(
            [call("AMZN"), call("TSLA"),
             call("JNJ")])
        assert Reminder.select().count() == 3
        assert Reminder.select().first().tweet_id == 2
Exemplo n.º 12
0
    def test_replies_to_mention_when_reminder_created(self, mock_tweepy):
        with freeze_time("2020-12-13T15:32:00Z"):
            bot.reply_to_mentions()

        expected_status_call = call().update_status(
            status=
            "@user_name Sure thing buddy! I'll remind you of the price of "
            "$AMZN on Saturday March 13 2021. I hope you make tons of money! 🤑",
            in_reply_to_status_id=1,
        )

        assert Reminder.select().count() == 1
        assert expected_status_call in mock_tweepy.mock_calls
Exemplo n.º 13
0
    def test_replies_with_company_report_when_rating_not_available(
            self, mock_tweepy):
        with freeze_time("2020-12-13T15:32:00Z"):
            bot.reply_to_mentions()

        expected_status_call = call().update_status(
            status=
            "@user_name Knowledge is power! ­ЪДа­Ъњф Here is your company "
            "report for $AMZN: ",
            in_reply_to_status_id=1,
            media_ids=[ANY],
        )

        assert expected_status_call in mock_tweepy.mock_calls
Exemplo n.º 14
0
    def test_replies_to_mention_when_mention_is_a_reply_to_another_tweet(
            self, mock_tweepy, mock_giphy):
        bot.reply_to_mentions()

        expected_calls = [
            call().update_status(
                status=
                "@user_name Sure thing buddy! I'll remind you of the price of "
                "$AMZN on Saturday December 11 2021. I hope you make tons of money! 🤑",
                in_reply_to_status_id=2,
            ),
        ]

        assert expected_calls in mock_tweepy.mock_calls
Exemplo n.º 15
0
    def test_creates_reminders_when_mention_contains_multiple_stocks_and_date(
        self, ):
        assert Reminder.select().count() == 0

        bot.reply_to_mentions()

        reminders = Reminder.select()
        assert reminders.count() == 4
        assert [reminder.stock_symbol for reminder in reminders] == [
            "AMZN",
            "MSFT",
            "AAPL",
            "BABA",
        ]
Exemplo n.º 16
0
    def test_replies_with_help_message_when_mention_is_not_valid(
            self, mock_tweepy):
        bot.reply_to_mentions()

        expected_status_call = call().update_status(
            status="@user_name To create a reminder, mention me "
            "with one or more ticker symbols and a date. "
            "E.g. 'Remind me of $BTC in 3 months'. "
            "You can read about all my other features and "
            "implementation at: http://cutt.ly/Rh8CoJt",
            in_reply_to_status_id=1,
        )

        assert expected_status_call in mock_tweepy.mock_calls
        assert Reminder.select().count() == 0
Exemplo n.º 17
0
    def test_replies_to_mention_when_reminder_created(self, mock_tweepy,
                                                      mock_giphy):
        bot.reply_to_mentions()

        expected_calls = [
            call().update_status(
                status=
                "@user_name Sure thing buddy! I'll remind you of the price of "
                "$AMZN on Thursday March 11 2021. I hope you make tons of money! 🤑",
                in_reply_to_status_id=1,
            ),
        ]

        assert Reminder.select().count() == 1
        assert expected_calls in mock_tweepy.mock_calls
Exemplo n.º 18
0
    def test_replies_with_company_report_when_mention_contains_report_and_crypto(
        self,
        mock_tweepy,
    ):
        with freeze_time("2020-12-13T15:32:00Z"):
            bot.reply_to_mentions()

        expected_status_call = call().update_status(
            status="@user_name Knowledge is power! ­ЪДа­Ъњф Here "
            "is your crypto ratings report for $ETH:",
            in_reply_to_status_id=1,
            media_ids=[ANY],
        )

        assert expected_status_call in mock_tweepy.mock_calls
Exemplo n.º 19
0
    def test_replies_with_company_report_when_mention_contains_report_and_stock(
        self,
        mock_tweepy,
    ):
        with freeze_time("2020-12-13T15:32:00Z"):
            bot.reply_to_mentions()

        expected_status_call = call().update_status(
            status=
            "@user_name Knowledge is power! ­ЪДа­Ъњф Here is your company "
            "report for $AMZN. Score: 4, Rating: A+, Recommendation: Buy. Details: ",
            in_reply_to_status_id=1,
            media_ids=[ANY],
        )
        assert expected_status_call in mock_tweepy.mock_calls
Exemplo n.º 20
0
    def test_creates_reminder_when_mention_contains_stock_and_date(
            self, mock_alpha_vantage_get_intraday):
        assert Reminder.select().count() == 0

        with freeze_time("2020-12-13"):
            bot.reply_to_mentions()

        assert Reminder.select().count() == 1

        reminder = Reminder.select().first()
        assert reminder.tweet_id == 1
        assert reminder.created_on == date(2020, 12, 13)
        assert reminder.remind_on == date(2021, 3, 13)
        assert reminder.stock_symbol == "AMZN"
        assert reminder.stock_price == 3112.70
        mock_alpha_vantage_get_intraday.assert_called_once_with("AMZN")
Exemplo n.º 21
0
    def test_creates_reminder_when_mention_contains_stock_and_date(
            self, mock_alpha_vantage_get_intraday_amazon):
        assert Reminder.select().count() == 0

        with freeze_time("2020-12-13T15:32:00Z"):
            bot.reply_to_mentions()

        assert Reminder.select().count() == 1

        reminder = Reminder.select().first()
        assert reminder.tweet_id == 1
        assert reminder.created_on == date(2020, 12, 13)
        assert reminder.remind_on == "2021-03-13 15:32:00+00:00"
        assert reminder.stock_symbol == "AMZN"
        assert reminder.stock_price == 3112.70
        assert reminder.is_finished is False
        mock_alpha_vantage_get_intraday_amazon.assert_called_once_with("AMZN")
Exemplo n.º 22
0
    def test_does_not_save_old_mentions(self):
        assert Mention.select().count() == 1

        bot.reply_to_mentions()

        assert Mention.select().count() == 1