示例#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
示例#2
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
示例#3
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
示例#4
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",
        ]
示例#5
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")
示例#6
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")
示例#7
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
示例#8
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
示例#9
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
示例#10
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
示例#11
0
    async def reminder_notifier(self):
        query = Reminder.select()
        query = query.where(Reminder.finished == False)
        query = query.where(Reminder.due_date <= datetime.datetime.utcnow())

        for reminder in query:
            sendable = reminder.sendable
            if sendable is not None:
                embed = discord.Embed(color=self.bot.get_dominant_color(None))
                embed.set_author(
                    name="Reminder",
                    icon_url=
                    "https://cdn.discordapp.com/attachments/744172199770062899/804862458070040616/1.webp"
                )
                embed.description = reminder.text
                asyncio.gather(
                    sendable.send(content=f"<@{reminder.user_id}>",
                                  embed=embed))

            reminder.finished = True
            reminder.save()